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