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