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