Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1 | // Copyright (C) 2018 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 ( |
| 18 | "fmt" |
| 19 | "io" |
| 20 | "path/filepath" |
| 21 | "runtime" |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 22 | "sort" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 23 | "strings" |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 24 | "sync" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 25 | |
| 26 | "android/soong/android" |
| 27 | "android/soong/cc" |
| 28 | "android/soong/java" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 29 | "android/soong/python" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 30 | |
| 31 | "github.com/google/blueprint" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 32 | "github.com/google/blueprint/bootstrap" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 33 | "github.com/google/blueprint/proptools" |
| 34 | ) |
| 35 | |
| 36 | var ( |
| 37 | pctx = android.NewPackageContext("android/apex") |
| 38 | |
| 39 | // Create a canned fs config file where all files and directories are |
| 40 | // by default set to (uid/gid/mode) = (1000/1000/0644) |
| 41 | // TODO(b/113082813) make this configurable using config.fs syntax |
| 42 | generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{ |
Roland Levillain | 2b11f74 | 2018-11-02 11:50:42 +0000 | [diff] [blame] | 43 | Command: `echo '/ 1000 1000 0755' > ${out} && ` + |
Jiyong Park | 92905d6 | 2018-10-11 13:23:09 +0900 | [diff] [blame] | 44 | `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` + |
Jiyong Park | 805cbc3 | 2019-01-08 14:04:17 +0900 | [diff] [blame] | 45 | `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 46 | Description: "fs_config ${out}", |
Jiyong Park | 92905d6 | 2018-10-11 13:23:09 +0900 | [diff] [blame] | 47 | }, "ro_paths", "exec_paths") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 48 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 49 | apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{ |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 50 | Command: `rm -f $out && ${jsonmodify} $in ` + |
| 51 | `-a provideNativeLibs ${provideNativeLibs} ` + |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 52 | `-a requireNativeLibs ${requireNativeLibs} ` + |
| 53 | `${opt} ` + |
| 54 | `-o $out`, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 55 | CommandDeps: []string{"${jsonmodify}"}, |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 56 | Description: "prepare ${out}", |
| 57 | }, "provideNativeLibs", "requireNativeLibs", "opt") |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 58 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 59 | stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{ |
| 60 | Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`, |
| 61 | CommandDeps: []string{"${conv_apex_manifest}"}, |
| 62 | Description: "strip ${in}=>${out}", |
| 63 | }) |
| 64 | |
| 65 | pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{ |
| 66 | Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`, |
| 67 | CommandDeps: []string{"${conv_apex_manifest}"}, |
| 68 | Description: "convert ${in}=>${out}", |
| 69 | }) |
| 70 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 71 | // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate |
| 72 | // against the binary policy using sefcontext_compiler -p <policy>. |
| 73 | |
| 74 | // TODO(b/114327326): automate the generation of file_contexts |
| 75 | apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{ |
| 76 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
Roland Levillain | 96cf4d4 | 2019-07-30 19:56:56 +0100 | [diff] [blame] | 77 | `(. ${out}.copy_commands) && ` + |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 78 | `APEXER_TOOL_PATH=${tool_path} ` + |
Jiyong Park | 2556015 | 2018-11-20 09:57:52 +0900 | [diff] [blame] | 79 | `${apexer} --force --manifest ${manifest} ` + |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 80 | `--manifest_json ${manifest_json} --manifest_json_full ${manifest_json_full} ` + |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 81 | `--file_contexts ${file_contexts} ` + |
| 82 | `--canned_fs_config ${canned_fs_config} ` + |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 83 | `--payload_type image ` + |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 84 | `--key ${key} ${opt_flags} ${image_dir} ${out} `, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 85 | CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}", |
| 86 | "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", |
Dan Willemsen | dd651fa | 2019-06-13 04:48:54 +0000 | [diff] [blame] | 87 | "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"}, |
Roland Levillain | 96cf4d4 | 2019-07-30 19:56:56 +0100 | [diff] [blame] | 88 | Rspfile: "${out}.copy_commands", |
| 89 | RspfileContent: "${copy_commands}", |
| 90 | Description: "APEX ${image_dir} => ${out}", |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 91 | }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", |
| 92 | "manifest", "manifest_json", "manifest_json_full", |
| 93 | ) |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 94 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 95 | zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ |
| 96 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
Roland Levillain | 96cf4d4 | 2019-07-30 19:56:56 +0100 | [diff] [blame] | 97 | `(. ${out}.copy_commands) && ` + |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 98 | `APEXER_TOOL_PATH=${tool_path} ` + |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 99 | `${apexer} --force --manifest ${manifest} --manifest_json_full ${manifest_json_full} ` + |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 100 | `--payload_type zip ` + |
| 101 | `${image_dir} ${out} `, |
Roland Levillain | 96cf4d4 | 2019-07-30 19:56:56 +0100 | [diff] [blame] | 102 | CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"}, |
| 103 | Rspfile: "${out}.copy_commands", |
| 104 | RspfileContent: "${copy_commands}", |
| 105 | Description: "ZipAPEX ${image_dir} => ${out}", |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 106 | }, "tool_path", "image_dir", "copy_commands", "manifest", "manifest_json_full") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 107 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 108 | apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule", |
| 109 | blueprint.RuleParams{ |
| 110 | Command: `${aapt2} convert --output-format proto $in -o $out`, |
| 111 | CommandDeps: []string{"${aapt2}"}, |
| 112 | }) |
| 113 | |
| 114 | apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{ |
Jiyong Park | 1ed0fc5 | 2018-11-23 13:22:21 +0900 | [diff] [blame] | 115 | Command: `${zip2zip} -i $in -o $out ` + |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 116 | `apex_payload.img:apex/${abi}.img ` + |
| 117 | `apex_manifest.json:root/apex_manifest.json ` + |
Jaewoong Jung | b00c1fb | 2019-09-04 13:26:18 -0700 | [diff] [blame] | 118 | `AndroidManifest.xml:manifest/AndroidManifest.xml ` + |
| 119 | `assets/NOTICE.html.gz:assets/NOTICE.html.gz`, |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 120 | CommandDeps: []string{"${zip2zip}"}, |
| 121 | Description: "app bundle", |
| 122 | }, "abi") |
Nikita Ioffe | 5d5ae76 | 2019-08-31 14:38:05 +0100 | [diff] [blame] | 123 | |
| 124 | emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{ |
| 125 | Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`, |
| 126 | Rspfile: "${out}.emit_commands", |
| 127 | RspfileContent: "${emit_commands}", |
| 128 | Description: "Emit APEX image content", |
| 129 | }, "emit_commands") |
| 130 | |
| 131 | diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{ |
| 132 | Command: `diff --unchanged-group-format='' \` + |
| 133 | `--changed-group-format='%<' \` + |
| 134 | `${image_content_file} ${whitelisted_files_file} || (` + |
| 135 | `echo -e "New unexpected files were added to ${apex_module_name}." ` + |
| 136 | ` "To fix the build run following command:" && ` + |
| 137 | `echo "system/apex/tools/update_whitelist.sh ${whitelisted_files_file} ${image_content_file}" && ` + |
| 138 | `exit 1)`, |
| 139 | Description: "Diff ${image_content_file} and ${whitelisted_files_file}", |
| 140 | }, "image_content_file", "whitelisted_files_file", "apex_module_name") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 141 | ) |
| 142 | |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 143 | const ( |
| 144 | imageApexSuffix = ".apex" |
| 145 | zipApexSuffix = ".zipapex" |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 146 | flattenedSuffix = ".flattened" |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 147 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 148 | imageApexType = "image" |
| 149 | zipApexType = "zip" |
| 150 | flattenedApexType = "flattened" |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 151 | |
| 152 | vndkApexNamePrefix = "com.android.vndk.v" |
| 153 | ) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 154 | |
| 155 | type dependencyTag struct { |
| 156 | blueprint.BaseDependencyTag |
| 157 | name string |
| 158 | } |
| 159 | |
| 160 | var ( |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 161 | sharedLibTag = dependencyTag{name: "sharedLib"} |
| 162 | executableTag = dependencyTag{name: "executable"} |
| 163 | javaLibTag = dependencyTag{name: "javaLib"} |
| 164 | prebuiltTag = dependencyTag{name: "prebuilt"} |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 165 | testTag = dependencyTag{name: "test"} |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 166 | keyTag = dependencyTag{name: "key"} |
| 167 | certificateTag = dependencyTag{name: "certificate"} |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 168 | usesTag = dependencyTag{name: "uses"} |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 169 | androidAppTag = dependencyTag{name: "androidApp"} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 170 | ) |
| 171 | |
| 172 | func init() { |
Colin Cross | cc0ce80 | 2019-04-02 16:14:11 -0700 | [diff] [blame] | 173 | pctx.Import("android/soong/android") |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 174 | pctx.Import("android/soong/java") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 175 | pctx.HostBinToolVariable("apexer", "apexer") |
Roland Levillain | 54bdfda | 2018-10-05 19:34:32 +0100 | [diff] [blame] | 176 | // ART minimal builds (using the master-art manifest) do not have the "frameworks/base" |
| 177 | // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead. |
| 178 | hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) { |
| 179 | pctx.VariableFunc(name, func(ctx android.PackageVarContext) string { |
David Brazdil | 91b4e3e | 2019-01-23 21:04:05 +0000 | [diff] [blame] | 180 | if !ctx.Config().FrameworksBaseDirExists(ctx) { |
Roland Levillain | 54bdfda | 2018-10-05 19:34:32 +0100 | [diff] [blame] | 181 | return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool) |
| 182 | } else { |
| 183 | return pctx.HostBinToolPath(ctx, tool).String() |
| 184 | } |
| 185 | }) |
| 186 | } |
| 187 | hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 188 | pctx.HostBinToolVariable("avbtool", "avbtool") |
| 189 | pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid") |
| 190 | pctx.HostBinToolVariable("merge_zips", "merge_zips") |
| 191 | pctx.HostBinToolVariable("mke2fs", "mke2fs") |
| 192 | pctx.HostBinToolVariable("resize2fs", "resize2fs") |
| 193 | pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile") |
| 194 | pctx.HostBinToolVariable("soong_zip", "soong_zip") |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 195 | pctx.HostBinToolVariable("zip2zip", "zip2zip") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 196 | pctx.HostBinToolVariable("zipalign", "zipalign") |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 197 | pctx.HostBinToolVariable("jsonmodify", "jsonmodify") |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 198 | pctx.HostBinToolVariable("conv_apex_manifest", "conv_apex_manifest") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 199 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 200 | android.RegisterModuleType("apex", BundleFactory) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 201 | android.RegisterModuleType("apex_test", testApexBundleFactory) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 202 | android.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 203 | android.RegisterModuleType("apex_defaults", defaultsFactory) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 204 | android.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 205 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 206 | android.PreDepsMutators(RegisterPreDepsMutators) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 207 | android.PostDepsMutators(RegisterPostDepsMutators) |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 208 | |
| 209 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 210 | apexFileContextsInfos := apexFileContextsInfos(ctx.Config()) |
| 211 | sort.Strings(*apexFileContextsInfos) |
| 212 | ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " ")) |
| 213 | }) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 214 | } |
| 215 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 216 | func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { |
| 217 | ctx.TopDown("apex_vndk", apexVndkMutator).Parallel() |
| 218 | ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel() |
| 219 | } |
| 220 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 221 | func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { |
| 222 | ctx.TopDown("apex_deps", apexDepsMutator) |
| 223 | ctx.BottomUp("apex", apexMutator).Parallel() |
| 224 | ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel() |
| 225 | ctx.BottomUp("apex_uses", apexUsesMutator).Parallel() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 226 | } |
| 227 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 228 | var ( |
| 229 | vndkApexListKey = android.NewOnceKey("vndkApexList") |
| 230 | vndkApexListMutex sync.Mutex |
| 231 | ) |
| 232 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 233 | func vndkApexList(config android.Config) map[string]string { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 234 | return config.Once(vndkApexListKey, func() interface{} { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 235 | return map[string]string{} |
| 236 | }).(map[string]string) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 237 | } |
| 238 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 239 | func apexVndkMutator(mctx android.TopDownMutatorContext) { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 240 | if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex { |
| 241 | if ab.IsNativeBridgeSupported() { |
| 242 | mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType()) |
| 243 | } |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 244 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 245 | vndkVersion := ab.vndkVersion(mctx.DeviceConfig()) |
| 246 | // Ensure VNDK APEX mount point is formatted as com.android.vndk.v### |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 247 | ab.properties.Apex_name = proptools.StringPtr(vndkApexNamePrefix + vndkVersion) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 248 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 249 | // vndk_version should be unique |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 250 | vndkApexListMutex.Lock() |
| 251 | defer vndkApexListMutex.Unlock() |
| 252 | vndkApexList := vndkApexList(mctx.Config()) |
| 253 | if other, ok := vndkApexList[vndkVersion]; ok { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 254 | mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 255 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 256 | vndkApexList[vndkVersion] = mctx.ModuleName() |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 260 | func apexVndkDepsMutator(mctx android.BottomUpMutatorContext) { |
| 261 | if m, ok := mctx.Module().(*cc.Module); ok && cc.IsForVndkApex(mctx, m) { |
| 262 | vndkVersion := m.VndkVersion() |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 263 | vndkApexList := vndkApexList(mctx.Config()) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 264 | if vndkApex, ok := vndkApexList[vndkVersion]; ok { |
| 265 | mctx.AddReverseDependency(mctx.Module(), sharedLibTag, vndkApex) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 266 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 267 | } else if a, ok := mctx.Module().(*apexBundle); ok && a.vndkApex { |
| 268 | vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current") |
| 269 | mctx.AddDependency(mctx.Module(), prebuiltTag, cc.VndkLibrariesTxtModules(vndkVersion)...) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 273 | // Mark the direct and transitive dependencies of apex bundles so that they |
| 274 | // can be built for the apex bundles. |
| 275 | func apexDepsMutator(mctx android.TopDownMutatorContext) { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 276 | if a, ok := mctx.Module().(*apexBundle); ok { |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 277 | apexBundleName := mctx.ModuleName() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 278 | mctx.WalkDeps(func(child, parent android.Module) bool { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 279 | depName := mctx.OtherModuleName(child) |
| 280 | // If the parent is apexBundle, this child is directly depended. |
| 281 | _, directDep := parent.(*apexBundle) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 282 | if a.installable() && !a.testApex { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 283 | // TODO(b/123892969): Workaround for not having any way to annotate test-apexs |
| 284 | // non-installable apex's cannot be installed and so should not prevent libraries from being |
| 285 | // installed to the system. |
| 286 | android.UpdateApexDependency(apexBundleName, depName, directDep) |
| 287 | } |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 288 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 289 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 290 | am.BuildForApex(apexBundleName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 291 | return true |
| 292 | } else { |
| 293 | return false |
| 294 | } |
| 295 | }) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // Create apex variations if a module is included in APEX(s). |
| 300 | func apexMutator(mctx android.BottomUpMutatorContext) { |
| 301 | if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 302 | am.CreateApexVariations(mctx) |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 303 | } else if a, ok := mctx.Module().(*apexBundle); ok { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 304 | // apex bundle itself is mutated so that it and its modules have same |
| 305 | // apex variant. |
| 306 | apexBundleName := mctx.ModuleName() |
| 307 | mctx.CreateVariations(apexBundleName) |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 308 | |
| 309 | // collects APEX list |
| 310 | if mctx.Device() && a.installable() { |
| 311 | addApexFileContextsInfos(mctx, a) |
| 312 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 313 | } |
| 314 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 315 | |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 316 | var ( |
| 317 | apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey") |
| 318 | apexFileContextsInfosMutex sync.Mutex |
| 319 | ) |
| 320 | |
| 321 | func apexFileContextsInfos(config android.Config) *[]string { |
| 322 | return config.Once(apexFileContextsInfosKey, func() interface{} { |
| 323 | return &[]string{} |
| 324 | }).(*[]string) |
| 325 | } |
| 326 | |
| 327 | func addApexFileContextsInfos(ctx android.BaseModuleContext, a *apexBundle) { |
| 328 | apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName()) |
| 329 | fileContextsName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName()) |
| 330 | |
| 331 | apexFileContextsInfosMutex.Lock() |
| 332 | defer apexFileContextsInfosMutex.Unlock() |
| 333 | apexFileContextsInfos := apexFileContextsInfos(ctx.Config()) |
| 334 | *apexFileContextsInfos = append(*apexFileContextsInfos, apexName+":"+fileContextsName) |
| 335 | } |
| 336 | |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 337 | func apexFlattenedMutator(mctx android.BottomUpMutatorContext) { |
Sundong Ahn | e8fb724 | 2019-09-17 13:50:45 +0900 | [diff] [blame] | 338 | if ab, ok := mctx.Module().(*apexBundle); ok { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 339 | var variants []string |
| 340 | switch proptools.StringDefault(ab.properties.Payload_type, "image") { |
| 341 | case "image": |
| 342 | variants = append(variants, imageApexType, flattenedApexType) |
| 343 | case "zip": |
| 344 | variants = append(variants, zipApexType) |
| 345 | case "both": |
| 346 | variants = append(variants, imageApexType, zipApexType, flattenedApexType) |
| 347 | default: |
Sundong Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame^] | 348 | mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 349 | return |
| 350 | } |
| 351 | |
| 352 | modules := mctx.CreateLocalVariations(variants...) |
| 353 | |
| 354 | for i, v := range variants { |
| 355 | switch v { |
| 356 | case imageApexType: |
| 357 | modules[i].(*apexBundle).properties.ApexType = imageApex |
| 358 | case zipApexType: |
| 359 | modules[i].(*apexBundle).properties.ApexType = zipApex |
| 360 | case flattenedApexType: |
| 361 | modules[i].(*apexBundle).properties.ApexType = flattenedApex |
Sundong Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame^] | 362 | if !mctx.Config().FlattenApex() { |
| 363 | modules[i].(*apexBundle).MakeAsSystemExt() |
| 364 | } |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 365 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 370 | func apexUsesMutator(mctx android.BottomUpMutatorContext) { |
| 371 | if ab, ok := mctx.Module().(*apexBundle); ok { |
| 372 | mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...) |
| 373 | } |
| 374 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 375 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 376 | var ( |
| 377 | useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist") |
| 378 | ) |
| 379 | |
| 380 | // useVendorWhitelist returns the list of APEXes which are allowed to use_vendor. |
| 381 | // When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__, |
| 382 | // which may cause compatibility issues. (e.g. libbinder) |
| 383 | // Even though libbinder restricts its availability via 'apex_available' property and relies on |
| 384 | // yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules |
| 385 | // to avoid similar problems. |
| 386 | func useVendorWhitelist(config android.Config) []string { |
| 387 | return config.Once(useVendorWhitelistKey, func() interface{} { |
| 388 | return []string{ |
| 389 | // swcodec uses "vendor" variants for smaller size |
| 390 | "com.android.media.swcodec", |
| 391 | "test_com.android.media.swcodec", |
| 392 | } |
| 393 | }).([]string) |
| 394 | } |
| 395 | |
| 396 | // setUseVendorWhitelistForTest overrides useVendorWhitelist and must be |
| 397 | // called before the first call to useVendorWhitelist() |
| 398 | func setUseVendorWhitelistForTest(config android.Config, whitelist []string) { |
| 399 | config.Once(useVendorWhitelistKey, func() interface{} { |
| 400 | return whitelist |
| 401 | }) |
| 402 | } |
| 403 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 404 | type apexNativeDependencies struct { |
| 405 | // List of native libraries |
| 406 | Native_shared_libs []string |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 407 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 408 | // List of native executables |
| 409 | Binaries []string |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 410 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 411 | // List of native tests |
| 412 | Tests []string |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 413 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 414 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 415 | type apexMultilibProperties struct { |
| 416 | // Native dependencies whose compile_multilib is "first" |
| 417 | First apexNativeDependencies |
| 418 | |
| 419 | // Native dependencies whose compile_multilib is "both" |
| 420 | Both apexNativeDependencies |
| 421 | |
| 422 | // Native dependencies whose compile_multilib is "prefer32" |
| 423 | Prefer32 apexNativeDependencies |
| 424 | |
| 425 | // Native dependencies whose compile_multilib is "32" |
| 426 | Lib32 apexNativeDependencies |
| 427 | |
| 428 | // Native dependencies whose compile_multilib is "64" |
| 429 | Lib64 apexNativeDependencies |
| 430 | } |
| 431 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 432 | type apexBundleProperties struct { |
| 433 | // Json manifest file describing meta info of this APEX bundle. Default: |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 434 | // "apex_manifest.json" |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 435 | Manifest *string `android:"path"` |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 436 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 437 | // AndroidManifest.xml file used for the zip container of this APEX bundle. |
| 438 | // If unspecified, a default one is automatically generated. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 439 | AndroidManifest *string `android:"path"` |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 440 | |
Roland Levillain | 411c584 | 2019-09-19 16:37:20 +0100 | [diff] [blame] | 441 | // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on |
| 442 | // device (/apex/<apex_name>). |
| 443 | // If unspecified, defaults to the value of name. |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 444 | Apex_name *string |
| 445 | |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 446 | // Determines the file contexts file for setting security context to each file in this APEX bundle. |
| 447 | // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is |
| 448 | // used. |
| 449 | // Default: <name_of_this_module> |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 450 | File_contexts *string |
| 451 | |
| 452 | // List of native shared libs that are embedded inside this APEX bundle |
| 453 | Native_shared_libs []string |
| 454 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 455 | // List of executables that are embedded inside this APEX bundle |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 456 | Binaries []string |
| 457 | |
| 458 | // List of java libraries that are embedded inside this APEX bundle |
| 459 | Java_libs []string |
| 460 | |
| 461 | // List of prebuilt files that are embedded inside this APEX bundle |
| 462 | Prebuilts []string |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 463 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 464 | // List of tests that are embedded inside this APEX bundle |
| 465 | Tests []string |
| 466 | |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 467 | // Name of the apex_key module that provides the private key to sign APEX |
| 468 | Key *string |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 469 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 470 | // The type of APEX to build. Controls what the APEX payload is. Either |
| 471 | // 'image', 'zip' or 'both'. Default: 'image'. |
| 472 | Payload_type *string |
| 473 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 474 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 475 | // or an android_app_certificate module name in the form ":module". |
| 476 | Certificate *string |
| 477 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 478 | // Whether this APEX is installable to one of the partitions. Default: true. |
| 479 | Installable *bool |
| 480 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 481 | // For native libraries and binaries, use the vendor variant instead of the core (platform) variant. |
| 482 | // Default is false. |
| 483 | Use_vendor *bool |
| 484 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 485 | // For telling the apex to ignore special handling for system libraries such as bionic. Default is false. |
| 486 | Ignore_system_library_special_case *bool |
| 487 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 488 | Multilib apexMultilibProperties |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 489 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 490 | // List of sanitizer names that this APEX is enabled for |
| 491 | SanitizerNames []string `blueprint:"mutated"` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 492 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 493 | PreventInstall bool `blueprint:"mutated"` |
| 494 | |
| 495 | HideFromMake bool `blueprint:"mutated"` |
| 496 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 497 | // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false. |
| 498 | Provide_cpp_shared_libs *bool |
| 499 | |
| 500 | // List of providing APEXes' names so that this APEX can depend on provided shared libraries. |
| 501 | Uses []string |
Nikita Ioffe | 5d5ae76 | 2019-08-31 14:38:05 +0100 | [diff] [blame] | 502 | |
| 503 | // A txt file containing list of files that are whitelisted to be included in this APEX. |
| 504 | Whitelisted_files *string |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 505 | |
| 506 | // List of APKs to package inside APEX |
| 507 | Apps []string |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 508 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 509 | // package format of this apex variant; could be non-flattened, flattened, or zip. |
| 510 | // imageApex, zipApex or flattened |
| 511 | ApexType apexPackaging `blueprint:"mutated"` |
Sundong Ahn | e8fb724 | 2019-09-17 13:50:45 +0900 | [diff] [blame] | 512 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 513 | // List of SDKs that are used to build this APEX. A reference to an SDK should be either |
| 514 | // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current` |
| 515 | // is implied. This value affects all modules included in this APEX. In other words, they are |
| 516 | // also built with the SDKs specified here. |
| 517 | Uses_sdks []string |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | type apexTargetBundleProperties struct { |
| 521 | Target struct { |
| 522 | // Multilib properties only for android. |
| 523 | Android struct { |
| 524 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 525 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 526 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 527 | // Multilib properties only for host. |
| 528 | Host struct { |
| 529 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 530 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 531 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 532 | // Multilib properties only for host linux_bionic. |
| 533 | Linux_bionic struct { |
| 534 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 535 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 536 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 537 | // Multilib properties only for host linux_glibc. |
| 538 | Linux_glibc struct { |
| 539 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 540 | } |
| 541 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 542 | } |
| 543 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 544 | type apexVndkProperties struct { |
| 545 | // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version. |
| 546 | Vndk_version *string |
| 547 | } |
| 548 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 549 | type apexFileClass int |
| 550 | |
| 551 | const ( |
| 552 | etc apexFileClass = iota |
| 553 | nativeSharedLib |
| 554 | nativeExecutable |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 555 | shBinary |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 556 | pyBinary |
| 557 | goBinary |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 558 | javaSharedLib |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 559 | nativeTest |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 560 | app |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 561 | ) |
| 562 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 563 | type apexPackaging int |
| 564 | |
| 565 | const ( |
| 566 | imageApex apexPackaging = iota |
| 567 | zipApex |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 568 | flattenedApex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 569 | ) |
| 570 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 571 | // The suffix for the output "file", not the module |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 572 | func (a apexPackaging) suffix() string { |
| 573 | switch a { |
| 574 | case imageApex: |
| 575 | return imageApexSuffix |
| 576 | case zipApex: |
| 577 | return zipApexSuffix |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 578 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 579 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
| 583 | func (a apexPackaging) name() string { |
| 584 | switch a { |
| 585 | case imageApex: |
| 586 | return imageApexType |
| 587 | case zipApex: |
| 588 | return zipApexType |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 589 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 590 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 594 | func (class apexFileClass) NameInMake() string { |
| 595 | switch class { |
| 596 | case etc: |
| 597 | return "ETC" |
| 598 | case nativeSharedLib: |
| 599 | return "SHARED_LIBRARIES" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 600 | case nativeExecutable, shBinary, pyBinary, goBinary: |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 601 | return "EXECUTABLES" |
| 602 | case javaSharedLib: |
| 603 | return "JAVA_LIBRARIES" |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 604 | case nativeTest: |
| 605 | return "NATIVE_TESTS" |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 606 | case app: |
Jiyong Park | f383f7c | 2019-10-11 20:46:25 +0900 | [diff] [blame] | 607 | // b/142537672 Why isn't this APP? We want to have full control over |
| 608 | // the paths and file names of the apk file under the flattend APEX. |
| 609 | // If this is set to APP, then the paths and file names are modified |
| 610 | // by the Make build system. For example, it is installed to |
| 611 | // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of |
| 612 | // /system/apex/<apexname>/app/<Appname> because the build system automatically |
| 613 | // appends module name (which is <apexname>.<Appname> to the path. |
| 614 | return "ETC" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 615 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 616 | panic(fmt.Errorf("unknown class %d", class)) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
| 620 | type apexFile struct { |
| 621 | builtFile android.Path |
| 622 | moduleName string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 623 | installDir string |
| 624 | class apexFileClass |
Jiyong Park | a889484 | 2018-12-19 17:36:39 +0900 | [diff] [blame] | 625 | module android.Module |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 626 | symlinks []string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 627 | } |
| 628 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 629 | type apexBundle struct { |
| 630 | android.ModuleBase |
| 631 | android.DefaultableModuleBase |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 632 | android.SdkBase |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 633 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 634 | properties apexBundleProperties |
| 635 | targetProperties apexTargetBundleProperties |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 636 | vndkProperties apexVndkProperties |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 637 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 638 | bundleModuleFile android.WritablePath |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 639 | outputFile android.WritablePath |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 640 | installDir android.InstallPath |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 641 | |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 642 | prebuiltFileToDelete string |
| 643 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 644 | public_key_file android.Path |
| 645 | private_key_file android.Path |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 646 | |
| 647 | container_certificate_file android.Path |
| 648 | container_private_key_file android.Path |
| 649 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 650 | // list of files to be included in this apex |
| 651 | filesInfo []apexFile |
| 652 | |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 653 | // list of module names that this APEX is depending on |
| 654 | externalDeps []string |
| 655 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 656 | testApex bool |
| 657 | vndkApex bool |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 658 | artApex bool |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 659 | primaryApexType bool |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 660 | |
| 661 | // intermediate path for apex_manifest.json |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 662 | manifestJsonOut android.WritablePath |
| 663 | manifestJsonFullOut android.WritablePath |
| 664 | manifestPbOut android.WritablePath |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 665 | |
| 666 | // list of commands to create symlinks for backward compatibility |
| 667 | // these commands will be attached as LOCAL_POST_INSTALL_CMD to |
| 668 | // apex package itself(for unflattened build) or apex_manifest.json(for flattened build) |
| 669 | // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting. |
| 670 | compatSymlinks []string |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 671 | |
| 672 | // Suffix of module name in Android.mk |
| 673 | // ".flattened", ".apex", ".zipapex", or "" |
| 674 | suffix string |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 675 | } |
| 676 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 677 | func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 678 | native_shared_libs []string, binaries []string, tests []string, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 679 | target android.Target, imageVariation string) { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 680 | // Use *FarVariation* to be able to depend on modules having |
| 681 | // conflicting variations with this module. This is required since |
| 682 | // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64' |
| 683 | // for native shared libs. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 684 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 685 | {Mutator: "image", Variation: imageVariation}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 686 | {Mutator: "link", Variation: "shared"}, |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 687 | {Mutator: "version", Variation: ""}, // "" is the non-stub variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 688 | }...), sharedLibTag, native_shared_libs...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 689 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 690 | ctx.AddFarVariationDependencies(append(target.Variations(), |
| 691 | blueprint.Variation{Mutator: "image", Variation: imageVariation}), |
| 692 | executableTag, binaries...) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 693 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 694 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 695 | {Mutator: "image", Variation: imageVariation}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 696 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 697 | }...), testTag, tests...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 698 | } |
| 699 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 700 | func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { |
| 701 | if ctx.Os().Class == android.Device { |
| 702 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil) |
| 703 | } else { |
| 704 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil) |
| 705 | if ctx.Os().Bionic() { |
| 706 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil) |
| 707 | } else { |
| 708 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil) |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 713 | func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 714 | if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) { |
| 715 | ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true") |
| 716 | } |
| 717 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 718 | targets := ctx.MultiTargets() |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 719 | config := ctx.DeviceConfig() |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 720 | |
| 721 | a.combineProperties(ctx) |
| 722 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 723 | has32BitTarget := false |
| 724 | for _, target := range targets { |
| 725 | if target.Arch.ArchType.Multilib == "lib32" { |
| 726 | has32BitTarget = true |
| 727 | } |
| 728 | } |
| 729 | for i, target := range targets { |
| 730 | // When multilib.* is omitted for native_shared_libs, it implies |
| 731 | // multilib.both. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 732 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 733 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 734 | {Mutator: "link", Variation: "shared"}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 735 | }...), sharedLibTag, a.properties.Native_shared_libs...) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 736 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 737 | // When multilib.* is omitted for tests, it implies |
| 738 | // multilib.both. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 739 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 740 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 741 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 742 | }...), testTag, a.properties.Tests...) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 743 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 744 | // Add native modules targetting both ABIs |
| 745 | addDependenciesForNativeModules(ctx, |
| 746 | a.properties.Multilib.Both.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 747 | a.properties.Multilib.Both.Binaries, |
| 748 | a.properties.Multilib.Both.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 749 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 750 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 751 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 752 | isPrimaryAbi := i == 0 |
| 753 | if isPrimaryAbi { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 754 | // When multilib.* is omitted for binaries, it implies |
| 755 | // multilib.first. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 756 | ctx.AddFarVariationDependencies(append(target.Variations(), |
| 757 | blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}), |
| 758 | executableTag, a.properties.Binaries...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 759 | |
| 760 | // Add native modules targetting the first ABI |
| 761 | addDependenciesForNativeModules(ctx, |
| 762 | a.properties.Multilib.First.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 763 | a.properties.Multilib.First.Binaries, |
| 764 | a.properties.Multilib.First.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 765 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 766 | a.getImageVariation(config)) |
Jaewoong Jung | b9a1151 | 2019-01-15 10:47:05 -0800 | [diff] [blame] | 767 | |
| 768 | // When multilib.* is omitted for prebuilts, it implies multilib.first. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 769 | ctx.AddFarVariationDependencies(target.Variations(), |
| 770 | prebuiltTag, a.properties.Prebuilts...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | switch target.Arch.ArchType.Multilib { |
| 774 | case "lib32": |
| 775 | // Add native modules targetting 32-bit ABI |
| 776 | addDependenciesForNativeModules(ctx, |
| 777 | a.properties.Multilib.Lib32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 778 | a.properties.Multilib.Lib32.Binaries, |
| 779 | a.properties.Multilib.Lib32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 780 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 781 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 782 | |
| 783 | addDependenciesForNativeModules(ctx, |
| 784 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 785 | a.properties.Multilib.Prefer32.Binaries, |
| 786 | a.properties.Multilib.Prefer32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 787 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 788 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 789 | case "lib64": |
| 790 | // Add native modules targetting 64-bit ABI |
| 791 | addDependenciesForNativeModules(ctx, |
| 792 | a.properties.Multilib.Lib64.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 793 | a.properties.Multilib.Lib64.Binaries, |
| 794 | a.properties.Multilib.Lib64.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 795 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 796 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 797 | |
| 798 | if !has32BitTarget { |
| 799 | addDependenciesForNativeModules(ctx, |
| 800 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 801 | a.properties.Multilib.Prefer32.Binaries, |
| 802 | a.properties.Multilib.Prefer32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 803 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 804 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 805 | } |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 806 | |
| 807 | if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device { |
| 808 | for _, sanitizer := range ctx.Config().SanitizeDevice() { |
| 809 | if sanitizer == "hwaddress" { |
| 810 | addDependenciesForNativeModules(ctx, |
| 811 | []string{"libclang_rt.hwasan-aarch64-android"}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 812 | nil, nil, target, a.getImageVariation(config)) |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 813 | break |
| 814 | } |
| 815 | } |
| 816 | } |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 817 | } |
| 818 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 819 | } |
| 820 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 821 | ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), |
| 822 | javaLibTag, a.properties.Java_libs...) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 823 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 824 | ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), |
| 825 | androidAppTag, a.properties.Apps...) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 826 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 827 | if String(a.properties.Key) == "" { |
| 828 | ctx.ModuleErrorf("key is missing") |
| 829 | return |
| 830 | } |
| 831 | ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key)) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 832 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 833 | cert := android.SrcIsModule(a.getCertString(ctx)) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 834 | if cert != "" { |
| 835 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 836 | } |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 837 | |
| 838 | // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks |
| 839 | if len(a.properties.Uses_sdks) > 0 { |
| 840 | sdkRefs := []android.SdkRef{} |
| 841 | for _, str := range a.properties.Uses_sdks { |
| 842 | parsed := android.ParseSdkRef(ctx, str, "uses_sdks") |
| 843 | sdkRefs = append(sdkRefs, parsed) |
| 844 | } |
| 845 | a.BuildWithSdks(sdkRefs) |
| 846 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 847 | } |
| 848 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 849 | func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 850 | // direct deps of an APEX bundle are all part of the APEX bundle |
| 851 | return true |
| 852 | } |
| 853 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 854 | func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 855 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName()) |
| 856 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 857 | return ":" + certificate |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 858 | } |
| 859 | return String(a.properties.Certificate) |
| 860 | } |
| 861 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 862 | func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) { |
| 863 | switch tag { |
| 864 | case "": |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 865 | return android.Paths{a.outputFile}, nil |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 866 | default: |
| 867 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Jiyong Park | 5a83202 | 2018-12-20 09:54:35 +0900 | [diff] [blame] | 868 | } |
Jiyong Park | 74e240b | 2018-11-27 21:27:08 +0900 | [diff] [blame] | 869 | } |
| 870 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 871 | func (a *apexBundle) installable() bool { |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 872 | return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable)) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 873 | } |
| 874 | |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 875 | func (a *apexBundle) getImageVariation(config android.DeviceConfig) string { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 876 | if a.vndkApex { |
| 877 | return "vendor." + a.vndkVersion(config) |
| 878 | } |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 879 | if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) { |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 880 | return "vendor." + config.PlatformVndkVersion() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 881 | } else { |
| 882 | return "core" |
| 883 | } |
| 884 | } |
| 885 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 886 | func (a *apexBundle) EnableSanitizer(sanitizerName string) { |
| 887 | if !android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 888 | a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName) |
| 889 | } |
| 890 | } |
| 891 | |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 892 | func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool { |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 893 | if android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 894 | return true |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | // Then follow the global setting |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 898 | globalSanitizerNames := []string{} |
| 899 | if a.Host() { |
| 900 | globalSanitizerNames = ctx.Config().SanitizeHost() |
| 901 | } else { |
| 902 | arches := ctx.Config().SanitizeDeviceArch() |
| 903 | if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) { |
| 904 | globalSanitizerNames = ctx.Config().SanitizeDevice() |
| 905 | } |
| 906 | } |
| 907 | return android.InList(sanitizerName, globalSanitizerNames) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 908 | } |
| 909 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 910 | func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 911 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 912 | } |
| 913 | |
| 914 | func (a *apexBundle) PreventInstall() { |
| 915 | a.properties.PreventInstall = true |
| 916 | } |
| 917 | |
| 918 | func (a *apexBundle) HideFromMake() { |
| 919 | a.properties.HideFromMake = true |
| 920 | } |
| 921 | |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 922 | func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 923 | // Decide the APEX-local directory by the multilib of the library |
| 924 | // In the future, we may query this to the module. |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 925 | switch ccMod.Arch().ArchType.Multilib { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 926 | case "lib32": |
| 927 | dirInApex = "lib" |
| 928 | case "lib64": |
| 929 | dirInApex = "lib64" |
| 930 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 931 | dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath()) |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 932 | if ccMod.Target().NativeBridge == android.NativeBridgeEnabled { |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 933 | dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 934 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 935 | if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) { |
| 936 | // Special case for Bionic libs and other libs installed with them. This is |
| 937 | // to prevent those libs from being included in the search path |
| 938 | // /apex/com.android.runtime/${LIB}. This exclusion is required because |
| 939 | // those libs in the Runtime APEX are available via the legacy paths in |
| 940 | // /system/lib/. By the init process, the libs in the APEX are bind-mounted |
| 941 | // to the legacy paths and thus will be loaded into the default linker |
| 942 | // namespace (aka "platform" namespace). If the libs are directly in |
| 943 | // /apex/com.android.runtime/${LIB} then the same libs will be loaded again |
| 944 | // into the runtime linker namespace, which will result in double loading of |
| 945 | // them, which isn't supported. |
| 946 | dirInApex = filepath.Join(dirInApex, "bionic") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 947 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 948 | |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 949 | fileToCopy = ccMod.OutputFile().Path() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 950 | return |
| 951 | } |
| 952 | |
| 953 | func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 954 | dirInApex = filepath.Join("bin", cc.RelativeInstallPath()) |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 955 | if cc.Target().NativeBridge == android.NativeBridgeEnabled { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 956 | dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath) |
Jiyong Park | acbf6c7 | 2019-07-09 16:19:16 +0900 | [diff] [blame] | 957 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 958 | fileToCopy = cc.OutputFile().Path() |
| 959 | return |
| 960 | } |
| 961 | |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 962 | func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) { |
| 963 | dirInApex = "bin" |
| 964 | fileToCopy = py.HostToolPath().Path() |
| 965 | return |
| 966 | } |
| 967 | func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) { |
| 968 | dirInApex = "bin" |
| 969 | s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath()) |
| 970 | if err != nil { |
| 971 | ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath()) |
| 972 | return |
| 973 | } |
| 974 | fileToCopy = android.PathForOutput(ctx, s) |
| 975 | return |
| 976 | } |
| 977 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 978 | func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) { |
| 979 | dirInApex = filepath.Join("bin", sh.SubDir()) |
| 980 | fileToCopy = sh.OutputFile() |
| 981 | return |
| 982 | } |
| 983 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 984 | func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) { |
| 985 | dirInApex = "javalib" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 986 | fileToCopy = java.DexJarFile() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 987 | return |
| 988 | } |
| 989 | |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 990 | func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) { |
| 991 | dirInApex = "javalib" |
| 992 | // The output is only one, but for some reason, ImplementationJars returns Paths, not Path |
| 993 | implJars := java.ImplementationJars() |
| 994 | if len(implJars) != 1 { |
| 995 | panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s", |
| 996 | strings.Join(implJars.Strings(), ", "))) |
| 997 | } |
| 998 | fileToCopy = implJars[0] |
| 999 | return |
| 1000 | } |
| 1001 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1002 | func getCopyManifestForPrebuiltEtc(prebuilt android.PrebuiltEtcModule) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1003 | dirInApex = filepath.Join("etc", prebuilt.SubDir()) |
| 1004 | fileToCopy = prebuilt.OutputFile() |
| 1005 | return |
| 1006 | } |
| 1007 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 1008 | func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 1009 | appDir := "app" |
| 1010 | if app.Privileged() { |
| 1011 | appDir = "priv-app" |
| 1012 | } |
| 1013 | dirInApex = filepath.Join(appDir, pkgName) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 1014 | fileToCopy = app.OutputFile() |
| 1015 | return |
| 1016 | } |
| 1017 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 1018 | func getCopyManifestForAndroidAppImport(app *java.AndroidAppImport, pkgName string) (fileToCopy android.Path, dirInApex string) { |
| 1019 | appDir := "app" |
| 1020 | if app.Privileged() { |
| 1021 | appDir = "priv-app" |
| 1022 | } |
| 1023 | dirInApex = filepath.Join(appDir, pkgName) |
| 1024 | fileToCopy = app.OutputFile() |
| 1025 | return |
| 1026 | } |
| 1027 | |
Roland Levillain | 935639d | 2019-08-13 14:55:28 +0100 | [diff] [blame] | 1028 | // Context "decorator", overriding the InstallBypassMake method to always reply `true`. |
| 1029 | type flattenedApexContext struct { |
| 1030 | android.ModuleContext |
| 1031 | } |
| 1032 | |
| 1033 | func (c *flattenedApexContext) InstallBypassMake() bool { |
| 1034 | return true |
| 1035 | } |
| 1036 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1037 | func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1038 | filesInfo := []apexFile{} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1039 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1040 | buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild() |
| 1041 | switch a.properties.ApexType { |
| 1042 | case imageApex: |
| 1043 | if buildFlattenedAsDefault { |
| 1044 | a.suffix = imageApexSuffix |
| 1045 | } else { |
| 1046 | a.suffix = "" |
| 1047 | a.primaryApexType = true |
| 1048 | } |
| 1049 | case zipApex: |
| 1050 | if proptools.String(a.properties.Payload_type) == "zip" { |
| 1051 | a.suffix = "" |
| 1052 | a.primaryApexType = true |
| 1053 | } else { |
| 1054 | a.suffix = zipApexSuffix |
| 1055 | } |
| 1056 | case flattenedApex: |
| 1057 | if buildFlattenedAsDefault { |
| 1058 | a.suffix = "" |
| 1059 | a.primaryApexType = true |
| 1060 | } else { |
| 1061 | a.suffix = flattenedSuffix |
| 1062 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1065 | if len(a.properties.Tests) > 0 && !a.testApex { |
| 1066 | ctx.PropertyErrorf("tests", "property not allowed in apex module type") |
| 1067 | return |
| 1068 | } |
| 1069 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 1070 | handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case) |
| 1071 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1072 | // native lib dependencies |
| 1073 | var provideNativeLibs []string |
| 1074 | var requireNativeLibs []string |
| 1075 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1076 | // Check if "uses" requirements are met with dependent apexBundles |
| 1077 | var providedNativeSharedLibs []string |
| 1078 | useVendor := proptools.Bool(a.properties.Use_vendor) |
| 1079 | ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) { |
| 1080 | if ctx.OtherModuleDependencyTag(m) != usesTag { |
| 1081 | return |
| 1082 | } |
| 1083 | otherName := ctx.OtherModuleName(m) |
| 1084 | other, ok := m.(*apexBundle) |
| 1085 | if !ok { |
| 1086 | ctx.PropertyErrorf("uses", "%q is not a provider", otherName) |
| 1087 | return |
| 1088 | } |
| 1089 | if proptools.Bool(other.properties.Use_vendor) != useVendor { |
| 1090 | ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName) |
| 1091 | return |
| 1092 | } |
| 1093 | if !proptools.Bool(other.properties.Provide_cpp_shared_libs) { |
| 1094 | ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName) |
| 1095 | return |
| 1096 | } |
| 1097 | providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...) |
| 1098 | }) |
| 1099 | |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1100 | ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1101 | depTag := ctx.OtherModuleDependencyTag(child) |
| 1102 | depName := ctx.OtherModuleName(child) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1103 | if _, ok := parent.(*apexBundle); ok { |
| 1104 | // direct dependencies |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1105 | switch depTag { |
| 1106 | case sharedLibTag: |
| 1107 | if cc, ok := child.(*cc.Module); ok { |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1108 | if cc.HasStubsVariants() { |
| 1109 | provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base()) |
| 1110 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1111 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1112 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1113 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1114 | } else { |
| 1115 | ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1116 | } |
| 1117 | case executableTag: |
| 1118 | if cc, ok := child.(*cc.Module); ok { |
| 1119 | fileToCopy, dirInApex := getCopyManifestForExecutable(cc) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1120 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1121 | return true |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 1122 | } else if sh, ok := child.(*android.ShBinary); ok { |
| 1123 | fileToCopy, dirInApex := getCopyManifestForShBinary(sh) |
Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 1124 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, sh.Symlinks()}) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1125 | } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() { |
| 1126 | fileToCopy, dirInApex := getCopyManifestForPyBinary(py) |
| 1127 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil}) |
| 1128 | } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() { |
| 1129 | fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb) |
| 1130 | // NB: Since go binaries are static we don't need the module for anything here, which is |
| 1131 | // good since the go tool is a blueprint.Module not an android.Module like we would |
| 1132 | // normally use. |
| 1133 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil}) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1134 | } else { |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1135 | ctx.PropertyErrorf("binaries", "%q is neither cc_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1136 | } |
| 1137 | case javaLibTag: |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1138 | if javaLib, ok := child.(*java.Library); ok { |
| 1139 | fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1140 | if fileToCopy == nil { |
| 1141 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 1142 | } else { |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1143 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil}) |
| 1144 | } |
| 1145 | return true |
| 1146 | } else if javaLib, ok := child.(*java.Import); ok { |
| 1147 | fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib) |
| 1148 | if fileToCopy == nil { |
| 1149 | ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName) |
| 1150 | } else { |
| 1151 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil}) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1152 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1153 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1154 | } else { |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1155 | ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child)) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1156 | } |
| 1157 | case prebuiltTag: |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1158 | if prebuilt, ok := child.(android.PrebuiltEtcModule); ok { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1159 | fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1160 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1161 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1162 | } else { |
| 1163 | ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName) |
| 1164 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1165 | case testTag: |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1166 | if ccTest, ok := child.(*cc.Module); ok { |
| 1167 | if ccTest.IsTestPerSrcAllTestsVariation() { |
| 1168 | // Multiple-output test module (where `test_per_src: true`). |
| 1169 | // |
| 1170 | // `ccTest` is the "" ("all tests") variation of a `test_per_src` module. |
| 1171 | // We do not add this variation to `filesInfo`, as it has no output; |
| 1172 | // however, we do add the other variations of this module as indirect |
| 1173 | // dependencies (see below). |
| 1174 | return true |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1175 | } else { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1176 | // Single-output test module (where `test_per_src: false`). |
| 1177 | fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest) |
| 1178 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil}) |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1179 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1180 | return true |
| 1181 | } else { |
| 1182 | ctx.PropertyErrorf("tests", "%q is not a cc module", depName) |
| 1183 | } |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1184 | case keyTag: |
| 1185 | if key, ok := child.(*apexKey); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1186 | a.private_key_file = key.private_key_file |
| 1187 | a.public_key_file = key.public_key_file |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1188 | return false |
| 1189 | } else { |
| 1190 | ctx.PropertyErrorf("key", "%q is not an apex_key module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1191 | } |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1192 | case certificateTag: |
| 1193 | if dep, ok := child.(*java.AndroidAppCertificate); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1194 | a.container_certificate_file = dep.Certificate.Pem |
| 1195 | a.container_private_key_file = dep.Certificate.Key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1196 | return false |
| 1197 | } else { |
| 1198 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName) |
| 1199 | } |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1200 | case android.PrebuiltDepTag: |
| 1201 | // If the prebuilt is force disabled, remember to delete the prebuilt file |
| 1202 | // that might have been installed in the previous builds |
| 1203 | if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() { |
| 1204 | a.prebuiltFileToDelete = prebuilt.InstallFilename() |
| 1205 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 1206 | case androidAppTag: |
| 1207 | if ap, ok := child.(*java.AndroidApp); ok { |
| 1208 | fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName)) |
| 1209 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil}) |
| 1210 | return true |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 1211 | } else if ap, ok := child.(*java.AndroidAppImport); ok { |
| 1212 | fileToCopy, dirInApex := getCopyManifestForAndroidAppImport(ap, ctx.DeviceConfig().OverridePackageNameFor(depName)) |
| 1213 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil}) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 1214 | } else { |
| 1215 | ctx.PropertyErrorf("apps", "%q is not an android_app module", depName) |
| 1216 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1217 | } |
Jooyung Han | 8aee204 | 2019-10-29 05:08:31 +0900 | [diff] [blame] | 1218 | } else if !a.vndkApex { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1219 | // indirect dependencies |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1220 | if am, ok := child.(android.ApexModule); ok { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1221 | // We cannot use a switch statement on `depTag` here as the checked |
| 1222 | // tags used below are private (e.g. `cc.sharedDepTag`). |
Sam Saccone | e3c22f7 | 2019-11-13 15:23:05 +0000 | [diff] [blame] | 1223 | if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) || java.IsJniDepTag(depTag) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1224 | if cc, ok := child.(*cc.Module); ok { |
| 1225 | if android.InList(cc.Name(), providedNativeSharedLibs) { |
| 1226 | // If we're using a shared library which is provided from other APEX, |
| 1227 | // don't include it in this APEX |
| 1228 | return false |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 1229 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1230 | if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) { |
| 1231 | // If the dependency is a stubs lib, don't include it in this APEX, |
| 1232 | // but make sure that the lib is installed on the device. |
| 1233 | // In case no APEX is having the lib, the lib is installed to the system |
| 1234 | // partition. |
| 1235 | // |
| 1236 | // Always include if we are a host-apex however since those won't have any |
| 1237 | // system libraries. |
| 1238 | if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) { |
| 1239 | a.externalDeps = append(a.externalDeps, cc.Name()) |
| 1240 | } |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1241 | requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base()) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1242 | // Don't track further |
| 1243 | return false |
| 1244 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1245 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1246 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
| 1247 | return true |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1248 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1249 | } else if cc.IsTestPerSrcDepTag(depTag) { |
| 1250 | if cc, ok := child.(*cc.Module); ok { |
| 1251 | fileToCopy, dirInApex := getCopyManifestForExecutable(cc) |
| 1252 | // Handle modules created as `test_per_src` variations of a single test module: |
| 1253 | // use the name of the generated test binary (`fileToCopy`) instead of the name |
| 1254 | // of the original test module (`depName`, shared by all `test_per_src` |
| 1255 | // variations of that module). |
| 1256 | moduleName := filepath.Base(fileToCopy.String()) |
| 1257 | filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil}) |
| 1258 | return true |
| 1259 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1260 | } else if am.CanHaveApexVariants() && am.IsInstallableToApex() { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1261 | ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | return false |
| 1266 | }) |
| 1267 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1268 | // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries. |
| 1269 | // Build rules are generated by the dexpreopt singleton, and here we access build artifacts |
| 1270 | // via the global boot image config. |
| 1271 | if a.artApex { |
| 1272 | for arch, files := range java.DexpreoptedArtApexJars(ctx) { |
| 1273 | dirInApex := filepath.Join("javalib", arch.String()) |
| 1274 | for _, f := range files { |
| 1275 | localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String()) |
| 1276 | filesInfo = append(filesInfo, apexFile{f, localModule, dirInApex, etc, nil, nil}) |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1281 | if a.private_key_file == nil { |
Jiyong Park | fa0a373 | 2018-11-09 05:52:26 +0900 | [diff] [blame] | 1282 | ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key)) |
| 1283 | return |
| 1284 | } |
| 1285 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1286 | // remove duplicates in filesInfo |
| 1287 | removeDup := func(filesInfo []apexFile) []apexFile { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1288 | encountered := make(map[string]bool) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1289 | result := []apexFile{} |
| 1290 | for _, f := range filesInfo { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1291 | dest := filepath.Join(f.installDir, f.builtFile.Base()) |
| 1292 | if !encountered[dest] { |
| 1293 | encountered[dest] = true |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1294 | result = append(result, f) |
| 1295 | } |
| 1296 | } |
| 1297 | return result |
| 1298 | } |
| 1299 | filesInfo = removeDup(filesInfo) |
| 1300 | |
| 1301 | // to have consistent build rules |
| 1302 | sort.Slice(filesInfo, func(i, j int) bool { |
| 1303 | return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String() |
| 1304 | }) |
| 1305 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 1306 | // check apex_available requirements |
Jiyong Park | 583a226 | 2019-10-08 20:55:38 +0900 | [diff] [blame] | 1307 | if !ctx.Host() { |
| 1308 | for _, fi := range filesInfo { |
| 1309 | if am, ok := fi.module.(android.ApexModule); ok { |
| 1310 | if !am.AvailableFor(ctx.ModuleName()) { |
| 1311 | ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name()) |
| 1312 | return |
| 1313 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1318 | // prepend the name of this APEX to the module names. These names will be the names of |
| 1319 | // modules that will be defined if the APEX is flattened. |
| 1320 | for i := range filesInfo { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1321 | filesInfo[i].moduleName = filesInfo[i].moduleName + "." + ctx.ModuleName() + a.suffix |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1322 | } |
| 1323 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1324 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 1325 | a.filesInfo = filesInfo |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1326 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1327 | // prepare apex_manifest.json |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1328 | a.buildManifest(ctx, provideNativeLibs, requireNativeLibs) |
| 1329 | |
| 1330 | a.setCertificateAndPrivateKey(ctx) |
| 1331 | if a.properties.ApexType == flattenedApex { |
| 1332 | a.buildFlattenedApex(ctx) |
| 1333 | } else { |
| 1334 | a.buildUnflattenedApex(ctx) |
| 1335 | } |
| 1336 | |
| 1337 | apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName()) |
| 1338 | a.compatSymlinks = makeCompatSymlinks(apexName, ctx) |
| 1339 | } |
| 1340 | |
| 1341 | func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, requireNativeLibs []string) { |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1342 | manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1343 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1344 | a.manifestJsonFullOut = android.PathForModuleOut(ctx, "apex_manifest_full.json") |
| 1345 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1346 | // put dependency({provide|require}NativeLibs) in apex_manifest.json |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1347 | provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs) |
| 1348 | requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs)) |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1349 | |
| 1350 | // apex name can be overridden |
| 1351 | optCommands := []string{} |
| 1352 | if a.properties.Apex_name != nil { |
| 1353 | optCommands = append(optCommands, "-v name "+*a.properties.Apex_name) |
| 1354 | } |
| 1355 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1356 | ctx.Build(pctx, android.BuildParams{ |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1357 | Rule: apexManifestRule, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1358 | Input: manifestSrc, |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1359 | Output: a.manifestJsonFullOut, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1360 | Args: map[string]string{ |
| 1361 | "provideNativeLibs": strings.Join(provideNativeLibs, " "), |
| 1362 | "requireNativeLibs": strings.Join(requireNativeLibs, " "), |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1363 | "opt": strings.Join(optCommands, " "), |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1364 | }, |
| 1365 | }) |
| 1366 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1367 | // b/143654022 Q apexd can't understand newly added keys in apex_manifest.json |
Roland Levillain | 8ac0557 | 2019-11-13 10:45:55 +0000 | [diff] [blame] | 1368 | // prepare stripped-down version so that APEX modules built from R+ can be installed to Q |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1369 | a.manifestJsonOut = android.PathForModuleOut(ctx, "apex_manifest.json") |
| 1370 | ctx.Build(pctx, android.BuildParams{ |
| 1371 | Rule: stripApexManifestRule, |
| 1372 | Input: a.manifestJsonFullOut, |
| 1373 | Output: a.manifestJsonOut, |
| 1374 | }) |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 1375 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1376 | // from R+, protobuf binary format (.pb) is the standard format for apex_manifest |
| 1377 | a.manifestPbOut = android.PathForModuleOut(ctx, "apex_manifest.pb") |
| 1378 | ctx.Build(pctx, android.BuildParams{ |
| 1379 | Rule: pbApexManifestRule, |
| 1380 | Input: a.manifestJsonFullOut, |
| 1381 | Output: a.manifestPbOut, |
| 1382 | }) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1383 | } |
| 1384 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 1385 | func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath { |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1386 | noticeFiles := []android.Path{} |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1387 | for _, f := range a.filesInfo { |
| 1388 | if f.module != nil { |
| 1389 | notice := f.module.NoticeFile() |
| 1390 | if notice.Valid() { |
| 1391 | noticeFiles = append(noticeFiles, notice.Path()) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | } |
| 1395 | // append the notice file specified in the apex module itself |
| 1396 | if a.NoticeFile().Valid() { |
| 1397 | noticeFiles = append(noticeFiles, a.NoticeFile().Path()) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1398 | } |
| 1399 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 1400 | if len(noticeFiles) == 0 { |
| 1401 | return android.OptionalPath{} |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1402 | } |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 1403 | |
Jaewoong Jung | 9877279 | 2019-07-01 17:15:13 -0700 | [diff] [blame] | 1404 | return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1405 | } |
| 1406 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1407 | func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1408 | var abis []string |
| 1409 | for _, target := range ctx.MultiTargets() { |
| 1410 | if len(target.Arch.Abi) > 0 { |
| 1411 | abis = append(abis, target.Arch.Abi[0]) |
| 1412 | } |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 1413 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1414 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1415 | abis = android.FirstUniqueStrings(abis) |
| 1416 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1417 | apexType := a.properties.ApexType |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1418 | suffix := apexType.suffix() |
| 1419 | unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1420 | |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 1421 | filesToCopy := []android.Path{} |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1422 | for _, f := range a.filesInfo { |
| 1423 | filesToCopy = append(filesToCopy, f.builtFile) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1424 | } |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 1425 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1426 | copyCommands := []string{} |
Nikita Ioffe | 5d5ae76 | 2019-08-31 14:38:05 +0100 | [diff] [blame] | 1427 | emitCommands := []string{} |
| 1428 | imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt") |
| 1429 | emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String()) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1430 | for i, src := range filesToCopy { |
| 1431 | dest := filepath.Join(a.filesInfo[i].installDir, src.Base()) |
Nikita Ioffe | 5d5ae76 | 2019-08-31 14:38:05 +0100 | [diff] [blame] | 1432 | emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String()) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1433 | dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1434 | copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path)) |
| 1435 | copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 1436 | for _, sym := range a.filesInfo[i].symlinks { |
| 1437 | symlinkDest := filepath.Join(filepath.Dir(dest_path), sym) |
| 1438 | copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest) |
| 1439 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1440 | } |
Dario Freni | e423582 | 2019-10-28 14:49:27 +0000 | [diff] [blame] | 1441 | emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String()) |
| 1442 | |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 1443 | implicitInputs := append(android.Paths(nil), filesToCopy...) |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1444 | implicitInputs = append(implicitInputs, a.manifestPbOut, a.manifestJsonFullOut, a.manifestJsonOut) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1445 | |
Nikita Ioffe | 5d5ae76 | 2019-08-31 14:38:05 +0100 | [diff] [blame] | 1446 | if a.properties.Whitelisted_files != nil { |
| 1447 | ctx.Build(pctx, android.BuildParams{ |
| 1448 | Rule: emitApexContentRule, |
| 1449 | Implicits: implicitInputs, |
| 1450 | Output: imageContentFile, |
| 1451 | Description: "emit apex image content", |
| 1452 | Args: map[string]string{ |
| 1453 | "emit_commands": strings.Join(emitCommands, " && "), |
| 1454 | }, |
| 1455 | }) |
| 1456 | implicitInputs = append(implicitInputs, imageContentFile) |
| 1457 | whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files)) |
| 1458 | |
Nikita Ioffe | 1acf6f9 | 2019-09-04 11:53:14 +0100 | [diff] [blame] | 1459 | phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output") |
Nikita Ioffe | 5d5ae76 | 2019-08-31 14:38:05 +0100 | [diff] [blame] | 1460 | ctx.Build(pctx, android.BuildParams{ |
| 1461 | Rule: diffApexContentRule, |
| 1462 | Implicits: implicitInputs, |
| 1463 | Output: phonyOutput, |
| 1464 | Description: "diff apex image content", |
| 1465 | Args: map[string]string{ |
| 1466 | "whitelisted_files_file": whitelistedFilesFile.String(), |
| 1467 | "image_content_file": imageContentFile.String(), |
| 1468 | "apex_module_name": ctx.ModuleName(), |
| 1469 | }, |
| 1470 | }) |
| 1471 | |
| 1472 | implicitInputs = append(implicitInputs, phonyOutput) |
| 1473 | } |
| 1474 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1475 | outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String() |
| 1476 | prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1477 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1478 | if apexType == imageApex { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1479 | // files and dirs that will be created in APEX |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1480 | var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"} |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1481 | var executablePaths []string // this also includes dirs |
| 1482 | for _, f := range a.filesInfo { |
| 1483 | pathInApex := filepath.Join(f.installDir, f.builtFile.Base()) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1484 | if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1485 | executablePaths = append(executablePaths, pathInApex) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 1486 | for _, s := range f.symlinks { |
Jiyong Park | c80b5fa | 2019-07-20 14:24:33 +0900 | [diff] [blame] | 1487 | executablePaths = append(executablePaths, filepath.Join(f.installDir, s)) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 1488 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1489 | } else { |
| 1490 | readOnlyPaths = append(readOnlyPaths, pathInApex) |
| 1491 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1492 | dir := f.installDir |
| 1493 | for !android.InList(dir, executablePaths) && dir != "" { |
| 1494 | executablePaths = append(executablePaths, dir) |
| 1495 | dir, _ = filepath.Split(dir) // move up to the parent |
| 1496 | if len(dir) > 0 { |
| 1497 | // remove trailing slash |
| 1498 | dir = dir[:len(dir)-1] |
| 1499 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1500 | } |
| 1501 | } |
| 1502 | sort.Strings(readOnlyPaths) |
| 1503 | sort.Strings(executablePaths) |
| 1504 | cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config") |
| 1505 | ctx.Build(pctx, android.BuildParams{ |
| 1506 | Rule: generateFsConfig, |
| 1507 | Output: cannedFsConfig, |
| 1508 | Description: "generate fs config", |
| 1509 | Args: map[string]string{ |
| 1510 | "ro_paths": strings.Join(readOnlyPaths, " "), |
| 1511 | "exec_paths": strings.Join(executablePaths, " "), |
| 1512 | }, |
| 1513 | }) |
| 1514 | |
| 1515 | fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName()) |
| 1516 | fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts" |
| 1517 | fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath) |
| 1518 | if !fileContextsOptionalPath.Valid() { |
| 1519 | ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath) |
| 1520 | return |
| 1521 | } |
| 1522 | fileContexts := fileContextsOptionalPath.Path() |
| 1523 | |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 1524 | optFlags := []string{} |
| 1525 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1526 | // Additional implicit inputs. |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 1527 | implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file) |
| 1528 | optFlags = append(optFlags, "--pubkey "+a.public_key_file.String()) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1529 | |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 1530 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
| 1531 | if overridden { |
| 1532 | optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName) |
| 1533 | } |
| 1534 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 1535 | if a.properties.AndroidManifest != nil { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1536 | androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest)) |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 1537 | implicitInputs = append(implicitInputs, androidManifestFile) |
| 1538 | optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String()) |
| 1539 | } |
| 1540 | |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 1541 | targetSdkVersion := ctx.Config().DefaultAppTargetSdk() |
| 1542 | if targetSdkVersion == ctx.Config().PlatformSdkCodename() && |
| 1543 | ctx.Config().UnbundledBuild() && |
| 1544 | !ctx.Config().UnbundledBuildUsePrebuiltSdks() && |
| 1545 | ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") { |
| 1546 | apiFingerprint := java.ApiFingerprintPath(ctx) |
| 1547 | targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String()) |
| 1548 | implicitInputs = append(implicitInputs, apiFingerprint) |
| 1549 | } |
| 1550 | optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion) |
| 1551 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 1552 | noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix) |
| 1553 | if noticeFile.Valid() { |
| 1554 | // If there's a NOTICE file, embed it as an asset file in the APEX. |
| 1555 | implicitInputs = append(implicitInputs, noticeFile.Path()) |
| 1556 | optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String())) |
| 1557 | } |
| 1558 | |
Jooyung Han | e65ed7c | 2019-08-28 00:27:35 +0900 | [diff] [blame] | 1559 | if !ctx.Config().UnbundledBuild() && a.installable() { |
| 1560 | // Apexes which are supposed to be installed in builtin dirs(/system, etc) |
| 1561 | // don't need hashtree for activation. Therefore, by removing hashtree from |
| 1562 | // apex bundle (filesystem image in it, to be specific), we can save storage. |
| 1563 | optFlags = append(optFlags, "--no_hashtree") |
| 1564 | } |
| 1565 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1566 | if a.properties.Apex_name != nil { |
| 1567 | // If apex_name is set, apexer can skip checking if key name matches with apex name. |
| 1568 | // Note that apex_manifest is also mended. |
| 1569 | optFlags = append(optFlags, "--do_not_check_keyname") |
| 1570 | } |
| 1571 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1572 | ctx.Build(pctx, android.BuildParams{ |
| 1573 | Rule: apexRule, |
| 1574 | Implicits: implicitInputs, |
| 1575 | Output: unsignedOutputFile, |
| 1576 | Description: "apex (" + apexType.name() + ")", |
| 1577 | Args: map[string]string{ |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1578 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
| 1579 | "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(), |
| 1580 | "copy_commands": strings.Join(copyCommands, " && "), |
| 1581 | "manifest_json_full": a.manifestJsonFullOut.String(), |
| 1582 | "manifest_json": a.manifestJsonOut.String(), |
| 1583 | "manifest": a.manifestPbOut.String(), |
| 1584 | "file_contexts": fileContexts.String(), |
| 1585 | "canned_fs_config": cannedFsConfig.String(), |
| 1586 | "key": a.private_key_file.String(), |
| 1587 | "opt_flags": strings.Join(optFlags, " "), |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1588 | }, |
| 1589 | }) |
| 1590 | |
| 1591 | apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix) |
| 1592 | bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip") |
| 1593 | a.bundleModuleFile = bundleModuleFile |
| 1594 | |
| 1595 | ctx.Build(pctx, android.BuildParams{ |
| 1596 | Rule: apexProtoConvertRule, |
| 1597 | Input: unsignedOutputFile, |
| 1598 | Output: apexProtoFile, |
| 1599 | Description: "apex proto convert", |
| 1600 | }) |
| 1601 | |
| 1602 | ctx.Build(pctx, android.BuildParams{ |
| 1603 | Rule: apexBundleRule, |
| 1604 | Input: apexProtoFile, |
| 1605 | Output: a.bundleModuleFile, |
| 1606 | Description: "apex bundle module", |
| 1607 | Args: map[string]string{ |
| 1608 | "abi": strings.Join(abis, "."), |
| 1609 | }, |
| 1610 | }) |
| 1611 | } else { |
| 1612 | ctx.Build(pctx, android.BuildParams{ |
| 1613 | Rule: zipApexRule, |
| 1614 | Implicits: implicitInputs, |
| 1615 | Output: unsignedOutputFile, |
| 1616 | Description: "apex (" + apexType.name() + ")", |
| 1617 | Args: map[string]string{ |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1618 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
| 1619 | "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(), |
| 1620 | "copy_commands": strings.Join(copyCommands, " && "), |
| 1621 | "manifest": a.manifestPbOut.String(), |
| 1622 | "manifest_json_full": a.manifestJsonFullOut.String(), |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1623 | }, |
| 1624 | }) |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1625 | } |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1626 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1627 | a.outputFile = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1628 | ctx.Build(pctx, android.BuildParams{ |
| 1629 | Rule: java.Signapk, |
| 1630 | Description: "signapk", |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1631 | Output: a.outputFile, |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1632 | Input: unsignedOutputFile, |
Dan Willemsen | dd651fa | 2019-06-13 04:48:54 +0000 | [diff] [blame] | 1633 | Implicits: []android.Path{ |
| 1634 | a.container_certificate_file, |
| 1635 | a.container_private_key_file, |
| 1636 | }, |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1637 | Args: map[string]string{ |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1638 | "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(), |
Jiyong Park | bfe64a1 | 2018-11-22 02:51:54 +0900 | [diff] [blame] | 1639 | "flags": "-a 4096", //alignment |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1640 | }, |
| 1641 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1642 | |
| 1643 | // Install to $OUT/soong/{target,host}/.../apex |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1644 | if a.installable() { |
| 1645 | ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFile) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1646 | } |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1647 | a.buildFilesInfo(ctx) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1648 | } |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1649 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1650 | func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1651 | // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it |
| 1652 | // reply true to `InstallBypassMake()` (thus making the call |
| 1653 | // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir` |
| 1654 | // instead of `android.PathForOutput`) to return the correct path to the flattened |
| 1655 | // APEX (as its contents is installed by Make, not Soong). |
| 1656 | factx := flattenedApexContext{ctx} |
| 1657 | apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName()) |
| 1658 | a.outputFile = android.PathForModuleInstall(&factx, "apex", apexName) |
| 1659 | |
| 1660 | a.buildFilesInfo(ctx) |
| 1661 | } |
| 1662 | |
| 1663 | func (a *apexBundle) setCertificateAndPrivateKey(ctx android.ModuleContext) { |
| 1664 | cert := String(a.properties.Certificate) |
| 1665 | if cert != "" && android.SrcIsModule(cert) == "" { |
| 1666 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
| 1667 | a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem") |
| 1668 | a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8") |
| 1669 | } else if cert == "" { |
| 1670 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
| 1671 | a.container_certificate_file = pem |
| 1672 | a.container_private_key_file = key |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) { |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1677 | if a.installable() { |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 1678 | // For flattened APEX, do nothing but make sure that apex_manifest.json and apex_pubkey are also copied along |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1679 | // with other ordinary files. |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1680 | a.filesInfo = append(a.filesInfo, apexFile{a.manifestJsonOut, "apex_manifest.json." + ctx.ModuleName() + a.suffix, ".", etc, nil, nil}) |
| 1681 | a.filesInfo = append(a.filesInfo, apexFile{a.manifestPbOut, "apex_manifest.pb." + ctx.ModuleName() + a.suffix, ".", etc, nil, nil}) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1682 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 1683 | // rename to apex_pubkey |
| 1684 | copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey") |
| 1685 | ctx.Build(pctx, android.BuildParams{ |
| 1686 | Rule: android.Cp, |
| 1687 | Input: a.public_key_file, |
| 1688 | Output: copiedPubkey, |
| 1689 | }) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1690 | a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, "apex_pubkey." + ctx.ModuleName() + a.suffix, ".", etc, nil, nil}) |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 1691 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1692 | if a.properties.ApexType == flattenedApex { |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 1693 | apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName()) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1694 | for _, fi := range a.filesInfo { |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 1695 | dir := filepath.Join("apex", apexName, fi.installDir) |
Alex Light | f4857cf | 2019-02-22 13:00:04 -0800 | [diff] [blame] | 1696 | target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile) |
| 1697 | for _, sym := range fi.symlinks { |
| 1698 | ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target) |
| 1699 | } |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1700 | } |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1701 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1702 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | func (a *apexBundle) AndroidMk() android.AndroidMkData { |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 1706 | if a.properties.HideFromMake { |
| 1707 | return android.AndroidMkData{ |
| 1708 | Disabled: true, |
| 1709 | } |
| 1710 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1711 | writers := []android.AndroidMkData{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1712 | writers = append(writers, a.androidMkForType()) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1713 | return android.AndroidMkData{ |
| 1714 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 1715 | for _, data := range writers { |
| 1716 | data.Custom(w, name, prefix, moduleDir, data) |
| 1717 | } |
| 1718 | }} |
| 1719 | } |
| 1720 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1721 | func (a *apexBundle) androidMkForFiles(w io.Writer, apexName, moduleDir string) []string { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1722 | moduleNames := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1723 | apexType := a.properties.ApexType |
| 1724 | // To avoid creating duplicate build rules, run this function only when primaryApexType is true |
| 1725 | // to install symbol files in $(PRODUCT_OUT}/apex. |
| 1726 | // And if apexType is flattened, run this function to install files in $(PRODUCT_OUT}/system/apex. |
| 1727 | if !a.primaryApexType && apexType != flattenedApex { |
| 1728 | return moduleNames |
| 1729 | } |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1730 | |
| 1731 | for _, fi := range a.filesInfo { |
| 1732 | if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake { |
| 1733 | continue |
| 1734 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 1735 | |
| 1736 | if !android.InList(fi.moduleName, moduleNames) { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1737 | moduleNames = append(moduleNames, fi.moduleName) |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 1738 | } |
| 1739 | |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1740 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1741 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1742 | fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName) |
Roland Levillain | 411c584 | 2019-09-19 16:37:20 +0100 | [diff] [blame] | 1743 | // /apex/<apex_name>/{lib|framework|...} |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 1744 | pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1745 | if apexType == flattenedApex { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1746 | // /system/apex/<name>/{lib|framework|...} |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 1747 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(), |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 1748 | apexName, fi.installDir)) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1749 | if a.primaryApexType { |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 1750 | fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated) |
| 1751 | } |
Alex Light | f4857cf | 2019-02-22 13:00:04 -0800 | [diff] [blame] | 1752 | if len(fi.symlinks) > 0 { |
| 1753 | fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " ")) |
| 1754 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1755 | |
| 1756 | if fi.module != nil && fi.module.NoticeFile().Valid() { |
| 1757 | fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String()) |
| 1758 | } |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1759 | } else { |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1760 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1761 | } |
| 1762 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String()) |
| 1763 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake()) |
| 1764 | if fi.module != nil { |
| 1765 | archStr := fi.module.Target().Arch.ArchType.String() |
| 1766 | host := false |
| 1767 | switch fi.module.Target().Os.Class { |
| 1768 | case android.Host: |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 1769 | if fi.module.Target().Arch.ArchType != android.Common { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1770 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) |
| 1771 | } |
| 1772 | host = true |
| 1773 | case android.HostCross: |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 1774 | if fi.module.Target().Arch.ArchType != android.Common { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1775 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) |
| 1776 | } |
| 1777 | host = true |
| 1778 | case android.Device: |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 1779 | if fi.module.Target().Arch.ArchType != android.Common { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1780 | fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr) |
| 1781 | } |
| 1782 | } |
| 1783 | if host { |
| 1784 | makeOs := fi.module.Target().Os.String() |
| 1785 | if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic { |
| 1786 | makeOs = "linux" |
| 1787 | } |
| 1788 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs) |
| 1789 | fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") |
| 1790 | } |
| 1791 | } |
| 1792 | if fi.class == javaSharedLib { |
| 1793 | javaModule := fi.module.(*java.Library) |
| 1794 | // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore |
| 1795 | // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise |
| 1796 | // we will have foo.jar.jar |
| 1797 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar")) |
| 1798 | fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String()) |
| 1799 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String()) |
| 1800 | fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String()) |
| 1801 | fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") |
| 1802 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") |
Logan Chien | 0342c58 | 2019-09-10 09:08:24 -0700 | [diff] [blame] | 1803 | } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1804 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base()) |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 1805 | if cc, ok := fi.module.(*cc.Module); ok { |
| 1806 | if cc.UnstrippedOutputFile() != nil { |
| 1807 | fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String()) |
| 1808 | } |
| 1809 | cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w) |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 1810 | if cc.CoverageOutputFile().Valid() { |
| 1811 | fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String()) |
| 1812 | } |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1813 | } |
| 1814 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk") |
| 1815 | } else { |
| 1816 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base()) |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 1817 | // For flattened apexes, compat symlinks are attached to apex_manifest.json which is guaranteed for every apex |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1818 | if a.primaryApexType && fi.builtFile == a.manifestPbOut && len(a.compatSymlinks) > 0 { |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 1819 | fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(a.compatSymlinks, " && ")) |
| 1820 | } |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1821 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
| 1822 | } |
| 1823 | } |
| 1824 | return moduleNames |
| 1825 | } |
| 1826 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1827 | func (a *apexBundle) androidMkForType() android.AndroidMkData { |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1828 | return android.AndroidMkData{ |
| 1829 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 1830 | moduleNames := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1831 | apexType := a.properties.ApexType |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1832 | if a.installable() { |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 1833 | apexName := proptools.StringDefault(a.properties.Apex_name, name) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1834 | moduleNames = a.androidMkForFiles(w, apexName, moduleDir) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1835 | } |
| 1836 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1837 | if apexType == flattenedApex { |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1838 | // Only image APEXes can be flattened. |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1839 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1840 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1841 | fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1842 | if len(moduleNames) > 0 { |
| 1843 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " ")) |
| 1844 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1845 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1846 | fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.outputFile.String()) |
Roland Levillain | 935639d | 2019-08-13 14:55:28 +0100 | [diff] [blame] | 1847 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1848 | } else { |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1849 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1850 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1851 | fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1852 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class? |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1853 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String()) |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 1854 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String()) |
Colin Cross | 189ff98 | 2019-01-02 22:32:27 -0800 | [diff] [blame] | 1855 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix()) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1856 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable()) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1857 | if len(moduleNames) > 0 { |
| 1858 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " ")) |
| 1859 | } |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 1860 | if len(a.externalDeps) > 0 { |
| 1861 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " ")) |
| 1862 | } |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 1863 | var postInstallCommands []string |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1864 | if a.prebuiltFileToDelete != "" { |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 1865 | postInstallCommands = append(postInstallCommands, "rm -rf "+ |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 1866 | filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete)) |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1867 | } |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 1868 | // For unflattened apexes, compat symlinks are attached to apex package itself as LOCAL_POST_INSTALL_CMD |
| 1869 | postInstallCommands = append(postInstallCommands, a.compatSymlinks...) |
| 1870 | if len(postInstallCommands) > 0 { |
| 1871 | fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && ")) |
| 1872 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1873 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1874 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1875 | if apexType == imageApex { |
| 1876 | fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String()) |
| 1877 | } |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1878 | } |
| 1879 | }} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1880 | } |
| 1881 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1882 | func newApexBundle() *apexBundle { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1883 | module := &apexBundle{} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1884 | module.AddProperties(&module.properties) |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1885 | module.AddProperties(&module.targetProperties) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1886 | module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 1887 | return class == android.Device && ctx.Config().DevicePrefer32BitExecutables() |
| 1888 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1889 | android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1890 | android.InitDefaultableModule(module) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1891 | android.InitSdkAwareModule(module) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1892 | return module |
| 1893 | } |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1894 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1895 | func ApexBundleFactory(testApex bool, artApex bool) android.Module { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1896 | bundle := newApexBundle() |
| 1897 | bundle.testApex = testApex |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1898 | bundle.artApex = artApex |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1899 | return bundle |
| 1900 | } |
| 1901 | |
| 1902 | func testApexBundleFactory() android.Module { |
| 1903 | bundle := newApexBundle() |
| 1904 | bundle.testApex = true |
| 1905 | return bundle |
| 1906 | } |
| 1907 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1908 | func BundleFactory() android.Module { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1909 | return newApexBundle() |
| 1910 | } |
| 1911 | |
| 1912 | // apex_vndk creates a special variant of apex modules which contains only VNDK libraries. |
| 1913 | // If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically. |
| 1914 | // If not specified, then the "current" versions are gathered. |
| 1915 | func vndkApexBundleFactory() android.Module { |
| 1916 | bundle := newApexBundle() |
| 1917 | bundle.vndkApex = true |
| 1918 | bundle.AddProperties(&bundle.vndkProperties) |
| 1919 | android.AddLoadHook(bundle, func(ctx android.LoadHookContext) { |
| 1920 | ctx.AppendProperties(&struct { |
| 1921 | Compile_multilib *string |
| 1922 | }{ |
| 1923 | proptools.StringPtr("both"), |
| 1924 | }) |
| 1925 | }) |
| 1926 | return bundle |
| 1927 | } |
| 1928 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1929 | func (a *apexBundle) vndkVersion(config android.DeviceConfig) string { |
| 1930 | vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current") |
| 1931 | if vndkVersion == "current" { |
| 1932 | vndkVersion = config.PlatformVndkVersion() |
| 1933 | } |
| 1934 | return vndkVersion |
| 1935 | } |
| 1936 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1937 | // |
| 1938 | // Defaults |
| 1939 | // |
| 1940 | type Defaults struct { |
| 1941 | android.ModuleBase |
| 1942 | android.DefaultsModuleBase |
| 1943 | } |
| 1944 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1945 | func defaultsFactory() android.Module { |
| 1946 | return DefaultsFactory() |
| 1947 | } |
| 1948 | |
| 1949 | func DefaultsFactory(props ...interface{}) android.Module { |
| 1950 | module := &Defaults{} |
| 1951 | |
| 1952 | module.AddProperties(props...) |
| 1953 | module.AddProperties( |
| 1954 | &apexBundleProperties{}, |
| 1955 | &apexTargetBundleProperties{}, |
| 1956 | ) |
| 1957 | |
| 1958 | android.InitDefaultsModule(module) |
| 1959 | return module |
| 1960 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1961 | |
| 1962 | // |
| 1963 | // Prebuilt APEX |
| 1964 | // |
| 1965 | type Prebuilt struct { |
| 1966 | android.ModuleBase |
| 1967 | prebuilt android.Prebuilt |
| 1968 | |
| 1969 | properties PrebuiltProperties |
| 1970 | |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1971 | inputApex android.Path |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 1972 | installDir android.InstallPath |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1973 | installFilename string |
Nikita Ioffe | 89ecd59 | 2019-04-05 02:10:45 +0100 | [diff] [blame] | 1974 | outputApex android.WritablePath |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | type PrebuiltProperties struct { |
| 1978 | // the path to the prebuilt .apex file to import. |
Jiyong Park | 2cb5288 | 2019-07-07 12:39:16 +0900 | [diff] [blame] | 1979 | Source string `blueprint:"mutated"` |
| 1980 | ForceDisable bool `blueprint:"mutated"` |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1981 | |
| 1982 | Src *string |
| 1983 | Arch struct { |
| 1984 | Arm struct { |
| 1985 | Src *string |
| 1986 | } |
| 1987 | Arm64 struct { |
| 1988 | Src *string |
| 1989 | } |
| 1990 | X86 struct { |
| 1991 | Src *string |
| 1992 | } |
| 1993 | X86_64 struct { |
| 1994 | Src *string |
| 1995 | } |
| 1996 | } |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1997 | |
| 1998 | Installable *bool |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1999 | // Optional name for the installed apex. If unspecified, name of the |
| 2000 | // module is used as the file name |
| 2001 | Filename *string |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2002 | |
| 2003 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 2004 | // (in Make or Soong). |
| 2005 | // This does not completely prevent installation of the overridden binaries, but if both |
| 2006 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 2007 | // from PRODUCT_PACKAGES. |
| 2008 | Overrides []string |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | func (p *Prebuilt) installable() bool { |
| 2012 | return p.properties.Installable == nil || proptools.Bool(p.properties.Installable) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | e3ef3c8 | 2019-07-15 15:31:16 +0900 | [diff] [blame] | 2016 | // If the device is configured to use flattened APEX, force disable the prebuilt because |
| 2017 | // the prebuilt is a non-flattened one. |
| 2018 | forceDisable := ctx.Config().FlattenApex() |
| 2019 | |
| 2020 | // Force disable the prebuilts when we are doing unbundled build. We do unbundled build |
| 2021 | // to build the prebuilts themselves. |
Jiyong Park | ca8992e | 2019-07-17 08:21:36 +0900 | [diff] [blame] | 2022 | forceDisable = forceDisable || ctx.Config().UnbundledBuild() |
Jiyong Park | 50b81e5 | 2019-07-11 11:24:41 +0900 | [diff] [blame] | 2023 | |
Kun Niu | 10c9f83 | 2019-07-29 16:28:57 -0700 | [diff] [blame] | 2024 | // Force disable the prebuilts when coverage is enabled. |
| 2025 | forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled() |
| 2026 | forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") |
| 2027 | |
Jiyong Park | 50b81e5 | 2019-07-11 11:24:41 +0900 | [diff] [blame] | 2028 | // b/137216042 don't use prebuilts when address sanitizer is on |
| 2029 | forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) || |
| 2030 | android.InList("hwaddress", ctx.Config().SanitizeDevice()) |
| 2031 | |
| 2032 | if forceDisable && p.prebuilt.SourceExists() { |
Jiyong Park | 2cb5288 | 2019-07-07 12:39:16 +0900 | [diff] [blame] | 2033 | p.properties.ForceDisable = true |
| 2034 | return |
| 2035 | } |
| 2036 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 2037 | // This is called before prebuilt_select and prebuilt_postdeps mutators |
| 2038 | // The mutators requires that src to be set correctly for each arch so that |
| 2039 | // arch variants are disabled when src is not provided for the arch. |
| 2040 | if len(ctx.MultiTargets()) != 1 { |
| 2041 | ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex") |
| 2042 | return |
| 2043 | } |
| 2044 | var src string |
| 2045 | switch ctx.MultiTargets()[0].Arch.ArchType { |
| 2046 | case android.Arm: |
| 2047 | src = String(p.properties.Arch.Arm.Src) |
| 2048 | case android.Arm64: |
| 2049 | src = String(p.properties.Arch.Arm64.Src) |
| 2050 | case android.X86: |
| 2051 | src = String(p.properties.Arch.X86.Src) |
| 2052 | case android.X86_64: |
| 2053 | src = String(p.properties.Arch.X86_64.Src) |
| 2054 | default: |
| 2055 | ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String()) |
| 2056 | return |
| 2057 | } |
| 2058 | if src == "" { |
| 2059 | src = String(p.properties.Src) |
| 2060 | } |
| 2061 | p.properties.Source = src |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 2064 | func (p *Prebuilt) isForceDisabled() bool { |
| 2065 | return p.properties.ForceDisable |
| 2066 | } |
| 2067 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2068 | func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) { |
| 2069 | switch tag { |
| 2070 | case "": |
| 2071 | return android.Paths{p.outputApex}, nil |
| 2072 | default: |
| 2073 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 2074 | } |
Nikita Ioffe | 89ecd59 | 2019-04-05 02:10:45 +0100 | [diff] [blame] | 2075 | } |
| 2076 | |
Jiyong Park | 4d27704 | 2019-04-23 18:00:10 +0900 | [diff] [blame] | 2077 | func (p *Prebuilt) InstallFilename() string { |
| 2078 | return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix) |
| 2079 | } |
| 2080 | |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2081 | func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 2cb5288 | 2019-07-07 12:39:16 +0900 | [diff] [blame] | 2082 | if p.properties.ForceDisable { |
| 2083 | return |
| 2084 | } |
| 2085 | |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2086 | // TODO(jungjw): Check the key validity. |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 2087 | p.inputApex = p.Prebuilt().SingleSourcePath(ctx) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2088 | p.installDir = android.PathForModuleInstall(ctx, "apex") |
Jiyong Park | 4d27704 | 2019-04-23 18:00:10 +0900 | [diff] [blame] | 2089 | p.installFilename = p.InstallFilename() |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 2090 | if !strings.HasSuffix(p.installFilename, imageApexSuffix) { |
| 2091 | ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix) |
| 2092 | } |
Nikita Ioffe | 89ecd59 | 2019-04-05 02:10:45 +0100 | [diff] [blame] | 2093 | p.outputApex = android.PathForModuleOut(ctx, p.installFilename) |
| 2094 | ctx.Build(pctx, android.BuildParams{ |
| 2095 | Rule: android.Cp, |
| 2096 | Input: p.inputApex, |
| 2097 | Output: p.outputApex, |
| 2098 | }) |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 2099 | if p.installable() { |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 2100 | ctx.InstallFile(p.installDir, p.installFilename, p.inputApex) |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 2101 | } |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 2102 | |
| 2103 | // TODO(b/143192278): Add compat symlinks for prebuilt_apex |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | func (p *Prebuilt) Prebuilt() *android.Prebuilt { |
| 2107 | return &p.prebuilt |
| 2108 | } |
| 2109 | |
| 2110 | func (p *Prebuilt) Name() string { |
| 2111 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 2112 | } |
| 2113 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2114 | func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries { |
| 2115 | return android.AndroidMkEntries{ |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2116 | Class: "ETC", |
| 2117 | OutputFile: android.OptionalPathForPath(p.inputApex), |
| 2118 | Include: "$(BUILD_PREBUILT)", |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 2119 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 2120 | func(entries *android.AndroidMkEntries) { |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 2121 | entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String()) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 2122 | entries.SetString("LOCAL_MODULE_STEM", p.installFilename) |
| 2123 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) |
| 2124 | entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...) |
| 2125 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2126 | }, |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 2131 | func PrebuiltFactory() android.Module { |
| 2132 | module := &Prebuilt{} |
| 2133 | module.AddProperties(&module.properties) |
Jaewoong Jung | 3e18b19 | 2019-06-11 12:25:34 -0700 | [diff] [blame] | 2134 | android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source") |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 2135 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2136 | return module |
| 2137 | } |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 2138 | |
| 2139 | func makeCompatSymlinks(apexName string, ctx android.ModuleContext) (symlinks []string) { |
| 2140 | // small helper to add symlink commands |
| 2141 | addSymlink := func(target, dir, linkName string) { |
| 2142 | outDir := filepath.Join("$(PRODUCT_OUT)", dir) |
| 2143 | link := filepath.Join(outDir, linkName) |
| 2144 | symlinks = append(symlinks, "mkdir -p "+outDir+" && rm -rf "+link+" && ln -sf "+target+" "+link) |
| 2145 | } |
| 2146 | |
| 2147 | // TODO(b/142911355): [VNDK APEX] Fix hard-coded references to /system/lib/vndk |
| 2148 | // When all hard-coded references are fixed, remove symbolic links |
| 2149 | // Note that we should keep following symlinks for older VNDKs (<=29) |
| 2150 | // Since prebuilt vndk libs still depend on system/lib/vndk path |
| 2151 | if strings.HasPrefix(apexName, vndkApexNamePrefix) { |
| 2152 | // the name of vndk apex is formatted "com.android.vndk.v" + version |
| 2153 | vndkVersion := strings.TrimPrefix(apexName, vndkApexNamePrefix) |
| 2154 | if ctx.Config().Android64() { |
| 2155 | addSymlink("/apex/"+apexName+"/lib64", "/system/lib64", "vndk-sp-"+vndkVersion) |
| 2156 | addSymlink("/apex/"+apexName+"/lib64", "/system/lib64", "vndk-"+vndkVersion) |
| 2157 | } |
| 2158 | if !ctx.Config().Android64() || ctx.DeviceConfig().DeviceSecondaryArch() != "" { |
| 2159 | addSymlink("/apex/"+apexName+"/lib", "/system/lib", "vndk-sp-"+vndkVersion) |
| 2160 | addSymlink("/apex/"+apexName+"/lib", "/system/lib", "vndk-"+vndkVersion) |
| 2161 | } |
| 2162 | } |
| 2163 | return |
| 2164 | } |