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