Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 18 | "encoding/json" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 19 | "fmt" |
| 20 | "path/filepath" |
| 21 | "runtime" |
| 22 | "sort" |
Nikita Ioffe | 5335bc4 | 2020-10-20 00:02:15 +0100 | [diff] [blame] | 23 | "strconv" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 24 | "strings" |
| 25 | |
| 26 | "android/soong/android" |
| 27 | "android/soong/java" |
| 28 | |
| 29 | "github.com/google/blueprint" |
| 30 | "github.com/google/blueprint/proptools" |
| 31 | ) |
| 32 | |
| 33 | var ( |
| 34 | pctx = android.NewPackageContext("android/apex") |
| 35 | ) |
| 36 | |
| 37 | func init() { |
| 38 | pctx.Import("android/soong/android") |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 39 | pctx.Import("android/soong/cc/config") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 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") |
Huang Jianan | 13cac63 | 2021-08-02 15:02:17 +0800 | [diff] [blame] | 68 | pctx.HostBinToolVariable("make_erofs", "make_erofs") |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 69 | pctx.HostBinToolVariable("apex_compression_tool", "apex_compression_tool") |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 70 | pctx.HostBinToolVariable("dexdeps", "dexdeps") |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 71 | pctx.SourcePathVariable("genNdkUsedbyApexPath", "build/soong/scripts/gen_ndk_usedby_apex.sh") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | var ( |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 75 | apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{ |
| 76 | Command: `rm -f $out && ${jsonmodify} $in ` + |
| 77 | `-a provideNativeLibs ${provideNativeLibs} ` + |
| 78 | `-a requireNativeLibs ${requireNativeLibs} ` + |
| 79 | `${opt} ` + |
| 80 | `-o $out`, |
| 81 | CommandDeps: []string{"${jsonmodify}"}, |
| 82 | Description: "prepare ${out}", |
| 83 | }, "provideNativeLibs", "requireNativeLibs", "opt") |
| 84 | |
| 85 | stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{ |
| 86 | Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`, |
| 87 | CommandDeps: []string{"${conv_apex_manifest}"}, |
| 88 | Description: "strip ${in}=>${out}", |
| 89 | }) |
| 90 | |
| 91 | pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{ |
| 92 | Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`, |
| 93 | CommandDeps: []string{"${conv_apex_manifest}"}, |
| 94 | Description: "convert ${in}=>${out}", |
| 95 | }) |
| 96 | |
Joe Onorato | b4638c1 | 2021-10-27 15:47:06 -0700 | [diff] [blame] | 97 | // TODO(b/113233103): make sure that file_contexts is as expected, i.e., validate |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 98 | // against the binary policy using sefcontext_compiler -p <policy>. |
| 99 | |
| 100 | // TODO(b/114327326): automate the generation of file_contexts |
| 101 | apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{ |
| 102 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
| 103 | `(. ${out}.copy_commands) && ` + |
| 104 | `APEXER_TOOL_PATH=${tool_path} ` + |
| 105 | `${apexer} --force --manifest ${manifest} ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 106 | `--file_contexts ${file_contexts} ` + |
| 107 | `--canned_fs_config ${canned_fs_config} ` + |
Dario Freni | 0f4ae07 | 2020-01-02 15:24:12 +0000 | [diff] [blame] | 108 | `--include_build_info ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 109 | `--payload_type image ` + |
| 110 | `--key ${key} ${opt_flags} ${image_dir} ${out} `, |
| 111 | CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}", |
Huang Jianan | 13cac63 | 2021-08-02 15:02:17 +0800 | [diff] [blame] | 112 | "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", "${sload_f2fs}", "${make_erofs}", |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 113 | "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"}, |
| 114 | Rspfile: "${out}.copy_commands", |
| 115 | RspfileContent: "${copy_commands}", |
| 116 | Description: "APEX ${image_dir} => ${out}", |
Theotime Combes | 4ba38c1 | 2020-06-12 12:46:59 +0000 | [diff] [blame] | 117 | }, "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] | 118 | |
| 119 | zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ |
| 120 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
| 121 | `(. ${out}.copy_commands) && ` + |
| 122 | `APEXER_TOOL_PATH=${tool_path} ` + |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 123 | `${apexer} --force --manifest ${manifest} ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 124 | `--payload_type zip ` + |
| 125 | `${image_dir} ${out} `, |
| 126 | CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"}, |
| 127 | Rspfile: "${out}.copy_commands", |
| 128 | RspfileContent: "${copy_commands}", |
| 129 | Description: "ZipAPEX ${image_dir} => ${out}", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 130 | }, "tool_path", "image_dir", "copy_commands", "manifest") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 131 | |
| 132 | apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule", |
| 133 | blueprint.RuleParams{ |
| 134 | Command: `${aapt2} convert --output-format proto $in -o $out`, |
| 135 | CommandDeps: []string{"${aapt2}"}, |
| 136 | }) |
| 137 | |
| 138 | apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{ |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 139 | Command: `${zip2zip} -i $in -o $out.base ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 140 | `apex_payload.img:apex/${abi}.img ` + |
Dario Freni | da1aefe | 2020-03-02 21:47:09 +0000 | [diff] [blame] | 141 | `apex_build_info.pb:apex/${abi}.build_info.pb ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 142 | `apex_manifest.json:root/apex_manifest.json ` + |
Jiyong Park | 53ae334 | 2019-12-08 02:06:24 +0900 | [diff] [blame] | 143 | `apex_manifest.pb:root/apex_manifest.pb ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 144 | `AndroidManifest.xml:manifest/AndroidManifest.xml ` + |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 145 | `assets/NOTICE.html.gz:assets/NOTICE.html.gz &&` + |
| 146 | `${soong_zip} -o $out.config -C $$(dirname ${config}) -f ${config} && ` + |
| 147 | `${merge_zips} $out $out.base $out.config`, |
| 148 | CommandDeps: []string{"${zip2zip}", "${soong_zip}", "${merge_zips}"}, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 149 | Description: "app bundle", |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 150 | }, "abi", "config") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 151 | |
| 152 | emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{ |
| 153 | Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`, |
| 154 | Rspfile: "${out}.emit_commands", |
| 155 | RspfileContent: "${emit_commands}", |
| 156 | Description: "Emit APEX image content", |
| 157 | }, "emit_commands") |
| 158 | |
| 159 | diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{ |
| 160 | Command: `diff --unchanged-group-format='' \` + |
| 161 | `--changed-group-format='%<' \` + |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 162 | `${image_content_file} ${allowed_files_file} || (` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 163 | `echo -e "New unexpected files were added to ${apex_module_name}." ` + |
| 164 | ` "To fix the build run following command:" && ` + |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 165 | `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] | 166 | `exit 1); touch ${out}`, |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 167 | Description: "Diff ${image_content_file} and ${allowed_files_file}", |
| 168 | }, "image_content_file", "allowed_files_file", "apex_module_name") |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 169 | |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 170 | generateAPIsUsedbyApexRule = pctx.StaticRule("generateAPIsUsedbyApexRule", blueprint.RuleParams{ |
| 171 | Command: "$genNdkUsedbyApexPath ${image_dir} ${readelf} ${out}", |
| 172 | CommandDeps: []string{"${genNdkUsedbyApexPath}"}, |
| 173 | Description: "Generate symbol list used by Apex", |
| 174 | }, "image_dir", "readelf") |
| 175 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 176 | // Don't add more rules here. Consider using android.NewRuleBuilder instead. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 177 | ) |
| 178 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 179 | // buildManifest creates buile rules to modify the input apex_manifest.json to add information |
| 180 | // gathered by the build system such as provided/required native libraries. Two output files having |
| 181 | // different formats are generated. a.manifestJsonOut is JSON format for Q devices, and |
| 182 | // a.manifest.PbOut is protobuf format for R+ devices. |
| 183 | // 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] | 184 | func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, requireNativeLibs []string) { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 185 | src := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 186 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 187 | // Put dependency({provide|require}NativeLibs) in apex_manifest.json |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 188 | provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs) |
| 189 | requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs)) |
| 190 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 191 | // APEX name can be overridden |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 192 | optCommands := []string{} |
| 193 | if a.properties.Apex_name != nil { |
| 194 | optCommands = append(optCommands, "-v name "+*a.properties.Apex_name) |
| 195 | } |
| 196 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 197 | // Collect jniLibs. Notice that a.filesInfo is already sorted |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 198 | var jniLibs []string |
| 199 | for _, fi := range a.filesInfo { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 200 | if fi.isJniLib && !android.InList(fi.stem(), jniLibs) { |
| 201 | jniLibs = append(jniLibs, fi.stem()) |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | if len(jniLibs) > 0 { |
| 205 | optCommands = append(optCommands, "-a jniLibs "+strings.Join(jniLibs, " ")) |
| 206 | } |
| 207 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 208 | manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 209 | ctx.Build(pctx, android.BuildParams{ |
| 210 | Rule: apexManifestRule, |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 211 | Input: src, |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 212 | Output: manifestJsonFullOut, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 213 | Args: map[string]string{ |
| 214 | "provideNativeLibs": strings.Join(provideNativeLibs, " "), |
| 215 | "requireNativeLibs": strings.Join(requireNativeLibs, " "), |
| 216 | "opt": strings.Join(optCommands, " "), |
| 217 | }, |
| 218 | }) |
| 219 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 220 | // b/143654022 Q apexd can't understand newly added keys in apex_manifest.json prepare |
| 221 | // 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] | 222 | minSdkVersion := a.minSdkVersion(ctx) |
| 223 | if minSdkVersion.EqualTo(android.SdkVersion_Android10) { |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 224 | a.manifestJsonOut = android.PathForModuleOut(ctx, "apex_manifest.json") |
| 225 | ctx.Build(pctx, android.BuildParams{ |
| 226 | Rule: stripApexManifestRule, |
| 227 | Input: manifestJsonFullOut, |
| 228 | Output: a.manifestJsonOut, |
| 229 | }) |
| 230 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 231 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 232 | // 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] | 233 | a.manifestPbOut = android.PathForModuleOut(ctx, "apex_manifest.pb") |
| 234 | ctx.Build(pctx, android.BuildParams{ |
| 235 | Rule: pbApexManifestRule, |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 236 | Input: manifestJsonFullOut, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 237 | Output: a.manifestPbOut, |
| 238 | }) |
| 239 | } |
| 240 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 241 | // buildFileContexts create build rules to append an entry for apex_manifest.pb to the file_contexts |
| 242 | // file for this APEX which is either from /systme/sepolicy/apex/<apexname>-file_contexts or from |
| 243 | // the file_contexts property of this APEX. This is to make sure that the manifest file is correctly |
| 244 | // labeled as system_file. |
| 245 | func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) android.OutputPath { |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 246 | var fileContexts android.Path |
Liz Kammer | 37997c4 | 2021-09-14 17:53:38 -0400 | [diff] [blame] | 247 | var fileContextsDir string |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 248 | if a.properties.File_contexts == nil { |
| 249 | fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts") |
| 250 | } else { |
Liz Kammer | 37997c4 | 2021-09-14 17:53:38 -0400 | [diff] [blame] | 251 | if m, t := android.SrcIsModuleWithTag(*a.properties.File_contexts); m != "" { |
| 252 | otherModule := android.GetModuleFromPathDep(ctx, m, t) |
| 253 | fileContextsDir = ctx.OtherModuleDir(otherModule) |
| 254 | } |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 255 | fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts) |
| 256 | } |
Liz Kammer | 37997c4 | 2021-09-14 17:53:38 -0400 | [diff] [blame] | 257 | if fileContextsDir == "" { |
| 258 | fileContextsDir = filepath.Dir(fileContexts.String()) |
| 259 | } |
| 260 | fileContextsDir += string(filepath.Separator) |
| 261 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 262 | if a.Platform() { |
Liz Kammer | 37997c4 | 2021-09-14 17:53:38 -0400 | [diff] [blame] | 263 | if !strings.HasPrefix(fileContextsDir, "system/sepolicy/") { |
| 264 | ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but found in %q", fileContextsDir) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | if !android.ExistentPathForSource(ctx, fileContexts.String()).Valid() { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 268 | ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", fileContexts.String()) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | output := android.PathForModuleOut(ctx, "file_contexts") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 272 | rule := android.NewRuleBuilder(pctx, ctx) |
Jooyung Han | 7f146c0 | 2020-09-23 19:15:55 +0900 | [diff] [blame] | 273 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 274 | switch a.properties.ApexType { |
| 275 | case imageApex: |
Jooyung Han | 7f146c0 | 2020-09-23 19:15:55 +0900 | [diff] [blame] | 276 | // remove old file |
| 277 | rule.Command().Text("rm").FlagWithOutput("-f ", output) |
| 278 | // copy file_contexts |
| 279 | rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output) |
| 280 | // new line |
| 281 | rule.Command().Text("echo").Text(">>").Output(output) |
| 282 | // force-label /apex_manifest.pb and / as system_file so that apexd can read them |
| 283 | rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output) |
| 284 | 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] | 285 | case flattenedApex: |
Jooyung Han | 7f146c0 | 2020-09-23 19:15:55 +0900 | [diff] [blame] | 286 | // For flattened apexes, install path should be prepended. |
| 287 | // File_contexts file should be emiited to make via LOCAL_FILE_CONTEXTS |
| 288 | // so that it can be merged into file_contexts.bin |
| 289 | apexPath := android.InstallPathToOnDevicePath(ctx, a.installDir.Join(ctx, a.Name())) |
| 290 | apexPath = strings.ReplaceAll(apexPath, ".", `\\.`) |
| 291 | // remove old file |
| 292 | rule.Command().Text("rm").FlagWithOutput("-f ", output) |
| 293 | // copy file_contexts |
| 294 | rule.Command().Text("awk").Text(`'/object_r/{printf("` + apexPath + `%s\n", $0)}'`).Input(fileContexts).Text(">").Output(output) |
| 295 | // new line |
| 296 | rule.Command().Text("echo").Text(">>").Output(output) |
| 297 | // force-label /apex_manifest.pb and / as system_file so that apexd can read them |
| 298 | rule.Command().Text("echo").Flag(apexPath + `/apex_manifest\\.pb u:object_r:system_file:s0`).Text(">>").Output(output) |
| 299 | 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] | 300 | default: |
| 301 | panic(fmt.Errorf("unsupported type %v", a.properties.ApexType)) |
Jooyung Han | 7f146c0 | 2020-09-23 19:15:55 +0900 | [diff] [blame] | 302 | } |
| 303 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 304 | rule.Build("file_contexts."+a.Name(), "Generate file_contexts") |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 305 | return output.OutputPath |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 306 | } |
| 307 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 308 | // buildNoticeFiles creates a buile rule for aggregating notice files from the modules that |
| 309 | // 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] | 310 | func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName string) android.NoticeOutputs { |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 311 | var noticeFiles android.Paths |
| 312 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 313 | 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] | 314 | if externalDep { |
Paul Duffin | be5a5be | 2020-03-30 15:54:08 +0100 | [diff] [blame] | 315 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 316 | return false |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 317 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 318 | noticeFiles = append(noticeFiles, to.NoticeFiles()...) |
Paul Duffin | be5a5be | 2020-03-30 15:54:08 +0100 | [diff] [blame] | 319 | return true |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 320 | }) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 321 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 322 | // 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] | 323 | for _, fi := range a.filesInfo { |
| 324 | noticeFiles = append(noticeFiles, fi.noticeFiles...) |
| 325 | } |
| 326 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 327 | if len(noticeFiles) == 0 { |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 328 | return android.NoticeOutputs{} |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 329 | } |
| 330 | |
Jiyong Park | 33c7736 | 2020-05-29 22:00:16 +0900 | [diff] [blame] | 331 | return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.SortedUniquePaths(noticeFiles)) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 332 | } |
| 333 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 334 | // buildInstalledFilesFile creates a build rule for the installed-files.txt file where the list of |
| 335 | // files included in this APEX is shown. The text file is dist'ed so that people can see what's |
| 336 | // included in the APEX without actually downloading and extracting it. |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 337 | func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApex android.Path, imageDir android.Path) android.OutputPath { |
| 338 | output := android.PathForModuleOut(ctx, "installed-files.txt") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 339 | rule := android.NewRuleBuilder(pctx, ctx) |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 340 | rule.Command(). |
| 341 | Implicit(builtApex). |
| 342 | Text("(cd " + imageDir.String() + " ; "). |
Jiyong Park | bd63a10 | 2020-02-08 12:40:05 +0900 | [diff] [blame] | 343 | Text("find . \\( -type f -o -type l \\) -printf \"%s %p\\n\") "). |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 344 | Text(" | sort -nr > "). |
| 345 | Output(output) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 346 | rule.Build("installed-files."+a.Name(), "Installed files") |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 347 | return output.OutputPath |
| 348 | } |
| 349 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 350 | // buildBundleConfig creates a build rule for the bundle config file that will control the bundle |
| 351 | // creation process. |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 352 | func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath { |
| 353 | output := android.PathForModuleOut(ctx, "bundle_config.json") |
| 354 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 355 | type ApkConfig struct { |
| 356 | Package_name string `json:"package_name"` |
| 357 | Apk_path string `json:"path"` |
| 358 | } |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 359 | config := struct { |
| 360 | Compression struct { |
| 361 | Uncompressed_glob []string `json:"uncompressed_glob"` |
| 362 | } `json:"compression"` |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 363 | Apex_config struct { |
| 364 | Apex_embedded_apk_config []ApkConfig `json:"apex_embedded_apk_config,omitempty"` |
| 365 | } `json:"apex_config,omitempty"` |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 366 | }{} |
| 367 | |
| 368 | config.Compression.Uncompressed_glob = []string{ |
| 369 | "apex_payload.img", |
| 370 | "apex_manifest.*", |
| 371 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 372 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 373 | // Collect the manifest names and paths of android apps if their manifest names are |
| 374 | // overridden. |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 375 | for _, fi := range a.filesInfo { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 376 | if fi.class != app && fi.class != appSet { |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 377 | continue |
| 378 | } |
| 379 | packageName := fi.overriddenPackageName |
| 380 | if packageName != "" { |
| 381 | config.Apex_config.Apex_embedded_apk_config = append( |
| 382 | config.Apex_config.Apex_embedded_apk_config, |
| 383 | ApkConfig{ |
| 384 | Package_name: packageName, |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 385 | Apk_path: fi.path(), |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 386 | }) |
| 387 | } |
| 388 | } |
| 389 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 390 | j, err := json.Marshal(config) |
| 391 | if err != nil { |
| 392 | panic(fmt.Errorf("error while marshalling to %q: %#v", output, err)) |
| 393 | } |
| 394 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 395 | android.WriteFileRule(ctx, output, string(j)) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 396 | |
| 397 | return output.OutputPath |
| 398 | } |
| 399 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 400 | // buildUnflattendApex creates build rules to build an APEX using apexer. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 401 | func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 402 | apexType := a.properties.ApexType |
| 403 | suffix := apexType.suffix() |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 404 | apexName := proptools.StringDefault(a.properties.Apex_name, a.BaseModuleName()) |
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 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 411 | installSymbolFiles := !ctx.Config().KatiEnabled() || a.ExportedToMake() |
| 412 | |
| 413 | // b/140136207. When there are overriding APEXes for a VNDK APEX, the symbols file for the overridden |
| 414 | // APEX and the overriding APEX will have the same installation paths at /apex/com.android.vndk.v<ver> |
| 415 | // as their apexName will be the same. To avoid the path conflicts, skip installing the symbol files |
| 416 | // for the overriding VNDK APEXes. |
| 417 | if a.vndkApex && len(a.overridableProperties.Overrides) > 0 { |
| 418 | installSymbolFiles = false |
| 419 | } |
| 420 | |
| 421 | // Avoid creating duplicate build rules for multi-installed APEXes. |
| 422 | if proptools.BoolDefault(a.properties.Multi_install_skip_symbol_files, false) { |
| 423 | installSymbolFiles = false |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 424 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 425 | } |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 426 | // set of dependency module:location mappings |
| 427 | installMapSet := make(map[string]bool) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 428 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 429 | // TODO(jiyong): use the RuleBuilder |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 430 | var copyCommands []string |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 431 | var implicitInputs []android.Path |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 432 | pathWhenActivated := android.PathForModuleInPartitionInstall(ctx, "apex", apexName) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 433 | for _, fi := range a.filesInfo { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 434 | destPath := imageDir.Join(ctx, fi.path()).String() |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 435 | // Prepare the destination path |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 436 | destPathDir := filepath.Dir(destPath) |
| 437 | if fi.class == appSet { |
| 438 | copyCommands = append(copyCommands, "rm -rf "+destPathDir) |
| 439 | } |
| 440 | copyCommands = append(copyCommands, "mkdir -p "+destPathDir) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 441 | |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 442 | installMapPath := fi.builtFile |
| 443 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 444 | // Copy the built file to the directory. But if the symlink optimization is turned |
| 445 | // on, place a symlink to the corresponding file in /system partition instead. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 446 | if a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 447 | // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 448 | pathOnDevice := filepath.Join("/system", fi.path()) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 449 | copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath) |
| 450 | } else { |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 451 | var installedPath android.InstallPath |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 452 | if fi.class == appSet { |
| 453 | copyCommands = append(copyCommands, |
Colin Cross | ffbcd1d | 2021-11-12 12:19:42 -0800 | [diff] [blame] | 454 | fmt.Sprintf("unzip -qDD -d %s %s", destPathDir, |
| 455 | fi.module.(*java.AndroidAppSet).PackedAdditionalOutputs().String())) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 456 | if installSymbolFiles { |
| 457 | installedPath = ctx.InstallFileWithExtraFilesZip(pathWhenActivated.Join(ctx, fi.installDir), |
| 458 | fi.stem(), fi.builtFile, fi.module.(*java.AndroidAppSet).PackedAdditionalOutputs()) |
| 459 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 460 | } else { |
| 461 | copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 462 | if installSymbolFiles { |
| 463 | installedPath = ctx.InstallFile(pathWhenActivated.Join(ctx, fi.installDir), fi.stem(), fi.builtFile) |
| 464 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 465 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 466 | implicitInputs = append(implicitInputs, fi.builtFile) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 467 | if installSymbolFiles { |
| 468 | implicitInputs = append(implicitInputs, installedPath) |
| 469 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 470 | |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 471 | // Create additional symlinks pointing the file inside the APEX (if any). Note that |
| 472 | // this is independent from the symlink optimization. |
| 473 | for _, symlinkPath := range fi.symlinkPaths() { |
| 474 | symlinkDest := imageDir.Join(ctx, symlinkPath).String() |
| 475 | copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest) |
| 476 | if installSymbolFiles { |
| 477 | installedSymlink := ctx.InstallSymlink(pathWhenActivated.Join(ctx, filepath.Dir(symlinkPath)), filepath.Base(symlinkPath), installedPath) |
| 478 | implicitInputs = append(implicitInputs, installedSymlink) |
| 479 | } |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 480 | } |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 481 | |
| 482 | installMapPath = installedPath |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 483 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 484 | |
| 485 | // Copy the test files (if any) |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 486 | for _, d := range fi.dataPaths { |
| 487 | // 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] | 488 | relPath := d.SrcPath.Rel() |
| 489 | dataPath := d.SrcPath.String() |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 490 | if !strings.HasSuffix(dataPath, relPath) { |
| 491 | panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath)) |
| 492 | } |
| 493 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 494 | dataDest := imageDir.Join(ctx, fi.apexRelativePath(relPath), d.RelativeInstallPath).String() |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 495 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 496 | copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest) |
| 497 | implicitInputs = append(implicitInputs, d.SrcPath) |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 498 | } |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 499 | |
| 500 | installMapSet[installMapPath.String()+":"+fi.installDir+"/"+fi.builtFile.Base()] = true |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 501 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 502 | implicitInputs = append(implicitInputs, a.manifestPbOut) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 503 | if installSymbolFiles { |
| 504 | installedManifest := ctx.InstallFile(pathWhenActivated, "apex_manifest.pb", a.manifestPbOut) |
| 505 | installedKey := ctx.InstallFile(pathWhenActivated, "apex_pubkey", a.publicKeyFile) |
| 506 | implicitInputs = append(implicitInputs, installedManifest, installedKey) |
| 507 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 508 | |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 509 | if len(installMapSet) > 0 { |
| 510 | var installs []string |
| 511 | installs = append(installs, android.SortedStringKeys(installMapSet)...) |
| 512 | a.SetLicenseInstallMap(installs) |
| 513 | } |
| 514 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 515 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 516 | // Step 1.a: Write the list of files in this APEX to a txt file and compare it against |
| 517 | // the allowed list given via the allowed_files property. Build fails when the two lists |
| 518 | // differ. |
| 519 | // |
| 520 | // TODO(jiyong): consider removing this. Nobody other than com.android.apex.cts.shim.* seems |
| 521 | // to be using this at this moment. Furthermore, this looks very similar to what |
| 522 | // buildInstalledFilesFile does. At least, move this to somewhere else so that this doesn't |
| 523 | // hurt readability. |
| 524 | // TODO(jiyong): use RuleBuilder |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 525 | if a.overridableProperties.Allowed_files != nil { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 526 | // Build content.txt |
| 527 | var emitCommands []string |
| 528 | imageContentFile := android.PathForModuleOut(ctx, "content.txt") |
| 529 | emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String()) |
| 530 | minSdkVersion := a.minSdkVersion(ctx) |
| 531 | if minSdkVersion.EqualTo(android.SdkVersion_Android10) { |
| 532 | emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String()) |
| 533 | } |
| 534 | for _, fi := range a.filesInfo { |
| 535 | emitCommands = append(emitCommands, "echo './"+fi.path()+"' >> "+imageContentFile.String()) |
| 536 | } |
| 537 | emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 538 | ctx.Build(pctx, android.BuildParams{ |
| 539 | Rule: emitApexContentRule, |
| 540 | Implicits: implicitInputs, |
| 541 | Output: imageContentFile, |
| 542 | Description: "emit apex image content", |
| 543 | Args: map[string]string{ |
| 544 | "emit_commands": strings.Join(emitCommands, " && "), |
| 545 | }, |
| 546 | }) |
| 547 | implicitInputs = append(implicitInputs, imageContentFile) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 548 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 549 | // Compare content.txt against allowed_files. |
| 550 | allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files)) |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 551 | phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 552 | ctx.Build(pctx, android.BuildParams{ |
| 553 | Rule: diffApexContentRule, |
| 554 | Implicits: implicitInputs, |
| 555 | Output: phonyOutput, |
| 556 | Description: "diff apex image content", |
| 557 | Args: map[string]string{ |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 558 | "allowed_files_file": allowedFilesFile.String(), |
| 559 | "image_content_file": imageContentFile.String(), |
| 560 | "apex_module_name": a.Name(), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 561 | }, |
| 562 | }) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 563 | implicitInputs = append(implicitInputs, phonyOutput) |
| 564 | } |
| 565 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 566 | unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned") |
Colin Cross | 790ef35 | 2021-10-25 19:15:55 -0700 | [diff] [blame] | 567 | outHostBinDir := ctx.Config().HostToolPath(ctx, "").String() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 568 | prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") |
| 569 | |
Nikita Ioffe | bc03588 | 2021-04-14 21:35:24 +0100 | [diff] [blame] | 570 | // Figure out if need to compress apex. |
Nikita Ioffe | b6ea6c2 | 2021-04-19 13:07:24 +0100 | [diff] [blame] | 571 | compressionEnabled := ctx.Config().CompressedApex() && proptools.BoolDefault(a.properties.Compressible, false) && !a.testApex && !ctx.Config().UnbundledBuildApps() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 572 | if apexType == imageApex { |
Jiyong Park | 1b0893e | 2021-12-13 23:40:17 +0900 | [diff] [blame^] | 573 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 574 | //////////////////////////////////////////////////////////////////////////////////// |
| 575 | // Step 2: create canned_fs_config which encodes filemode,uid,gid of each files |
| 576 | // in this APEX. The file will be used by apexer in later steps. |
Jiyong Park | 1b0893e | 2021-12-13 23:40:17 +0900 | [diff] [blame^] | 577 | cannedFsConfig := a.buildCannedFsConfig(ctx) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 578 | implicitInputs = append(implicitInputs, cannedFsConfig) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 579 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 580 | //////////////////////////////////////////////////////////////////////////////////// |
| 581 | // Step 3: Prepare option flags for apexer and invoke it to create an unsigned APEX. |
| 582 | // TODO(jiyong): use the RuleBuilder |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 583 | optFlags := []string{} |
| 584 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 585 | fileContexts := a.buildFileContexts(ctx) |
| 586 | implicitInputs = append(implicitInputs, fileContexts) |
| 587 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 588 | implicitInputs = append(implicitInputs, a.privateKeyFile, a.publicKeyFile) |
| 589 | optFlags = append(optFlags, "--pubkey "+a.publicKeyFile.String()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 590 | |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 591 | manifestPackageName := a.getOverrideManifestPackageName(ctx) |
| 592 | if manifestPackageName != "" { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 593 | optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName) |
| 594 | } |
| 595 | |
| 596 | if a.properties.AndroidManifest != nil { |
| 597 | androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest)) |
| 598 | implicitInputs = append(implicitInputs, androidManifestFile) |
| 599 | optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String()) |
| 600 | } |
| 601 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 602 | // Determine target/min sdk version from the context |
| 603 | // TODO(jiyong): make this as a function |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 604 | moduleMinSdkVersion := a.minSdkVersion(ctx) |
Nikita Ioffe | 5335bc4 | 2020-10-20 00:02:15 +0100 | [diff] [blame] | 605 | minSdkVersion := moduleMinSdkVersion.String() |
| 606 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 607 | // bundletool doesn't understand what "current" is. We need to transform it to |
| 608 | // codename |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 609 | if moduleMinSdkVersion.IsCurrent() || moduleMinSdkVersion.IsNone() { |
Nikita Ioffe | 5335bc4 | 2020-10-20 00:02:15 +0100 | [diff] [blame] | 610 | minSdkVersion = ctx.Config().DefaultAppTargetSdk(ctx).String() |
Liz Kammer | 4854a7d | 2021-05-27 14:28:27 -0400 | [diff] [blame] | 611 | |
| 612 | if java.UseApiFingerprint(ctx) { |
| 613 | minSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String()) |
| 614 | implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx)) |
| 615 | } |
Nikita Ioffe | 5d600c9 | 2020-02-20 00:43:27 +0000 | [diff] [blame] | 616 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 617 | // apex module doesn't have a concept of target_sdk_version, hence for the time |
| 618 | // being targetSdkVersion == default targetSdkVersion of the branch. |
Nikita Ioffe | 5335bc4 | 2020-10-20 00:02:15 +0100 | [diff] [blame] | 619 | targetSdkVersion := strconv.Itoa(ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt()) |
Nikita Ioffe | 5d600c9 | 2020-02-20 00:43:27 +0000 | [diff] [blame] | 620 | |
Nikita Ioffe | 1f4f345 | 2020-03-02 16:58:11 +0000 | [diff] [blame] | 621 | if java.UseApiFingerprint(ctx) { |
| 622 | targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String()) |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 623 | implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx)) |
| 624 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 625 | optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion) |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 626 | optFlags = append(optFlags, "--min_sdk_version "+minSdkVersion) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 627 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 628 | if a.overridableProperties.Logging_parent != "" { |
| 629 | optFlags = append(optFlags, "--logging_parent ", a.overridableProperties.Logging_parent) |
| 630 | } |
| 631 | |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 632 | a.mergedNotices = a.buildNoticeFiles(ctx, a.Name()+suffix) |
| 633 | if a.mergedNotices.HtmlGzOutput.Valid() { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 634 | // 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] | 635 | implicitInputs = append(implicitInputs, a.mergedNotices.HtmlGzOutput.Path()) |
| 636 | optFlags = append(optFlags, "--assets_dir "+filepath.Dir(a.mergedNotices.HtmlGzOutput.String())) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 637 | } |
| 638 | |
Nikita Ioffe | 9d9960f | 2021-06-09 19:43:46 +0100 | [diff] [blame] | 639 | if (moduleMinSdkVersion.GreaterThan(android.SdkVersion_Android10) && !a.shouldGenerateHashtree()) && !compressionEnabled { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 640 | // Apexes which are supposed to be installed in builtin dirs(/system, etc) |
| 641 | // don't need hashtree for activation. Therefore, by removing hashtree from |
| 642 | // apex bundle (filesystem image in it, to be specific), we can save storage. |
| 643 | optFlags = append(optFlags, "--no_hashtree") |
| 644 | } |
| 645 | |
Dario Freni | ca91339 | 2020-04-27 18:21:11 +0100 | [diff] [blame] | 646 | if a.testOnlyShouldSkipPayloadSign() { |
| 647 | optFlags = append(optFlags, "--unsigned_payload") |
| 648 | } |
| 649 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 650 | if a.properties.Apex_name != nil { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 651 | // If apex_name is set, apexer can skip checking if key name matches with |
| 652 | // apex name. Note that apex_manifest is also mended. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 653 | optFlags = append(optFlags, "--do_not_check_keyname") |
| 654 | } |
| 655 | |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 656 | if moduleMinSdkVersion == android.SdkVersion_Android10 { |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 657 | implicitInputs = append(implicitInputs, a.manifestJsonOut) |
| 658 | optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String()) |
| 659 | } |
| 660 | |
Theotime Combes | 4ba38c1 | 2020-06-12 12:46:59 +0000 | [diff] [blame] | 661 | optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string()) |
| 662 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 663 | ctx.Build(pctx, android.BuildParams{ |
| 664 | Rule: apexRule, |
| 665 | Implicits: implicitInputs, |
| 666 | Output: unsignedOutputFile, |
| 667 | Description: "apex (" + apexType.name() + ")", |
| 668 | Args: map[string]string{ |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 669 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 670 | "image_dir": imageDir.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 671 | "copy_commands": strings.Join(copyCommands, " && "), |
| 672 | "manifest": a.manifestPbOut.String(), |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 673 | "file_contexts": fileContexts.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 674 | "canned_fs_config": cannedFsConfig.String(), |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 675 | "key": a.privateKeyFile.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 676 | "opt_flags": strings.Join(optFlags, " "), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 677 | }, |
| 678 | }) |
| 679 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 680 | // TODO(jiyong): make the two rules below as separate functions |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 681 | apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix) |
| 682 | bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 683 | a.bundleModuleFile = bundleModuleFile |
| 684 | |
| 685 | ctx.Build(pctx, android.BuildParams{ |
| 686 | Rule: apexProtoConvertRule, |
| 687 | Input: unsignedOutputFile, |
| 688 | Output: apexProtoFile, |
| 689 | Description: "apex proto convert", |
| 690 | }) |
| 691 | |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 692 | implicitInputs = append(implicitInputs, unsignedOutputFile) |
| 693 | |
| 694 | // Run coverage analysis |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 695 | apisUsedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_using.txt") |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 696 | ctx.Build(pctx, android.BuildParams{ |
| 697 | Rule: generateAPIsUsedbyApexRule, |
| 698 | Implicits: implicitInputs, |
| 699 | Description: "coverage", |
| 700 | Output: apisUsedbyOutputFile, |
| 701 | Args: map[string]string{ |
| 702 | "image_dir": imageDir.String(), |
| 703 | "readelf": "${config.ClangBin}/llvm-readelf", |
| 704 | }, |
| 705 | }) |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 706 | a.nativeApisUsedByModuleFile = apisUsedbyOutputFile |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 707 | |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 708 | var nativeLibNames []string |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame] | 709 | for _, f := range a.filesInfo { |
| 710 | if f.class == nativeSharedLib { |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 711 | nativeLibNames = append(nativeLibNames, f.stem()) |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame] | 712 | } |
| 713 | } |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 714 | apisBackedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_backing.txt") |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 715 | rule := android.NewRuleBuilder(pctx, ctx) |
| 716 | rule.Command(). |
| 717 | Tool(android.PathForSource(ctx, "build/soong/scripts/gen_ndk_backedby_apex.sh")). |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 718 | Output(apisBackedbyOutputFile). |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 719 | Flags(nativeLibNames) |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 720 | rule.Build("ndk_backedby_list", "Generate API libraries backed by Apex") |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 721 | a.nativeApisBackedByModuleFile = apisBackedbyOutputFile |
| 722 | |
| 723 | var javaLibOrApkPath []android.Path |
| 724 | for _, f := range a.filesInfo { |
| 725 | if f.class == javaSharedLib || f.class == app { |
| 726 | javaLibOrApkPath = append(javaLibOrApkPath, f.builtFile) |
| 727 | } |
| 728 | } |
| 729 | javaApiUsedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_using.xml") |
| 730 | javaUsedByRule := android.NewRuleBuilder(pctx, ctx) |
| 731 | javaUsedByRule.Command(). |
| 732 | Tool(android.PathForSource(ctx, "build/soong/scripts/gen_java_usedby_apex.sh")). |
| 733 | BuiltTool("dexdeps"). |
| 734 | Output(javaApiUsedbyOutputFile). |
| 735 | Inputs(javaLibOrApkPath) |
| 736 | javaUsedByRule.Build("java_usedby_list", "Generate Java APIs used by Apex") |
| 737 | a.javaApisUsedByModuleFile = javaApiUsedbyOutputFile |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 738 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 739 | bundleConfig := a.buildBundleConfig(ctx) |
| 740 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 741 | var abis []string |
| 742 | for _, target := range ctx.MultiTargets() { |
| 743 | if len(target.Arch.Abi) > 0 { |
| 744 | abis = append(abis, target.Arch.Abi[0]) |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | abis = android.FirstUniqueStrings(abis) |
| 749 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 750 | ctx.Build(pctx, android.BuildParams{ |
| 751 | Rule: apexBundleRule, |
| 752 | Input: apexProtoFile, |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 753 | Implicit: bundleConfig, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 754 | Output: a.bundleModuleFile, |
| 755 | Description: "apex bundle module", |
| 756 | Args: map[string]string{ |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 757 | "abi": strings.Join(abis, "."), |
| 758 | "config": bundleConfig.String(), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 759 | }, |
| 760 | }) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 761 | } else { // zipApex |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 762 | ctx.Build(pctx, android.BuildParams{ |
| 763 | Rule: zipApexRule, |
| 764 | Implicits: implicitInputs, |
| 765 | Output: unsignedOutputFile, |
| 766 | Description: "apex (" + apexType.name() + ")", |
| 767 | Args: map[string]string{ |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 768 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 769 | "image_dir": imageDir.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 770 | "copy_commands": strings.Join(copyCommands, " && "), |
| 771 | "manifest": a.manifestPbOut.String(), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 772 | }, |
| 773 | }) |
| 774 | } |
| 775 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 776 | //////////////////////////////////////////////////////////////////////////////////// |
| 777 | // Step 4: Sign the APEX using signapk |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 778 | signedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 779 | |
| 780 | pem, key := a.getCertificateAndPrivateKey(ctx) |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 781 | rule := java.Signapk |
| 782 | args := map[string]string{ |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 783 | "certificates": pem.String() + " " + key.String(), |
Jooyung Han | 5d00f50 | 2021-07-11 07:26:22 +0900 | [diff] [blame] | 784 | "flags": "-a 4096 --align-file-size", //alignment |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 785 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 786 | implicits := android.Paths{pem, key} |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 787 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_SIGNAPK") { |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 788 | rule = java.SignapkRE |
| 789 | args["implicits"] = strings.Join(implicits.Strings(), ",") |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 790 | args["outCommaList"] = signedOutputFile.String() |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 791 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 792 | ctx.Build(pctx, android.BuildParams{ |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 793 | Rule: rule, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 794 | Description: "signapk", |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 795 | Output: signedOutputFile, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 796 | Input: unsignedOutputFile, |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 797 | Implicits: implicits, |
| 798 | Args: args, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 799 | }) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 800 | a.outputFile = signedOutputFile |
| 801 | |
Mohammad Samiul Islam | a8008f9 | 2020-12-22 10:47:50 +0000 | [diff] [blame] | 802 | if ctx.ModuleDir() != "system/apex/apexd/apexd_testdata" && a.testOnlyShouldForceCompression() { |
| 803 | ctx.PropertyErrorf("test_only_force_compression", "not available") |
| 804 | return |
| 805 | } |
Nikita Ioffe | bc03588 | 2021-04-14 21:35:24 +0100 | [diff] [blame] | 806 | |
Mohammad Samiul Islam | a8008f9 | 2020-12-22 10:47:50 +0000 | [diff] [blame] | 807 | if apexType == imageApex && (compressionEnabled || a.testOnlyShouldForceCompression()) { |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 808 | a.isCompressed = true |
Samiul Islam | 7c02e26 | 2021-09-08 17:48:28 +0100 | [diff] [blame] | 809 | unsignedCompressedOutputFile := android.PathForModuleOut(ctx, a.Name()+imageCapexSuffix+".unsigned") |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 810 | |
| 811 | compressRule := android.NewRuleBuilder(pctx, ctx) |
| 812 | compressRule.Command(). |
| 813 | Text("rm"). |
| 814 | FlagWithOutput("-f ", unsignedCompressedOutputFile) |
| 815 | compressRule.Command(). |
| 816 | BuiltTool("apex_compression_tool"). |
| 817 | Flag("compress"). |
| 818 | FlagWithArg("--apex_compression_tool ", outHostBinDir+":"+prebuiltSdkToolsBinDir). |
| 819 | FlagWithInput("--input ", signedOutputFile). |
| 820 | FlagWithOutput("--output ", unsignedCompressedOutputFile) |
| 821 | compressRule.Build("compressRule", "Generate unsigned compressed APEX file") |
| 822 | |
Samiul Islam | 7c02e26 | 2021-09-08 17:48:28 +0100 | [diff] [blame] | 823 | signedCompressedOutputFile := android.PathForModuleOut(ctx, a.Name()+imageCapexSuffix) |
Mohammad Samiul Islam | 9ac0e32 | 2021-01-19 11:32:29 +0000 | [diff] [blame] | 824 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_SIGNAPK") { |
| 825 | args["outCommaList"] = signedCompressedOutputFile.String() |
| 826 | } |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 827 | ctx.Build(pctx, android.BuildParams{ |
| 828 | Rule: rule, |
| 829 | Description: "sign compressedApex", |
| 830 | Output: signedCompressedOutputFile, |
| 831 | Input: unsignedCompressedOutputFile, |
| 832 | Implicits: implicits, |
| 833 | Args: args, |
| 834 | }) |
| 835 | a.outputFile = signedCompressedOutputFile |
| 836 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 837 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 838 | installSuffix := suffix |
| 839 | if a.isCompressed { |
| 840 | installSuffix = imageCapexSuffix |
| 841 | } |
| 842 | |
Jiyong Park | 17ff283 | 2021-09-27 12:50:30 +0900 | [diff] [blame] | 843 | // Install to $OUT/soong/{target,host}/.../apex. |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 844 | a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile, |
| 845 | a.compatSymlinks.Paths()...) |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 846 | |
| 847 | // installed-files.txt is dist'ed |
| 848 | a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 849 | } |
| 850 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 851 | // buildFlattenedApex creates rules for a flattened APEX. Flattened APEX actually doesn't have a |
| 852 | // single output file. It is a phony target for all the files under /system/apex/<name> directory. |
| 853 | // This function creates the installation rules for the files. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 854 | func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 855 | bundleName := a.Name() |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 856 | installedSymlinks := append(android.InstallPaths(nil), a.compatSymlinks...) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 857 | if a.installable() { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 858 | for _, fi := range a.filesInfo { |
| 859 | dir := filepath.Join("apex", bundleName, fi.installDir) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 860 | installDir := android.PathForModuleInstall(ctx, dir) |
| 861 | if a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() { |
| 862 | // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here |
| 863 | pathOnDevice := filepath.Join("/system", fi.path()) |
| 864 | installedSymlinks = append(installedSymlinks, |
| 865 | ctx.InstallAbsoluteSymlink(installDir, fi.stem(), pathOnDevice)) |
| 866 | } else { |
| 867 | target := ctx.InstallFile(installDir, fi.stem(), fi.builtFile) |
| 868 | for _, sym := range fi.symlinks { |
| 869 | installedSymlinks = append(installedSymlinks, |
| 870 | ctx.InstallSymlink(installDir, sym, target)) |
| 871 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 872 | } |
| 873 | } |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 874 | |
| 875 | // Create install rules for the files added in GenerateAndroidBuildActions after |
| 876 | // buildFlattenedApex is called. Add the links to system libs (if any) as dependencies |
| 877 | // of the apex_manifest.pb file since it is always present. |
| 878 | dir := filepath.Join("apex", bundleName) |
| 879 | installDir := android.PathForModuleInstall(ctx, dir) |
| 880 | ctx.InstallFile(installDir, "apex_manifest.pb", a.manifestPbOut, installedSymlinks.Paths()...) |
| 881 | ctx.InstallFile(installDir, "apex_pubkey", a.publicKeyFile) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 882 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 883 | |
| 884 | a.fileContexts = a.buildFileContexts(ctx) |
| 885 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 886 | a.outputFile = android.PathForModuleInstall(ctx, "apex", bundleName) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | // getCertificateAndPrivateKey retrieves the cert and the private key that will be used to sign |
| 890 | // the zip container of this APEX. See the description of the 'certificate' property for how |
| 891 | // the cert and the private key are found. |
| 892 | func (a *apexBundle) getCertificateAndPrivateKey(ctx android.PathContext) (pem, key android.Path) { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 893 | if a.containerCertificateFile != nil { |
| 894 | return a.containerCertificateFile, a.containerPrivateKeyFile |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 895 | } |
| 896 | |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 897 | cert := String(a.overridableProperties.Certificate) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 898 | if cert == "" { |
| 899 | return ctx.Config().DefaultAppCertificate(ctx) |
| 900 | } |
| 901 | |
| 902 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
| 903 | pem = defaultDir.Join(ctx, cert+".x509.pem") |
| 904 | key = defaultDir.Join(ctx, cert+".pk8") |
| 905 | return pem, key |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 906 | } |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 907 | |
| 908 | func (a *apexBundle) getOverrideManifestPackageName(ctx android.ModuleContext) string { |
| 909 | // For VNDK APEXes, check "com.android.vndk" in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES |
| 910 | // to see if it should be overridden because their <apex name> is dynamically generated |
| 911 | // according to its VNDK version. |
| 912 | if a.vndkApex { |
| 913 | overrideName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(vndkApexName) |
| 914 | if overridden { |
| 915 | return strings.Replace(*a.properties.Apex_name, vndkApexName, overrideName, 1) |
| 916 | } |
| 917 | return "" |
| 918 | } |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 919 | if a.overridableProperties.Package_name != "" { |
| 920 | return a.overridableProperties.Package_name |
| 921 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 922 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 923 | if overridden { |
| 924 | return manifestPackageName |
| 925 | } |
| 926 | return "" |
| 927 | } |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 928 | |
| 929 | func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) { |
| 930 | if !a.primaryApexType { |
| 931 | return |
| 932 | } |
| 933 | |
| 934 | if a.properties.IsCoverageVariant { |
| 935 | // Otherwise, we will have duplicated rules for coverage and |
| 936 | // non-coverage variants of the same APEX |
| 937 | return |
| 938 | } |
| 939 | |
| 940 | if ctx.Host() { |
| 941 | // No need to generate dependency info for host variant |
| 942 | return |
| 943 | } |
| 944 | |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 945 | depInfos := android.DepNameToDepInfoMap{} |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 946 | 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] | 947 | if from.Name() == to.Name() { |
| 948 | // This can happen for cc.reuseObjTag. We are not interested in tracking this. |
| 949 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 950 | return !externalDep |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 951 | } |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 952 | |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 953 | // Skip dependencies that are only available to APEXes; they are developed with updatability |
| 954 | // in mind and don't need manual approval. |
| 955 | if to.(android.ApexModule).NotAvailableForPlatform() { |
| 956 | return !externalDep |
| 957 | } |
| 958 | |
Cindy Zhou | 18417cb | 2020-12-10 07:12:38 -0800 | [diff] [blame] | 959 | depTag := ctx.OtherModuleDependencyTag(to) |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 960 | // Check to see if dependency been marked to skip the dependency check |
Cindy Zhou | 18417cb | 2020-12-10 07:12:38 -0800 | [diff] [blame] | 961 | if skipDepCheck, ok := depTag.(android.SkipApexAllowedDependenciesCheck); ok && skipDepCheck.SkipApexAllowedDependenciesCheck() { |
Cindy Zhou | 18417cb | 2020-12-10 07:12:38 -0800 | [diff] [blame] | 962 | return !externalDep |
| 963 | } |
| 964 | |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 965 | if info, exists := depInfos[to.Name()]; exists { |
| 966 | if !android.InList(from.Name(), info.From) { |
| 967 | info.From = append(info.From, from.Name()) |
| 968 | } |
| 969 | info.IsExternal = info.IsExternal && externalDep |
| 970 | depInfos[to.Name()] = info |
| 971 | } else { |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 972 | toMinSdkVersion := "(no version)" |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 973 | if m, ok := to.(interface { |
| 974 | MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec |
| 975 | }); ok { |
| 976 | if v := m.MinSdkVersion(ctx); !v.ApiLevel.IsNone() { |
| 977 | toMinSdkVersion = v.ApiLevel.String() |
| 978 | } |
| 979 | } else if m, ok := to.(interface{ MinSdkVersion() string }); ok { |
| 980 | // TODO(b/175678607) eliminate the use of MinSdkVersion returning |
| 981 | // string |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 982 | if v := m.MinSdkVersion(); v != "" { |
| 983 | toMinSdkVersion = v |
| 984 | } |
| 985 | } |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 986 | depInfos[to.Name()] = android.ApexModuleDepInfo{ |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 987 | To: to.Name(), |
| 988 | From: []string{from.Name()}, |
| 989 | IsExternal: externalDep, |
| 990 | MinSdkVersion: toMinSdkVersion, |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | |
| 994 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 995 | return !externalDep |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 996 | }) |
| 997 | |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 998 | a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, proptools.String(a.properties.Min_sdk_version), depInfos) |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 999 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1000 | ctx.Build(pctx, android.BuildParams{ |
| 1001 | Rule: android.Phony, |
| 1002 | Output: android.PathForPhony(ctx, a.Name()+"-deps-info"), |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1003 | Inputs: []android.Path{ |
| 1004 | a.ApexBundleDepsInfo.FullListPath(), |
| 1005 | a.ApexBundleDepsInfo.FlatListPath(), |
| 1006 | }, |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1007 | }) |
| 1008 | } |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 1009 | |
| 1010 | func (a *apexBundle) buildLintReports(ctx android.ModuleContext) { |
| 1011 | depSetsBuilder := java.NewLintDepSetBuilder() |
| 1012 | for _, fi := range a.filesInfo { |
| 1013 | depSetsBuilder.Transitive(fi.lintDepSets) |
| 1014 | } |
| 1015 | |
| 1016 | a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build()) |
| 1017 | } |
Jiyong Park | 1b0893e | 2021-12-13 23:40:17 +0900 | [diff] [blame^] | 1018 | |
| 1019 | func (a *apexBundle) buildCannedFsConfig(ctx android.ModuleContext) android.OutputPath { |
| 1020 | var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"} |
| 1021 | var executablePaths []string // this also includes dirs |
| 1022 | var appSetDirs []string |
| 1023 | appSetFiles := make(map[string]android.Path) |
| 1024 | for _, f := range a.filesInfo { |
| 1025 | pathInApex := f.path() |
| 1026 | if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") { |
| 1027 | executablePaths = append(executablePaths, pathInApex) |
| 1028 | for _, d := range f.dataPaths { |
| 1029 | readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel())) |
| 1030 | } |
| 1031 | for _, s := range f.symlinks { |
| 1032 | executablePaths = append(executablePaths, filepath.Join(f.installDir, s)) |
| 1033 | } |
| 1034 | } else if f.class == appSet { |
| 1035 | appSetDirs = append(appSetDirs, f.installDir) |
| 1036 | appSetFiles[f.installDir] = f.builtFile |
| 1037 | } else { |
| 1038 | readOnlyPaths = append(readOnlyPaths, pathInApex) |
| 1039 | } |
| 1040 | dir := f.installDir |
| 1041 | for !android.InList(dir, executablePaths) && dir != "" { |
| 1042 | executablePaths = append(executablePaths, dir) |
| 1043 | dir, _ = filepath.Split(dir) // move up to the parent |
| 1044 | if len(dir) > 0 { |
| 1045 | // remove trailing slash |
| 1046 | dir = dir[:len(dir)-1] |
| 1047 | } |
| 1048 | } |
| 1049 | } |
| 1050 | sort.Strings(readOnlyPaths) |
| 1051 | sort.Strings(executablePaths) |
| 1052 | sort.Strings(appSetDirs) |
| 1053 | |
| 1054 | cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config") |
| 1055 | builder := android.NewRuleBuilder(pctx, ctx) |
| 1056 | cmd := builder.Command() |
| 1057 | cmd.Text("(") |
| 1058 | cmd.Text("echo '/ 1000 1000 0755';") |
| 1059 | for _, p := range readOnlyPaths { |
| 1060 | cmd.Textf("echo '/%s 1000 1000 0644';", p) |
| 1061 | } |
| 1062 | for _, p := range executablePaths { |
| 1063 | cmd.Textf("echo '/%s 0 2000 0755';", p) |
| 1064 | } |
| 1065 | for _, dir := range appSetDirs { |
| 1066 | cmd.Textf("echo '/%s 0 2000 0755';", dir) |
| 1067 | file := appSetFiles[dir] |
| 1068 | cmd.Text("zipinfo -1").Input(file).Textf(`| sed "s:\(.*\):/%s/\1 1000 1000 0644:";`, dir) |
| 1069 | } |
| 1070 | cmd.Text(")").FlagWithOutput("> ", cannedFsConfig) |
| 1071 | builder.Build("generateFsConfig", fmt.Sprintf("Generating canned fs config for %s", a.BaseModuleName())) |
| 1072 | |
| 1073 | return cannedFsConfig.OutputPath |
| 1074 | } |