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