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