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