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 | d93e1b1 | 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" |
Jooyung Han | 23b0adf | 2020-03-12 18:37:20 +0900 | [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") |
| 39 | pctx.Import("android/soong/java") |
| 40 | pctx.HostBinToolVariable("apexer", "apexer") |
| 41 | // ART minimal builds (using the master-art manifest) do not have the "frameworks/base" |
| 42 | // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead. |
| 43 | hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) { |
| 44 | pctx.VariableFunc(name, func(ctx android.PackageVarContext) string { |
| 45 | if !ctx.Config().FrameworksBaseDirExists(ctx) { |
| 46 | return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool) |
| 47 | } else { |
Martin Stjernholm | 7260d06 | 2019-12-09 21:47:14 +0000 | [diff] [blame] | 48 | return ctx.Config().HostToolPath(ctx, tool).String() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 49 | } |
| 50 | }) |
| 51 | } |
| 52 | hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2") |
| 53 | pctx.HostBinToolVariable("avbtool", "avbtool") |
| 54 | pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid") |
| 55 | pctx.HostBinToolVariable("merge_zips", "merge_zips") |
| 56 | pctx.HostBinToolVariable("mke2fs", "mke2fs") |
| 57 | pctx.HostBinToolVariable("resize2fs", "resize2fs") |
| 58 | pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile") |
| 59 | pctx.HostBinToolVariable("soong_zip", "soong_zip") |
| 60 | pctx.HostBinToolVariable("zip2zip", "zip2zip") |
| 61 | pctx.HostBinToolVariable("zipalign", "zipalign") |
| 62 | pctx.HostBinToolVariable("jsonmodify", "jsonmodify") |
| 63 | pctx.HostBinToolVariable("conv_apex_manifest", "conv_apex_manifest") |
Jaewoong Jung | 8cf307e | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 64 | pctx.HostBinToolVariable("extract_apks", "extract_apks") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | var ( |
| 68 | // Create a canned fs config file where all files and directories are |
| 69 | // by default set to (uid/gid/mode) = (1000/1000/0644) |
| 70 | // TODO(b/113082813) make this configurable using config.fs syntax |
| 71 | generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{ |
Sasha Smundak | c4f0ff1 | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 72 | Command: `( echo '/ 1000 1000 0755' ` + |
| 73 | `&& for i in ${ro_paths}; do echo "/$$i 1000 1000 0644"; done ` + |
| 74 | `&& for i in ${exec_paths}; do echo "/$$i 0 2000 0755"; done ` + |
| 75 | `&& ( 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}`, |
| 76 | Description: "fs_config ${out}", |
| 77 | Rspfile: "$out.apklist", |
| 78 | RspfileContent: "$in", |
| 79 | }, "ro_paths", "exec_paths", "apk_paths") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 80 | |
| 81 | apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{ |
| 82 | Command: `rm -f $out && ${jsonmodify} $in ` + |
| 83 | `-a provideNativeLibs ${provideNativeLibs} ` + |
| 84 | `-a requireNativeLibs ${requireNativeLibs} ` + |
| 85 | `${opt} ` + |
| 86 | `-o $out`, |
| 87 | CommandDeps: []string{"${jsonmodify}"}, |
| 88 | Description: "prepare ${out}", |
| 89 | }, "provideNativeLibs", "requireNativeLibs", "opt") |
| 90 | |
| 91 | stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{ |
| 92 | Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`, |
| 93 | CommandDeps: []string{"${conv_apex_manifest}"}, |
| 94 | Description: "strip ${in}=>${out}", |
| 95 | }) |
| 96 | |
| 97 | pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{ |
| 98 | Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`, |
| 99 | CommandDeps: []string{"${conv_apex_manifest}"}, |
| 100 | Description: "convert ${in}=>${out}", |
| 101 | }) |
| 102 | |
| 103 | // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate |
| 104 | // against the binary policy using sefcontext_compiler -p <policy>. |
| 105 | |
| 106 | // TODO(b/114327326): automate the generation of file_contexts |
| 107 | apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{ |
| 108 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
| 109 | `(. ${out}.copy_commands) && ` + |
| 110 | `APEXER_TOOL_PATH=${tool_path} ` + |
| 111 | `${apexer} --force --manifest ${manifest} ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 112 | `--file_contexts ${file_contexts} ` + |
| 113 | `--canned_fs_config ${canned_fs_config} ` + |
Dario Freni | 0f4ae07 | 2020-01-02 15:24:12 +0000 | [diff] [blame] | 114 | `--include_build_info ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 115 | `--payload_type image ` + |
| 116 | `--key ${key} ${opt_flags} ${image_dir} ${out} `, |
| 117 | CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}", |
| 118 | "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", |
| 119 | "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"}, |
| 120 | Rspfile: "${out}.copy_commands", |
| 121 | RspfileContent: "${copy_commands}", |
| 122 | Description: "APEX ${image_dir} => ${out}", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 123 | }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 124 | |
| 125 | zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ |
| 126 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
| 127 | `(. ${out}.copy_commands) && ` + |
| 128 | `APEXER_TOOL_PATH=${tool_path} ` + |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 129 | `${apexer} --force --manifest ${manifest} ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 130 | `--payload_type zip ` + |
| 131 | `${image_dir} ${out} `, |
| 132 | CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"}, |
| 133 | Rspfile: "${out}.copy_commands", |
| 134 | RspfileContent: "${copy_commands}", |
| 135 | Description: "ZipAPEX ${image_dir} => ${out}", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 136 | }, "tool_path", "image_dir", "copy_commands", "manifest") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 137 | |
| 138 | apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule", |
| 139 | blueprint.RuleParams{ |
| 140 | Command: `${aapt2} convert --output-format proto $in -o $out`, |
| 141 | CommandDeps: []string{"${aapt2}"}, |
| 142 | }) |
| 143 | |
| 144 | apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{ |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 145 | Command: `${zip2zip} -i $in -o $out.base ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 146 | `apex_payload.img:apex/${abi}.img ` + |
Dario Freni | 1842378 | 2020-03-02 21:47:09 +0000 | [diff] [blame] | 147 | `apex_build_info.pb:apex/${abi}.build_info.pb ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 148 | `apex_manifest.json:root/apex_manifest.json ` + |
Jiyong Park | 53ae334 | 2019-12-08 02:06:24 +0900 | [diff] [blame] | 149 | `apex_manifest.pb:root/apex_manifest.pb ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 150 | `AndroidManifest.xml:manifest/AndroidManifest.xml ` + |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 151 | `assets/NOTICE.html.gz:assets/NOTICE.html.gz &&` + |
| 152 | `${soong_zip} -o $out.config -C $$(dirname ${config}) -f ${config} && ` + |
| 153 | `${merge_zips} $out $out.base $out.config`, |
| 154 | CommandDeps: []string{"${zip2zip}", "${soong_zip}", "${merge_zips}"}, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 155 | Description: "app bundle", |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 156 | }, "abi", "config") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 157 | |
| 158 | emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{ |
| 159 | Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`, |
| 160 | Rspfile: "${out}.emit_commands", |
| 161 | RspfileContent: "${emit_commands}", |
| 162 | Description: "Emit APEX image content", |
| 163 | }, "emit_commands") |
| 164 | |
| 165 | diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{ |
| 166 | Command: `diff --unchanged-group-format='' \` + |
| 167 | `--changed-group-format='%<' \` + |
Colin Cross | 95f7b34 | 2020-06-11 11:32:11 -0700 | [diff] [blame^] | 168 | `${image_content_file} ${allowed_files_file} || (` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 169 | `echo -e "New unexpected files were added to ${apex_module_name}." ` + |
| 170 | ` "To fix the build run following command:" && ` + |
Colin Cross | 95f7b34 | 2020-06-11 11:32:11 -0700 | [diff] [blame^] | 171 | `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] | 172 | `exit 1); touch ${out}`, |
Colin Cross | 95f7b34 | 2020-06-11 11:32:11 -0700 | [diff] [blame^] | 173 | Description: "Diff ${image_content_file} and ${allowed_files_file}", |
| 174 | }, "image_content_file", "allowed_files_file", "apex_module_name") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 175 | ) |
| 176 | |
| 177 | func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, requireNativeLibs []string) { |
| 178 | manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) |
| 179 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 180 | manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 181 | |
| 182 | // put dependency({provide|require}NativeLibs) in apex_manifest.json |
| 183 | provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs) |
| 184 | requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs)) |
| 185 | |
| 186 | // apex name can be overridden |
| 187 | optCommands := []string{} |
| 188 | if a.properties.Apex_name != nil { |
| 189 | optCommands = append(optCommands, "-v name "+*a.properties.Apex_name) |
| 190 | } |
| 191 | |
| 192 | ctx.Build(pctx, android.BuildParams{ |
| 193 | Rule: apexManifestRule, |
| 194 | Input: manifestSrc, |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 195 | Output: manifestJsonFullOut, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 196 | Args: map[string]string{ |
| 197 | "provideNativeLibs": strings.Join(provideNativeLibs, " "), |
| 198 | "requireNativeLibs": strings.Join(requireNativeLibs, " "), |
| 199 | "opt": strings.Join(optCommands, " "), |
| 200 | }, |
| 201 | }) |
| 202 | |
Jooyung Han | 23b0adf | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 203 | if a.minSdkVersion(ctx) == android.SdkVersion_Android10 { |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 204 | // b/143654022 Q apexd can't understand newly added keys in apex_manifest.json |
| 205 | // prepare stripped-down version so that APEX modules built from R+ can be installed to Q |
| 206 | a.manifestJsonOut = android.PathForModuleOut(ctx, "apex_manifest.json") |
| 207 | ctx.Build(pctx, android.BuildParams{ |
| 208 | Rule: stripApexManifestRule, |
| 209 | Input: manifestJsonFullOut, |
| 210 | Output: a.manifestJsonOut, |
| 211 | }) |
| 212 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 213 | |
| 214 | // from R+, protobuf binary format (.pb) is the standard format for apex_manifest |
| 215 | a.manifestPbOut = android.PathForModuleOut(ctx, "apex_manifest.pb") |
| 216 | ctx.Build(pctx, android.BuildParams{ |
| 217 | Rule: pbApexManifestRule, |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 218 | Input: manifestJsonFullOut, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 219 | Output: a.manifestPbOut, |
| 220 | }) |
| 221 | } |
| 222 | |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 223 | func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName string) android.NoticeOutputs { |
Jiyong Park | 162e844 | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 224 | var noticeFiles android.Paths |
| 225 | |
Paul Duffin | 133608f | 2020-03-30 15:54:08 +0100 | [diff] [blame] | 226 | a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { |
Jiyong Park | 162e844 | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 227 | if externalDep { |
Paul Duffin | 133608f | 2020-03-30 15:54:08 +0100 | [diff] [blame] | 228 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 229 | return false |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 230 | } |
Paul Duffin | 133608f | 2020-03-30 15:54:08 +0100 | [diff] [blame] | 231 | |
Jiyong Park | 162e844 | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 232 | notice := to.NoticeFile() |
| 233 | if notice.Valid() { |
| 234 | noticeFiles = append(noticeFiles, notice.Path()) |
| 235 | } |
Paul Duffin | 133608f | 2020-03-30 15:54:08 +0100 | [diff] [blame] | 236 | |
| 237 | return true |
Jiyong Park | 162e844 | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 238 | }) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 239 | |
| 240 | if len(noticeFiles) == 0 { |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 241 | return android.NoticeOutputs{} |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 242 | } |
| 243 | |
Jiyong Park | 402ace6 | 2020-05-29 22:00:16 +0900 | [diff] [blame] | 244 | return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.SortedUniquePaths(noticeFiles)) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 245 | } |
| 246 | |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 247 | func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApex android.Path, imageDir android.Path) android.OutputPath { |
| 248 | output := android.PathForModuleOut(ctx, "installed-files.txt") |
| 249 | rule := android.NewRuleBuilder() |
| 250 | rule.Command(). |
| 251 | Implicit(builtApex). |
| 252 | Text("(cd " + imageDir.String() + " ; "). |
Jiyong Park | bd63a10 | 2020-02-08 12:40:05 +0900 | [diff] [blame] | 253 | Text("find . \\( -type f -o -type l \\) -printf \"%s %p\\n\") "). |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 254 | Text(" | sort -nr > "). |
| 255 | Output(output) |
| 256 | rule.Build(pctx, ctx, "installed-files."+a.Name(), "Installed files") |
| 257 | return output.OutputPath |
| 258 | } |
| 259 | |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 260 | func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath { |
| 261 | output := android.PathForModuleOut(ctx, "bundle_config.json") |
| 262 | |
Jiyong Park | af8998c | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 263 | type ApkConfig struct { |
| 264 | Package_name string `json:"package_name"` |
| 265 | Apk_path string `json:"path"` |
| 266 | } |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 267 | config := struct { |
| 268 | Compression struct { |
| 269 | Uncompressed_glob []string `json:"uncompressed_glob"` |
| 270 | } `json:"compression"` |
Jiyong Park | af8998c | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 271 | Apex_config struct { |
| 272 | Apex_embedded_apk_config []ApkConfig `json:"apex_embedded_apk_config,omitempty"` |
| 273 | } `json:"apex_config,omitempty"` |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 274 | }{} |
| 275 | |
| 276 | config.Compression.Uncompressed_glob = []string{ |
| 277 | "apex_payload.img", |
| 278 | "apex_manifest.*", |
| 279 | } |
Jiyong Park | af8998c | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 280 | |
| 281 | // collect the manifest names and paths of android apps |
| 282 | // if their manifest names are overridden |
| 283 | for _, fi := range a.filesInfo { |
Sasha Smundak | c4f0ff1 | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 284 | if fi.class != app && fi.class != appSet { |
Jiyong Park | af8998c | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 285 | continue |
| 286 | } |
| 287 | packageName := fi.overriddenPackageName |
| 288 | if packageName != "" { |
| 289 | config.Apex_config.Apex_embedded_apk_config = append( |
| 290 | config.Apex_config.Apex_embedded_apk_config, |
| 291 | ApkConfig{ |
| 292 | Package_name: packageName, |
| 293 | Apk_path: fi.Path(), |
| 294 | }) |
| 295 | } |
| 296 | } |
| 297 | |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 298 | j, err := json.Marshal(config) |
| 299 | if err != nil { |
| 300 | panic(fmt.Errorf("error while marshalling to %q: %#v", output, err)) |
| 301 | } |
| 302 | |
| 303 | ctx.Build(pctx, android.BuildParams{ |
| 304 | Rule: android.WriteFile, |
| 305 | Output: output, |
| 306 | Description: "Bundle Config " + output.String(), |
| 307 | Args: map[string]string{ |
| 308 | "content": string(j), |
| 309 | }, |
| 310 | }) |
| 311 | |
| 312 | return output.OutputPath |
| 313 | } |
| 314 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 315 | func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { |
| 316 | var abis []string |
| 317 | for _, target := range ctx.MultiTargets() { |
| 318 | if len(target.Arch.Abi) > 0 { |
| 319 | abis = append(abis, target.Arch.Abi[0]) |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | abis = android.FirstUniqueStrings(abis) |
| 324 | |
| 325 | apexType := a.properties.ApexType |
| 326 | suffix := apexType.suffix() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 327 | var implicitInputs []android.Path |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 328 | unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 329 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 330 | // TODO(jiyong): construct the copy rules using RuleBuilder |
| 331 | var copyCommands []string |
| 332 | for _, fi := range a.filesInfo { |
| 333 | destPath := android.PathForModuleOut(ctx, "image"+suffix, fi.Path()).String() |
Sasha Smundak | c4f0ff1 | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 334 | destPathDir := filepath.Dir(destPath) |
| 335 | if fi.class == appSet { |
| 336 | copyCommands = append(copyCommands, "rm -rf "+destPathDir) |
| 337 | } |
| 338 | copyCommands = append(copyCommands, "mkdir -p "+destPathDir) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 339 | if a.linkToSystemLib && fi.transitiveDep && fi.AvailableToPlatform() { |
| 340 | // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here |
| 341 | pathOnDevice := filepath.Join("/system", fi.Path()) |
| 342 | copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath) |
| 343 | } else { |
Sasha Smundak | c4f0ff1 | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 344 | if fi.class == appSet { |
| 345 | copyCommands = append(copyCommands, |
| 346 | fmt.Sprintf("unzip -q -d %s %s", destPathDir, fi.builtFile.String())) |
| 347 | } else { |
| 348 | copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath) |
| 349 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 350 | implicitInputs = append(implicitInputs, fi.builtFile) |
| 351 | } |
| 352 | // create additional symlinks pointing the file inside the APEX |
| 353 | for _, symlinkPath := range fi.SymlinkPaths() { |
| 354 | symlinkDest := android.PathForModuleOut(ctx, "image"+suffix, symlinkPath).String() |
| 355 | copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest) |
| 356 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 357 | } |
| 358 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 359 | // TODO(jiyong): use RuleBuilder |
| 360 | var emitCommands []string |
| 361 | imageContentFile := android.PathForModuleOut(ctx, "content.txt") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 362 | emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String()) |
Jooyung Han | 23b0adf | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 363 | if a.minSdkVersion(ctx) == android.SdkVersion_Android10 { |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 364 | emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String()) |
| 365 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 366 | for _, fi := range a.filesInfo { |
| 367 | emitCommands = append(emitCommands, "echo './"+fi.Path()+"' >> "+imageContentFile.String()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 368 | } |
| 369 | emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String()) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 370 | implicitInputs = append(implicitInputs, a.manifestPbOut) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 371 | |
| 372 | if a.properties.Whitelisted_files != nil { |
| 373 | ctx.Build(pctx, android.BuildParams{ |
| 374 | Rule: emitApexContentRule, |
| 375 | Implicits: implicitInputs, |
| 376 | Output: imageContentFile, |
| 377 | Description: "emit apex image content", |
| 378 | Args: map[string]string{ |
| 379 | "emit_commands": strings.Join(emitCommands, " && "), |
| 380 | }, |
| 381 | }) |
| 382 | implicitInputs = append(implicitInputs, imageContentFile) |
Colin Cross | 95f7b34 | 2020-06-11 11:32:11 -0700 | [diff] [blame^] | 383 | allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files)) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 384 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 385 | phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 386 | ctx.Build(pctx, android.BuildParams{ |
| 387 | Rule: diffApexContentRule, |
| 388 | Implicits: implicitInputs, |
| 389 | Output: phonyOutput, |
| 390 | Description: "diff apex image content", |
| 391 | Args: map[string]string{ |
Colin Cross | 95f7b34 | 2020-06-11 11:32:11 -0700 | [diff] [blame^] | 392 | "allowed_files_file": allowedFilesFile.String(), |
| 393 | "image_content_file": imageContentFile.String(), |
| 394 | "apex_module_name": a.Name(), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 395 | }, |
| 396 | }) |
| 397 | |
| 398 | implicitInputs = append(implicitInputs, phonyOutput) |
| 399 | } |
| 400 | |
| 401 | outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String() |
| 402 | prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") |
| 403 | |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 404 | imageDir := android.PathForModuleOut(ctx, "image"+suffix) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 405 | if apexType == imageApex { |
| 406 | // files and dirs that will be created in APEX |
| 407 | var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"} |
| 408 | var executablePaths []string // this also includes dirs |
Sasha Smundak | c4f0ff1 | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 409 | var extractedAppSetPaths android.Paths |
| 410 | var extractedAppSetDirs []string |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 411 | for _, f := range a.filesInfo { |
Jiyong Park | cbe50c7 | 2020-05-29 21:29:20 +0900 | [diff] [blame] | 412 | pathInApex := f.Path() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 413 | if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") { |
| 414 | executablePaths = append(executablePaths, pathInApex) |
| 415 | for _, s := range f.symlinks { |
| 416 | executablePaths = append(executablePaths, filepath.Join(f.installDir, s)) |
| 417 | } |
Sasha Smundak | c4f0ff1 | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 418 | } else if f.class == appSet { |
| 419 | extractedAppSetPaths = append(extractedAppSetPaths, f.builtFile) |
| 420 | extractedAppSetDirs = append(extractedAppSetDirs, f.installDir) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 421 | } else { |
| 422 | readOnlyPaths = append(readOnlyPaths, pathInApex) |
| 423 | } |
| 424 | dir := f.installDir |
| 425 | for !android.InList(dir, executablePaths) && dir != "" { |
| 426 | executablePaths = append(executablePaths, dir) |
| 427 | dir, _ = filepath.Split(dir) // move up to the parent |
| 428 | if len(dir) > 0 { |
| 429 | // remove trailing slash |
| 430 | dir = dir[:len(dir)-1] |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | sort.Strings(readOnlyPaths) |
| 435 | sort.Strings(executablePaths) |
| 436 | cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config") |
| 437 | ctx.Build(pctx, android.BuildParams{ |
| 438 | Rule: generateFsConfig, |
| 439 | Output: cannedFsConfig, |
| 440 | Description: "generate fs config", |
Sasha Smundak | c4f0ff1 | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 441 | Inputs: extractedAppSetPaths, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 442 | Args: map[string]string{ |
| 443 | "ro_paths": strings.Join(readOnlyPaths, " "), |
| 444 | "exec_paths": strings.Join(executablePaths, " "), |
Sasha Smundak | c4f0ff1 | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 445 | "apk_paths": strings.Join(extractedAppSetDirs, " "), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 446 | }, |
| 447 | }) |
| 448 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 449 | optFlags := []string{} |
| 450 | |
| 451 | // Additional implicit inputs. |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 452 | implicitInputs = append(implicitInputs, cannedFsConfig, a.fileContexts, a.private_key_file, a.public_key_file) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 453 | optFlags = append(optFlags, "--pubkey "+a.public_key_file.String()) |
| 454 | |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 455 | manifestPackageName := a.getOverrideManifestPackageName(ctx) |
| 456 | if manifestPackageName != "" { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 457 | optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName) |
| 458 | } |
| 459 | |
| 460 | if a.properties.AndroidManifest != nil { |
| 461 | androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest)) |
| 462 | implicitInputs = append(implicitInputs, androidManifestFile) |
| 463 | optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String()) |
| 464 | } |
| 465 | |
| 466 | targetSdkVersion := ctx.Config().DefaultAppTargetSdk() |
Nikita Ioffe | 5f6771e | 2020-05-20 00:16:27 +0100 | [diff] [blame] | 467 | // TODO(b/157078772): propagate min_sdk_version to apexer. |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 468 | minSdkVersion := ctx.Config().DefaultAppTargetSdk() |
Nikita Ioffe | db10c13 | 2020-02-20 00:43:27 +0000 | [diff] [blame] | 469 | |
Jooyung Han | 23b0adf | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 470 | if a.minSdkVersion(ctx) == android.SdkVersion_Android10 { |
| 471 | minSdkVersion = strconv.Itoa(a.minSdkVersion(ctx)) |
Nikita Ioffe | db10c13 | 2020-02-20 00:43:27 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Nikita Ioffe | 934c4f2 | 2020-03-02 16:58:11 +0000 | [diff] [blame] | 474 | if java.UseApiFingerprint(ctx) { |
| 475 | targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String()) |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 476 | implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx)) |
| 477 | } |
Nikita Ioffe | 934c4f2 | 2020-03-02 16:58:11 +0000 | [diff] [blame] | 478 | if java.UseApiFingerprint(ctx) { |
| 479 | minSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String()) |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 480 | implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx)) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 481 | } |
| 482 | optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion) |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 483 | optFlags = append(optFlags, "--min_sdk_version "+minSdkVersion) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 484 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 485 | if a.overridableProperties.Logging_parent != "" { |
| 486 | optFlags = append(optFlags, "--logging_parent ", a.overridableProperties.Logging_parent) |
| 487 | } |
| 488 | |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 489 | a.mergedNotices = a.buildNoticeFiles(ctx, a.Name()+suffix) |
| 490 | if a.mergedNotices.HtmlGzOutput.Valid() { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 491 | // 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] | 492 | implicitInputs = append(implicitInputs, a.mergedNotices.HtmlGzOutput.Path()) |
| 493 | optFlags = append(optFlags, "--assets_dir "+filepath.Dir(a.mergedNotices.HtmlGzOutput.String())) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 494 | } |
| 495 | |
Nikita Ioffe | b4b44c0 | 2020-01-02 23:01:39 +0000 | [diff] [blame] | 496 | if ctx.ModuleDir() != "system/apex/apexd/apexd_testdata" && ctx.ModuleDir() != "system/apex/shim/build" && a.testOnlyShouldSkipHashtreeGeneration() { |
Nikita Ioffe | c72b5dd | 2019-12-07 17:30:22 +0000 | [diff] [blame] | 497 | ctx.PropertyErrorf("test_only_no_hashtree", "not available") |
| 498 | return |
| 499 | } |
Jooyung Han | 23b0adf | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 500 | if a.minSdkVersion(ctx) > android.SdkVersion_Android10 || a.testOnlyShouldSkipHashtreeGeneration() { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 501 | // Apexes which are supposed to be installed in builtin dirs(/system, etc) |
| 502 | // don't need hashtree for activation. Therefore, by removing hashtree from |
| 503 | // apex bundle (filesystem image in it, to be specific), we can save storage. |
| 504 | optFlags = append(optFlags, "--no_hashtree") |
| 505 | } |
| 506 | |
Dario Freni | 98410fd | 2020-04-27 18:21:11 +0100 | [diff] [blame] | 507 | if a.testOnlyShouldSkipPayloadSign() { |
| 508 | optFlags = append(optFlags, "--unsigned_payload") |
| 509 | } |
| 510 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 511 | if a.properties.Apex_name != nil { |
| 512 | // If apex_name is set, apexer can skip checking if key name matches with apex name. |
| 513 | // Note that apex_manifest is also mended. |
| 514 | optFlags = append(optFlags, "--do_not_check_keyname") |
| 515 | } |
| 516 | |
Jooyung Han | 23b0adf | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 517 | if a.minSdkVersion(ctx) == android.SdkVersion_Android10 { |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 518 | implicitInputs = append(implicitInputs, a.manifestJsonOut) |
| 519 | optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String()) |
| 520 | } |
| 521 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 522 | ctx.Build(pctx, android.BuildParams{ |
| 523 | Rule: apexRule, |
| 524 | Implicits: implicitInputs, |
| 525 | Output: unsignedOutputFile, |
| 526 | Description: "apex (" + apexType.name() + ")", |
| 527 | Args: map[string]string{ |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 528 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 529 | "image_dir": imageDir.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 530 | "copy_commands": strings.Join(copyCommands, " && "), |
| 531 | "manifest": a.manifestPbOut.String(), |
| 532 | "file_contexts": a.fileContexts.String(), |
| 533 | "canned_fs_config": cannedFsConfig.String(), |
| 534 | "key": a.private_key_file.String(), |
| 535 | "opt_flags": strings.Join(optFlags, " "), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 536 | }, |
| 537 | }) |
| 538 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 539 | apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix) |
| 540 | bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 541 | a.bundleModuleFile = bundleModuleFile |
| 542 | |
| 543 | ctx.Build(pctx, android.BuildParams{ |
| 544 | Rule: apexProtoConvertRule, |
| 545 | Input: unsignedOutputFile, |
| 546 | Output: apexProtoFile, |
| 547 | Description: "apex proto convert", |
| 548 | }) |
| 549 | |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 550 | bundleConfig := a.buildBundleConfig(ctx) |
| 551 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 552 | ctx.Build(pctx, android.BuildParams{ |
| 553 | Rule: apexBundleRule, |
| 554 | Input: apexProtoFile, |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 555 | Implicit: bundleConfig, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 556 | Output: a.bundleModuleFile, |
| 557 | Description: "apex bundle module", |
| 558 | Args: map[string]string{ |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 559 | "abi": strings.Join(abis, "."), |
| 560 | "config": bundleConfig.String(), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 561 | }, |
| 562 | }) |
| 563 | } else { |
| 564 | ctx.Build(pctx, android.BuildParams{ |
| 565 | Rule: zipApexRule, |
| 566 | Implicits: implicitInputs, |
| 567 | Output: unsignedOutputFile, |
| 568 | Description: "apex (" + apexType.name() + ")", |
| 569 | Args: map[string]string{ |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 570 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 571 | "image_dir": imageDir.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 572 | "copy_commands": strings.Join(copyCommands, " && "), |
| 573 | "manifest": a.manifestPbOut.String(), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 574 | }, |
| 575 | }) |
| 576 | } |
| 577 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 578 | a.outputFile = android.PathForModuleOut(ctx, a.Name()+suffix) |
Kousik Kumar | 15e9d0d | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 579 | rule := java.Signapk |
| 580 | args := map[string]string{ |
| 581 | "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(), |
| 582 | "flags": "-a 4096", //alignment |
| 583 | } |
| 584 | implicits := android.Paths{ |
| 585 | a.container_certificate_file, |
| 586 | a.container_private_key_file, |
| 587 | } |
| 588 | if ctx.Config().IsEnvTrue("RBE_SIGNAPK") { |
| 589 | rule = java.SignapkRE |
| 590 | args["implicits"] = strings.Join(implicits.Strings(), ",") |
| 591 | args["outCommaList"] = a.outputFile.String() |
| 592 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 593 | ctx.Build(pctx, android.BuildParams{ |
Kousik Kumar | 15e9d0d | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 594 | Rule: rule, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 595 | Description: "signapk", |
| 596 | Output: a.outputFile, |
| 597 | Input: unsignedOutputFile, |
Kousik Kumar | 15e9d0d | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 598 | Implicits: implicits, |
| 599 | Args: args, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 600 | }) |
| 601 | |
| 602 | // Install to $OUT/soong/{target,host}/.../apex |
| 603 | if a.installable() { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 604 | ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 605 | } |
| 606 | a.buildFilesInfo(ctx) |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 607 | |
| 608 | // installed-files.txt is dist'ed |
| 609 | a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { |
| 613 | // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it |
| 614 | // reply true to `InstallBypassMake()` (thus making the call |
| 615 | // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir` |
| 616 | // instead of `android.PathForOutput`) to return the correct path to the flattened |
| 617 | // APEX (as its contents is installed by Make, not Soong). |
| 618 | factx := flattenedApexContext{ctx} |
Jiyong Park | a594801 | 2020-02-07 10:15:14 +0900 | [diff] [blame] | 619 | apexBundleName := a.Name() |
| 620 | a.outputFile = android.PathForModuleInstall(&factx, "apex", apexBundleName) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 621 | |
Jooyung Han | 6bfc043 | 2020-04-27 22:18:19 +0900 | [diff] [blame] | 622 | if a.installable() { |
Jiyong Park | a594801 | 2020-02-07 10:15:14 +0900 | [diff] [blame] | 623 | installPath := android.PathForModuleInstall(ctx, "apex", apexBundleName) |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 624 | devicePath := android.InstallPathToOnDevicePath(ctx, installPath) |
Jiyong Park | a594801 | 2020-02-07 10:15:14 +0900 | [diff] [blame] | 625 | addFlattenedFileContextsInfos(ctx, apexBundleName+":"+devicePath+":"+a.fileContexts.String()) |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 626 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 627 | a.buildFilesInfo(ctx) |
| 628 | } |
| 629 | |
| 630 | func (a *apexBundle) setCertificateAndPrivateKey(ctx android.ModuleContext) { |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 631 | if a.container_certificate_file == nil { |
| 632 | cert := String(a.properties.Certificate) |
| 633 | if cert == "" { |
| 634 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
| 635 | a.container_certificate_file = pem |
| 636 | a.container_private_key_file = key |
| 637 | } else { |
| 638 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
| 639 | a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem") |
| 640 | a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8") |
| 641 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
| 645 | func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) { |
| 646 | if a.installable() { |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 647 | // For flattened APEX, do nothing but make sure that APEX manifest and apex_pubkey are also copied along |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 648 | // with other ordinary files. |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 649 | a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil)) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 650 | |
| 651 | // rename to apex_pubkey |
| 652 | copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey") |
| 653 | ctx.Build(pctx, android.BuildParams{ |
| 654 | Rule: android.Cp, |
| 655 | Input: a.public_key_file, |
| 656 | Output: copiedPubkey, |
| 657 | }) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 658 | a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil)) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 659 | |
| 660 | if a.properties.ApexType == flattenedApex { |
Jiyong Park | a594801 | 2020-02-07 10:15:14 +0900 | [diff] [blame] | 661 | apexBundleName := a.Name() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 662 | for _, fi := range a.filesInfo { |
Jiyong Park | a594801 | 2020-02-07 10:15:14 +0900 | [diff] [blame] | 663 | dir := filepath.Join("apex", apexBundleName, fi.installDir) |
Jiyong Park | cbe50c7 | 2020-05-29 21:29:20 +0900 | [diff] [blame] | 664 | target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.Stem(), fi.builtFile) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 665 | for _, sym := range fi.symlinks { |
| 666 | ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target) |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | } |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 672 | |
| 673 | func (a *apexBundle) getOverrideManifestPackageName(ctx android.ModuleContext) string { |
| 674 | // For VNDK APEXes, check "com.android.vndk" in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES |
| 675 | // to see if it should be overridden because their <apex name> is dynamically generated |
| 676 | // according to its VNDK version. |
| 677 | if a.vndkApex { |
| 678 | overrideName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(vndkApexName) |
| 679 | if overridden { |
| 680 | return strings.Replace(*a.properties.Apex_name, vndkApexName, overrideName, 1) |
| 681 | } |
| 682 | return "" |
| 683 | } |
Baligh Uddin | cb6aa12 | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 684 | if a.overridableProperties.Package_name != "" { |
| 685 | return a.overridableProperties.Package_name |
| 686 | } |
Jiyong Park | a519c54 | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 687 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 688 | if overridden { |
| 689 | return manifestPackageName |
| 690 | } |
| 691 | return "" |
| 692 | } |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 693 | |
| 694 | func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) { |
| 695 | if !a.primaryApexType { |
| 696 | return |
| 697 | } |
| 698 | |
| 699 | if a.properties.IsCoverageVariant { |
| 700 | // Otherwise, we will have duplicated rules for coverage and |
| 701 | // non-coverage variants of the same APEX |
| 702 | return |
| 703 | } |
| 704 | |
| 705 | if ctx.Host() { |
| 706 | // No need to generate dependency info for host variant |
| 707 | return |
| 708 | } |
| 709 | |
Artur Satayev | 334b517 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 710 | depInfos := android.DepNameToDepInfoMap{} |
| 711 | a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { |
| 712 | if from.Name() == to.Name() { |
| 713 | // This can happen for cc.reuseObjTag. We are not interested in tracking this. |
| 714 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 715 | return !externalDep |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 716 | } |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 717 | |
Artur Satayev | 334b517 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 718 | if info, exists := depInfos[to.Name()]; exists { |
| 719 | if !android.InList(from.Name(), info.From) { |
| 720 | info.From = append(info.From, from.Name()) |
| 721 | } |
| 722 | info.IsExternal = info.IsExternal && externalDep |
| 723 | depInfos[to.Name()] = info |
| 724 | } else { |
Artur Satayev | 388d39b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 725 | toMinSdkVersion := "(no version)" |
| 726 | if m, ok := to.(interface{ MinSdkVersion() string }); ok { |
| 727 | if v := m.MinSdkVersion(); v != "" { |
| 728 | toMinSdkVersion = v |
| 729 | } |
| 730 | } |
| 731 | |
Artur Satayev | 334b517 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 732 | depInfos[to.Name()] = android.ApexModuleDepInfo{ |
Artur Satayev | 388d39b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 733 | To: to.Name(), |
| 734 | From: []string{from.Name()}, |
| 735 | IsExternal: externalDep, |
| 736 | MinSdkVersion: toMinSdkVersion, |
Artur Satayev | 334b517 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
| 740 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 741 | return !externalDep |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 742 | }) |
| 743 | |
Artur Satayev | 388d39b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 744 | a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, proptools.String(a.properties.Min_sdk_version), depInfos) |
Artur Satayev | 334b517 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 745 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 746 | ctx.Build(pctx, android.BuildParams{ |
| 747 | Rule: android.Phony, |
| 748 | Output: android.PathForPhony(ctx, a.Name()+"-deps-info"), |
Artur Satayev | 5e7c32d | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 749 | Inputs: []android.Path{ |
| 750 | a.ApexBundleDepsInfo.FullListPath(), |
| 751 | a.ApexBundleDepsInfo.FlatListPath(), |
| 752 | }, |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 753 | }) |
| 754 | } |