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 | |
| 49 | // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate |
| 50 | // against the binary policy using sefcontext_compiler -p <policy>. |
| 51 | |
| 52 | // TODO(b/114327326): automate the generation of file_contexts |
| 53 | apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{ |
| 54 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
| 55 | `(${copy_commands}) && ` + |
| 56 | `APEXER_TOOL_PATH=${tool_path} ` + |
Jiyong Park | 2556015 | 2018-11-20 09:57:52 +0900 | [diff] [blame] | 57 | `${apexer} --force --manifest ${manifest} ` + |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 58 | `--file_contexts ${file_contexts} ` + |
| 59 | `--canned_fs_config ${canned_fs_config} ` + |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 60 | `--payload_type image ` + |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 61 | `--key ${key} ${opt_flags} ${image_dir} ${out} `, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 62 | CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}", |
| 63 | "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", |
| 64 | "${soong_zip}", "${zipalign}", "${aapt2}"}, |
| 65 | Description: "APEX ${image_dir} => ${out}", |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 66 | }, "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] | 67 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 68 | zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ |
| 69 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
| 70 | `(${copy_commands}) && ` + |
| 71 | `APEXER_TOOL_PATH=${tool_path} ` + |
| 72 | `${apexer} --force --manifest ${manifest} ` + |
| 73 | `--payload_type zip ` + |
| 74 | `${image_dir} ${out} `, |
| 75 | CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"}, |
| 76 | Description: "ZipAPEX ${image_dir} => ${out}", |
| 77 | }, "tool_path", "image_dir", "copy_commands", "manifest") |
| 78 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 79 | apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule", |
| 80 | blueprint.RuleParams{ |
| 81 | Command: `${aapt2} convert --output-format proto $in -o $out`, |
| 82 | CommandDeps: []string{"${aapt2}"}, |
| 83 | }) |
| 84 | |
| 85 | apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{ |
Jiyong Park | 1ed0fc5 | 2018-11-23 13:22:21 +0900 | [diff] [blame] | 86 | Command: `${zip2zip} -i $in -o $out ` + |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 87 | `apex_payload.img:apex/${abi}.img ` + |
| 88 | `apex_manifest.json:root/apex_manifest.json ` + |
Shahar Amitai | 328b077 | 2018-11-26 14:12:02 +0000 | [diff] [blame] | 89 | `AndroidManifest.xml:manifest/AndroidManifest.xml`, |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 90 | CommandDeps: []string{"${zip2zip}"}, |
| 91 | Description: "app bundle", |
| 92 | }, "abi") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 93 | ) |
| 94 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 95 | var imageApexSuffix = ".apex" |
| 96 | var zipApexSuffix = ".zipapex" |
| 97 | |
| 98 | var imageApexType = "image" |
| 99 | var zipApexType = "zip" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 100 | |
| 101 | type dependencyTag struct { |
| 102 | blueprint.BaseDependencyTag |
| 103 | name string |
| 104 | } |
| 105 | |
| 106 | var ( |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 107 | sharedLibTag = dependencyTag{name: "sharedLib"} |
| 108 | executableTag = dependencyTag{name: "executable"} |
| 109 | javaLibTag = dependencyTag{name: "javaLib"} |
| 110 | prebuiltTag = dependencyTag{name: "prebuilt"} |
| 111 | keyTag = dependencyTag{name: "key"} |
| 112 | certificateTag = dependencyTag{name: "certificate"} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 113 | ) |
| 114 | |
| 115 | func init() { |
| 116 | pctx.Import("android/soong/common") |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 117 | pctx.Import("android/soong/java") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 118 | pctx.HostBinToolVariable("apexer", "apexer") |
Roland Levillain | 54bdfda | 2018-10-05 19:34:32 +0100 | [diff] [blame] | 119 | // ART minimal builds (using the master-art manifest) do not have the "frameworks/base" |
| 120 | // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead. |
| 121 | hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) { |
| 122 | pctx.VariableFunc(name, func(ctx android.PackageVarContext) string { |
David Brazdil | 91b4e3e | 2019-01-23 21:04:05 +0000 | [diff] [blame] | 123 | if !ctx.Config().FrameworksBaseDirExists(ctx) { |
Roland Levillain | 54bdfda | 2018-10-05 19:34:32 +0100 | [diff] [blame] | 124 | return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool) |
| 125 | } else { |
| 126 | return pctx.HostBinToolPath(ctx, tool).String() |
| 127 | } |
| 128 | }) |
| 129 | } |
| 130 | hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 131 | pctx.HostBinToolVariable("avbtool", "avbtool") |
| 132 | pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid") |
| 133 | pctx.HostBinToolVariable("merge_zips", "merge_zips") |
| 134 | pctx.HostBinToolVariable("mke2fs", "mke2fs") |
| 135 | pctx.HostBinToolVariable("resize2fs", "resize2fs") |
| 136 | pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile") |
| 137 | pctx.HostBinToolVariable("soong_zip", "soong_zip") |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 138 | pctx.HostBinToolVariable("zip2zip", "zip2zip") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 139 | pctx.HostBinToolVariable("zipalign", "zipalign") |
| 140 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 141 | android.RegisterModuleType("apex", apexBundleFactory) |
| 142 | android.RegisterModuleType("apex_test", testApexBundleFactory) |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 143 | android.RegisterModuleType("apex_defaults", defaultsFactory) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 144 | |
| 145 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 146 | ctx.TopDown("apex_deps", apexDepsMutator) |
| 147 | ctx.BottomUp("apex", apexMutator) |
| 148 | }) |
| 149 | } |
| 150 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 151 | // Mark the direct and transitive dependencies of apex bundles so that they |
| 152 | // can be built for the apex bundles. |
| 153 | func apexDepsMutator(mctx android.TopDownMutatorContext) { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 154 | if a, ok := mctx.Module().(*apexBundle); ok { |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 155 | apexBundleName := mctx.ModuleName() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 156 | mctx.WalkDeps(func(child, parent android.Module) bool { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 157 | depName := mctx.OtherModuleName(child) |
| 158 | // If the parent is apexBundle, this child is directly depended. |
| 159 | _, directDep := parent.(*apexBundle) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 160 | if a.installable() && !a.testApex { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 161 | // TODO(b/123892969): Workaround for not having any way to annotate test-apexs |
| 162 | // non-installable apex's cannot be installed and so should not prevent libraries from being |
| 163 | // installed to the system. |
| 164 | android.UpdateApexDependency(apexBundleName, depName, directDep) |
| 165 | } |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 166 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 167 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 168 | am.BuildForApex(apexBundleName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 169 | return true |
| 170 | } else { |
| 171 | return false |
| 172 | } |
| 173 | }) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // Create apex variations if a module is included in APEX(s). |
| 178 | func apexMutator(mctx android.BottomUpMutatorContext) { |
| 179 | if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 180 | am.CreateApexVariations(mctx) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 181 | } else if _, ok := mctx.Module().(*apexBundle); ok { |
| 182 | // apex bundle itself is mutated so that it and its modules have same |
| 183 | // apex variant. |
| 184 | apexBundleName := mctx.ModuleName() |
| 185 | mctx.CreateVariations(apexBundleName) |
| 186 | } |
| 187 | } |
| 188 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 189 | type apexNativeDependencies struct { |
| 190 | // List of native libraries |
| 191 | Native_shared_libs []string |
| 192 | // List of native executables |
| 193 | Binaries []string |
| 194 | } |
| 195 | type apexMultilibProperties struct { |
| 196 | // Native dependencies whose compile_multilib is "first" |
| 197 | First apexNativeDependencies |
| 198 | |
| 199 | // Native dependencies whose compile_multilib is "both" |
| 200 | Both apexNativeDependencies |
| 201 | |
| 202 | // Native dependencies whose compile_multilib is "prefer32" |
| 203 | Prefer32 apexNativeDependencies |
| 204 | |
| 205 | // Native dependencies whose compile_multilib is "32" |
| 206 | Lib32 apexNativeDependencies |
| 207 | |
| 208 | // Native dependencies whose compile_multilib is "64" |
| 209 | Lib64 apexNativeDependencies |
| 210 | } |
| 211 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 212 | type apexBundleProperties struct { |
| 213 | // Json manifest file describing meta info of this APEX bundle. Default: |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 214 | // "apex_manifest.json" |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 215 | Manifest *string `android:"path"` |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 216 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 217 | // AndroidManifest.xml file used for the zip container of this APEX bundle. |
| 218 | // If unspecified, a default one is automatically generated. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 219 | AndroidManifest *string `android:"path"` |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 220 | |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 221 | // Canonical name of the APEX bundle in the manifest file. |
| 222 | // If unspecified, defaults to the value of name |
| 223 | Apex_name *string |
| 224 | |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 225 | // Determines the file contexts file for setting security context to each file in this APEX bundle. |
| 226 | // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is |
| 227 | // used. |
| 228 | // Default: <name_of_this_module> |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 229 | File_contexts *string |
| 230 | |
| 231 | // List of native shared libs that are embedded inside this APEX bundle |
| 232 | Native_shared_libs []string |
| 233 | |
| 234 | // List of native executables that are embedded inside this APEX bundle |
| 235 | Binaries []string |
| 236 | |
| 237 | // List of java libraries that are embedded inside this APEX bundle |
| 238 | Java_libs []string |
| 239 | |
| 240 | // List of prebuilt files that are embedded inside this APEX bundle |
| 241 | Prebuilts []string |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 242 | |
| 243 | // Name of the apex_key module that provides the private key to sign APEX |
| 244 | Key *string |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 245 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 246 | // The type of APEX to build. Controls what the APEX payload is. Either |
| 247 | // 'image', 'zip' or 'both'. Default: 'image'. |
| 248 | Payload_type *string |
| 249 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 250 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 251 | // or an android_app_certificate module name in the form ":module". |
| 252 | Certificate *string |
| 253 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 254 | // Whether this APEX is installable to one of the partitions. Default: true. |
| 255 | Installable *bool |
| 256 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 257 | // For native libraries and binaries, use the vendor variant instead of the core (platform) variant. |
| 258 | // Default is false. |
| 259 | Use_vendor *bool |
| 260 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 261 | // For telling the apex to ignore special handling for system libraries such as bionic. Default is false. |
| 262 | Ignore_system_library_special_case *bool |
| 263 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 264 | Multilib apexMultilibProperties |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 265 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 266 | // List of sanitizer names that this APEX is enabled for |
| 267 | SanitizerNames []string `blueprint:"mutated"` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | type apexTargetBundleProperties struct { |
| 271 | Target struct { |
| 272 | // Multilib properties only for android. |
| 273 | Android struct { |
| 274 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 275 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 276 | // Multilib properties only for host. |
| 277 | Host struct { |
| 278 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 279 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 280 | // Multilib properties only for host linux_bionic. |
| 281 | Linux_bionic struct { |
| 282 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 283 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 284 | // Multilib properties only for host linux_glibc. |
| 285 | Linux_glibc struct { |
| 286 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 287 | } |
| 288 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 289 | } |
| 290 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 291 | type apexFileClass int |
| 292 | |
| 293 | const ( |
| 294 | etc apexFileClass = iota |
| 295 | nativeSharedLib |
| 296 | nativeExecutable |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 297 | shBinary |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 298 | pyBinary |
| 299 | goBinary |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 300 | javaSharedLib |
| 301 | ) |
| 302 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 303 | type apexPackaging int |
| 304 | |
| 305 | const ( |
| 306 | imageApex apexPackaging = iota |
| 307 | zipApex |
| 308 | both |
| 309 | ) |
| 310 | |
| 311 | func (a apexPackaging) image() bool { |
| 312 | switch a { |
| 313 | case imageApex, both: |
| 314 | return true |
| 315 | } |
| 316 | return false |
| 317 | } |
| 318 | |
| 319 | func (a apexPackaging) zip() bool { |
| 320 | switch a { |
| 321 | case zipApex, both: |
| 322 | return true |
| 323 | } |
| 324 | return false |
| 325 | } |
| 326 | |
| 327 | func (a apexPackaging) suffix() string { |
| 328 | switch a { |
| 329 | case imageApex: |
| 330 | return imageApexSuffix |
| 331 | case zipApex: |
| 332 | return zipApexSuffix |
| 333 | case both: |
| 334 | panic(fmt.Errorf("must be either zip or image")) |
| 335 | default: |
| 336 | panic(fmt.Errorf("unkonwn APEX type %d", a)) |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | func (a apexPackaging) name() string { |
| 341 | switch a { |
| 342 | case imageApex: |
| 343 | return imageApexType |
| 344 | case zipApex: |
| 345 | return zipApexType |
| 346 | case both: |
| 347 | panic(fmt.Errorf("must be either zip or image")) |
| 348 | default: |
| 349 | panic(fmt.Errorf("unkonwn APEX type %d", a)) |
| 350 | } |
| 351 | } |
| 352 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 353 | func (class apexFileClass) NameInMake() string { |
| 354 | switch class { |
| 355 | case etc: |
| 356 | return "ETC" |
| 357 | case nativeSharedLib: |
| 358 | return "SHARED_LIBRARIES" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 359 | case nativeExecutable, shBinary, pyBinary, goBinary: |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 360 | return "EXECUTABLES" |
| 361 | case javaSharedLib: |
| 362 | return "JAVA_LIBRARIES" |
| 363 | default: |
| 364 | panic(fmt.Errorf("unkonwn class %d", class)) |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | type apexFile struct { |
| 369 | builtFile android.Path |
| 370 | moduleName string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 371 | installDir string |
| 372 | class apexFileClass |
Jiyong Park | a889484 | 2018-12-19 17:36:39 +0900 | [diff] [blame] | 373 | module android.Module |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 374 | symlinks []string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 375 | } |
| 376 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 377 | type apexBundle struct { |
| 378 | android.ModuleBase |
| 379 | android.DefaultableModuleBase |
| 380 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 381 | properties apexBundleProperties |
| 382 | targetProperties apexTargetBundleProperties |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 383 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 384 | apexTypes apexPackaging |
| 385 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 386 | bundleModuleFile android.WritablePath |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 387 | outputFiles map[apexPackaging]android.WritablePath |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 388 | installDir android.OutputPath |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 389 | |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 390 | public_key_file android.Path |
| 391 | private_key_file android.Path |
| 392 | bundle_public_key bool |
| 393 | |
| 394 | container_certificate_file android.Path |
| 395 | container_private_key_file android.Path |
| 396 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 397 | // list of files to be included in this apex |
| 398 | filesInfo []apexFile |
| 399 | |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 400 | // list of module names that this APEX is depending on |
| 401 | externalDeps []string |
| 402 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 403 | flattened bool |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 404 | |
| 405 | testApex bool |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 406 | } |
| 407 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 408 | func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 409 | native_shared_libs []string, binaries []string, arch string, imageVariation string) { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 410 | // Use *FarVariation* to be able to depend on modules having |
| 411 | // conflicting variations with this module. This is required since |
| 412 | // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64' |
| 413 | // for native shared libs. |
| 414 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 415 | {Mutator: "arch", Variation: arch}, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 416 | {Mutator: "image", Variation: imageVariation}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 417 | {Mutator: "link", Variation: "shared"}, |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 418 | {Mutator: "version", Variation: ""}, // "" is the non-stub variant |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 419 | }, sharedLibTag, native_shared_libs...) |
| 420 | |
| 421 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 422 | {Mutator: "arch", Variation: arch}, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 423 | {Mutator: "image", Variation: imageVariation}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 424 | }, executableTag, binaries...) |
| 425 | } |
| 426 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 427 | func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { |
| 428 | if ctx.Os().Class == android.Device { |
| 429 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil) |
| 430 | } else { |
| 431 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil) |
| 432 | if ctx.Os().Bionic() { |
| 433 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil) |
| 434 | } else { |
| 435 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil) |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 440 | func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 441 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 442 | targets := ctx.MultiTargets() |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 443 | config := ctx.DeviceConfig() |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 444 | |
| 445 | a.combineProperties(ctx) |
| 446 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 447 | has32BitTarget := false |
| 448 | for _, target := range targets { |
| 449 | if target.Arch.ArchType.Multilib == "lib32" { |
| 450 | has32BitTarget = true |
| 451 | } |
| 452 | } |
| 453 | for i, target := range targets { |
| 454 | // When multilib.* is omitted for native_shared_libs, it implies |
| 455 | // multilib.both. |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 456 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 457 | {Mutator: "arch", Variation: target.String()}, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 458 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 459 | {Mutator: "link", Variation: "shared"}, |
| 460 | }, sharedLibTag, a.properties.Native_shared_libs...) |
| 461 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 462 | // Add native modules targetting both ABIs |
| 463 | addDependenciesForNativeModules(ctx, |
| 464 | a.properties.Multilib.Both.Native_shared_libs, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 465 | a.properties.Multilib.Both.Binaries, target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 466 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 467 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 468 | isPrimaryAbi := i == 0 |
| 469 | if isPrimaryAbi { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 470 | // When multilib.* is omitted for binaries, it implies |
| 471 | // multilib.first. |
| 472 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 473 | {Mutator: "arch", Variation: target.String()}, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 474 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 475 | }, executableTag, a.properties.Binaries...) |
| 476 | |
| 477 | // Add native modules targetting the first ABI |
| 478 | addDependenciesForNativeModules(ctx, |
| 479 | a.properties.Multilib.First.Native_shared_libs, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 480 | a.properties.Multilib.First.Binaries, target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 481 | a.getImageVariation(config)) |
Jaewoong Jung | b9a1151 | 2019-01-15 10:47:05 -0800 | [diff] [blame] | 482 | |
| 483 | // When multilib.* is omitted for prebuilts, it implies multilib.first. |
| 484 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 485 | {Mutator: "arch", Variation: target.String()}, |
| 486 | }, prebuiltTag, a.properties.Prebuilts...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | switch target.Arch.ArchType.Multilib { |
| 490 | case "lib32": |
| 491 | // Add native modules targetting 32-bit ABI |
| 492 | addDependenciesForNativeModules(ctx, |
| 493 | a.properties.Multilib.Lib32.Native_shared_libs, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 494 | a.properties.Multilib.Lib32.Binaries, target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 495 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 496 | |
| 497 | addDependenciesForNativeModules(ctx, |
| 498 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 499 | a.properties.Multilib.Prefer32.Binaries, target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 500 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 501 | case "lib64": |
| 502 | // Add native modules targetting 64-bit ABI |
| 503 | addDependenciesForNativeModules(ctx, |
| 504 | a.properties.Multilib.Lib64.Native_shared_libs, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 505 | a.properties.Multilib.Lib64.Binaries, target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 506 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 507 | |
| 508 | if !has32BitTarget { |
| 509 | addDependenciesForNativeModules(ctx, |
| 510 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 511 | a.properties.Multilib.Prefer32.Binaries, target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 512 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 516 | } |
| 517 | |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 518 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 519 | {Mutator: "arch", Variation: "android_common"}, |
| 520 | }, javaLibTag, a.properties.Java_libs...) |
| 521 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 522 | if String(a.properties.Key) == "" { |
| 523 | ctx.ModuleErrorf("key is missing") |
| 524 | return |
| 525 | } |
| 526 | ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key)) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 527 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 528 | cert := android.SrcIsModule(a.getCertString(ctx)) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 529 | if cert != "" { |
| 530 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 531 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 532 | } |
| 533 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 534 | func (a *apexBundle) getCertString(ctx android.BaseContext) string { |
| 535 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName()) |
| 536 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 537 | return ":" + certificate |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 538 | } |
| 539 | return String(a.properties.Certificate) |
| 540 | } |
| 541 | |
Jiyong Park | 74e240b | 2018-11-27 21:27:08 +0900 | [diff] [blame] | 542 | func (a *apexBundle) Srcs() android.Paths { |
Jiyong Park | 5a83202 | 2018-12-20 09:54:35 +0900 | [diff] [blame] | 543 | if file, ok := a.outputFiles[imageApex]; ok { |
| 544 | return android.Paths{file} |
| 545 | } else { |
| 546 | return nil |
| 547 | } |
Jiyong Park | 74e240b | 2018-11-27 21:27:08 +0900 | [diff] [blame] | 548 | } |
| 549 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 550 | func (a *apexBundle) installable() bool { |
| 551 | return a.properties.Installable == nil || proptools.Bool(a.properties.Installable) |
| 552 | } |
| 553 | |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 554 | func (a *apexBundle) getImageVariation(config android.DeviceConfig) string { |
| 555 | if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 556 | return "vendor" |
| 557 | } else { |
| 558 | return "core" |
| 559 | } |
| 560 | } |
| 561 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 562 | func (a *apexBundle) EnableSanitizer(sanitizerName string) { |
| 563 | if !android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 564 | a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName) |
| 565 | } |
| 566 | } |
| 567 | |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 568 | func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool { |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 569 | if android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 570 | return true |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | // Then follow the global setting |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 574 | globalSanitizerNames := []string{} |
| 575 | if a.Host() { |
| 576 | globalSanitizerNames = ctx.Config().SanitizeHost() |
| 577 | } else { |
| 578 | arches := ctx.Config().SanitizeDeviceArch() |
| 579 | if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) { |
| 580 | globalSanitizerNames = ctx.Config().SanitizeDevice() |
| 581 | } |
| 582 | } |
| 583 | return android.InList(sanitizerName, globalSanitizerNames) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 584 | } |
| 585 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 586 | func getCopyManifestForNativeLibrary(cc *cc.Module, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 587 | // Decide the APEX-local directory by the multilib of the library |
| 588 | // In the future, we may query this to the module. |
| 589 | switch cc.Arch().ArchType.Multilib { |
| 590 | case "lib32": |
| 591 | dirInApex = "lib" |
| 592 | case "lib64": |
| 593 | dirInApex = "lib64" |
| 594 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 595 | dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath()) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 596 | if !cc.Arch().Native { |
| 597 | dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String()) |
| 598 | } |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 599 | if handleSpecialLibs { |
| 600 | switch cc.Name() { |
| 601 | case "libc", "libm", "libdl": |
| 602 | // Special case for bionic libs. This is to prevent the bionic libs |
| 603 | // from being included in the search path /apex/com.android.apex/lib. |
| 604 | // This exclusion is required because bionic libs in the runtime APEX |
| 605 | // are available via the legacy paths /system/lib/libc.so, etc. By the |
| 606 | // init process, the bionic libs in the APEX are bind-mounted to the |
| 607 | // legacy paths and thus will be loaded into the default linker namespace. |
| 608 | // If the bionic libs are directly in /apex/com.android.apex/lib then |
| 609 | // the same libs will be again loaded to the runtime linker namespace, |
| 610 | // which will result double loading of bionic libs that isn't supported. |
| 611 | dirInApex = filepath.Join(dirInApex, "bionic") |
| 612 | } |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 613 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 614 | |
| 615 | fileToCopy = cc.OutputFile().Path() |
| 616 | return |
| 617 | } |
| 618 | |
| 619 | func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 620 | dirInApex = filepath.Join("bin", cc.RelativeInstallPath()) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 621 | fileToCopy = cc.OutputFile().Path() |
| 622 | return |
| 623 | } |
| 624 | |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 625 | func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) { |
| 626 | dirInApex = "bin" |
| 627 | fileToCopy = py.HostToolPath().Path() |
| 628 | return |
| 629 | } |
| 630 | func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) { |
| 631 | dirInApex = "bin" |
| 632 | s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath()) |
| 633 | if err != nil { |
| 634 | ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath()) |
| 635 | return |
| 636 | } |
| 637 | fileToCopy = android.PathForOutput(ctx, s) |
| 638 | return |
| 639 | } |
| 640 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 641 | func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) { |
| 642 | dirInApex = filepath.Join("bin", sh.SubDir()) |
| 643 | fileToCopy = sh.OutputFile() |
| 644 | return |
| 645 | } |
| 646 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 647 | func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) { |
| 648 | dirInApex = "javalib" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 649 | fileToCopy = java.DexJarFile() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 650 | return |
| 651 | } |
| 652 | |
| 653 | func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) { |
| 654 | dirInApex = filepath.Join("etc", prebuilt.SubDir()) |
| 655 | fileToCopy = prebuilt.OutputFile() |
| 656 | return |
| 657 | } |
| 658 | |
| 659 | func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 660 | filesInfo := []apexFile{} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 661 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 662 | if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" { |
| 663 | a.apexTypes = imageApex |
| 664 | } else if *a.properties.Payload_type == "zip" { |
| 665 | a.apexTypes = zipApex |
| 666 | } else if *a.properties.Payload_type == "both" { |
| 667 | a.apexTypes = both |
| 668 | } else { |
| 669 | ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type) |
| 670 | return |
| 671 | } |
| 672 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 673 | handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case) |
| 674 | |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 675 | ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 676 | if _, ok := parent.(*apexBundle); ok { |
| 677 | // direct dependencies |
| 678 | depTag := ctx.OtherModuleDependencyTag(child) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 679 | depName := ctx.OtherModuleName(child) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 680 | switch depTag { |
| 681 | case sharedLibTag: |
| 682 | if cc, ok := child.(*cc.Module); ok { |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 683 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 684 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 685 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 686 | } else { |
| 687 | 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] | 688 | } |
| 689 | case executableTag: |
| 690 | if cc, ok := child.(*cc.Module); ok { |
Alex Light | 16df4e8 | 2019-01-24 11:37:55 -0800 | [diff] [blame] | 691 | if !cc.Arch().Native { |
| 692 | // There is only one 'bin' directory so we shouldn't bother copying in |
| 693 | // native-bridge'd binaries and only use main ones. |
| 694 | return true |
| 695 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 696 | fileToCopy, dirInApex := getCopyManifestForExecutable(cc) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 697 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 698 | return true |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 699 | } else if sh, ok := child.(*android.ShBinary); ok { |
| 700 | fileToCopy, dirInApex := getCopyManifestForShBinary(sh) |
| 701 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil}) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 702 | } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() { |
| 703 | fileToCopy, dirInApex := getCopyManifestForPyBinary(py) |
| 704 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil}) |
| 705 | } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() { |
| 706 | fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb) |
| 707 | // NB: Since go binaries are static we don't need the module for anything here, which is |
| 708 | // good since the go tool is a blueprint.Module not an android.Module like we would |
| 709 | // normally use. |
| 710 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil}) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 711 | } else { |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 712 | 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] | 713 | } |
| 714 | case javaLibTag: |
| 715 | if java, ok := child.(*java.Library); ok { |
| 716 | fileToCopy, dirInApex := getCopyManifestForJavaLibrary(java) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 717 | if fileToCopy == nil { |
| 718 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 719 | } else { |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 720 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, java, nil}) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 721 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 722 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 723 | } else { |
| 724 | ctx.PropertyErrorf("java_libs", "%q is not a java_library module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 725 | } |
| 726 | case prebuiltTag: |
| 727 | if prebuilt, ok := child.(*android.PrebuiltEtc); ok { |
| 728 | fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 729 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 730 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 731 | } else { |
| 732 | ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName) |
| 733 | } |
| 734 | case keyTag: |
| 735 | if key, ok := child.(*apexKey); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 736 | a.private_key_file = key.private_key_file |
| 737 | a.public_key_file = key.public_key_file |
| 738 | // If the key is not installed, bundled it with the APEX. |
| 739 | // Note: this bundled key is valid only for non-production builds |
| 740 | // (eng/userdebug). |
| 741 | a.bundle_public_key = !key.installable() && ctx.Config().Debuggable() |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 742 | return false |
| 743 | } else { |
| 744 | ctx.PropertyErrorf("key", "%q is not an apex_key module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 745 | } |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 746 | case certificateTag: |
| 747 | if dep, ok := child.(*java.AndroidAppCertificate); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 748 | a.container_certificate_file = dep.Certificate.Pem |
| 749 | a.container_private_key_file = dep.Certificate.Key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 750 | return false |
| 751 | } else { |
| 752 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName) |
| 753 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 754 | } |
| 755 | } else { |
| 756 | // indirect dependencies |
| 757 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && am.IsInstallableToApex() { |
| 758 | if cc, ok := child.(*cc.Module); ok { |
Alex Light | 49ae3d9 | 2019-02-21 14:02:46 -0800 | [diff] [blame] | 759 | if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) { |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 760 | // If the dependency is a stubs lib, don't include it in this APEX, |
| 761 | // but make sure that the lib is installed on the device. |
| 762 | // In case no APEX is having the lib, the lib is installed to the system |
| 763 | // partition. |
Alex Light | 49ae3d9 | 2019-02-21 14:02:46 -0800 | [diff] [blame] | 764 | // |
| 765 | // Always include if we are a host-apex however since those won't have any |
| 766 | // system libraries. |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 767 | if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) { |
| 768 | a.externalDeps = append(a.externalDeps, cc.Name()) |
| 769 | } |
| 770 | // Don't track further |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 771 | return false |
| 772 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 773 | depName := ctx.OtherModuleName(child) |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 774 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 775 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 776 | return true |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | return false |
| 781 | }) |
| 782 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 783 | a.flattened = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild() |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 784 | if a.private_key_file == nil { |
Jiyong Park | fa0a373 | 2018-11-09 05:52:26 +0900 | [diff] [blame] | 785 | ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key)) |
| 786 | return |
| 787 | } |
| 788 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 789 | // remove duplicates in filesInfo |
| 790 | removeDup := func(filesInfo []apexFile) []apexFile { |
| 791 | encountered := make(map[android.Path]bool) |
| 792 | result := []apexFile{} |
| 793 | for _, f := range filesInfo { |
| 794 | if !encountered[f.builtFile] { |
| 795 | encountered[f.builtFile] = true |
| 796 | result = append(result, f) |
| 797 | } |
| 798 | } |
| 799 | return result |
| 800 | } |
| 801 | filesInfo = removeDup(filesInfo) |
| 802 | |
| 803 | // to have consistent build rules |
| 804 | sort.Slice(filesInfo, func(i, j int) bool { |
| 805 | return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String() |
| 806 | }) |
| 807 | |
| 808 | // prepend the name of this APEX to the module names. These names will be the names of |
| 809 | // modules that will be defined if the APEX is flattened. |
| 810 | for i := range filesInfo { |
| 811 | filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName |
| 812 | } |
| 813 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 814 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 815 | a.filesInfo = filesInfo |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 816 | |
| 817 | if a.apexTypes.zip() { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 818 | a.buildUnflattenedApex(ctx, zipApex) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 819 | } |
| 820 | if a.apexTypes.image() { |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 821 | // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex() |
| 822 | // is true. This is to support referencing APEX via ":<module_name" syntax |
| 823 | // in other modules. It is in AndroidMk where the selection of flattened |
| 824 | // or unflattened APEX is made. |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 825 | a.buildUnflattenedApex(ctx, imageApex) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 826 | a.buildFlattenedApex(ctx) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 827 | } |
| 828 | } |
| 829 | |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 830 | func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) { |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 831 | cert := String(a.properties.Certificate) |
| 832 | if cert != "" && android.SrcIsModule(cert) == "" { |
| 833 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 834 | a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem") |
| 835 | a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8") |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 836 | } else if cert == "" { |
| 837 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 838 | a.container_certificate_file = pem |
| 839 | a.container_private_key_file = key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 840 | } |
| 841 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame^] | 842 | manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 843 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 844 | var abis []string |
| 845 | for _, target := range ctx.MultiTargets() { |
| 846 | if len(target.Arch.Abi) > 0 { |
| 847 | abis = append(abis, target.Arch.Abi[0]) |
| 848 | } |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 849 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 850 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 851 | abis = android.FirstUniqueStrings(abis) |
| 852 | |
| 853 | suffix := apexType.suffix() |
| 854 | unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 855 | |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 856 | filesToCopy := []android.Path{} |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 857 | for _, f := range a.filesInfo { |
| 858 | filesToCopy = append(filesToCopy, f.builtFile) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 859 | } |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 860 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 861 | copyCommands := []string{} |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 862 | for i, src := range filesToCopy { |
| 863 | dest := filepath.Join(a.filesInfo[i].installDir, src.Base()) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 864 | dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 865 | copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path)) |
| 866 | copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 867 | for _, sym := range a.filesInfo[i].symlinks { |
| 868 | symlinkDest := filepath.Join(filepath.Dir(dest_path), sym) |
| 869 | copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest) |
| 870 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 871 | } |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 872 | implicitInputs := append(android.Paths(nil), filesToCopy...) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 873 | implicitInputs = append(implicitInputs, manifest) |
| 874 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 875 | outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String() |
| 876 | prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 877 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 878 | if apexType.image() { |
| 879 | // files and dirs that will be created in APEX |
| 880 | var readOnlyPaths []string |
| 881 | var executablePaths []string // this also includes dirs |
| 882 | for _, f := range a.filesInfo { |
| 883 | pathInApex := filepath.Join(f.installDir, f.builtFile.Base()) |
| 884 | if f.installDir == "bin" { |
| 885 | executablePaths = append(executablePaths, pathInApex) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 886 | for _, s := range f.symlinks { |
| 887 | executablePaths = append(executablePaths, filepath.Join("bin", s)) |
| 888 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 889 | } else { |
| 890 | readOnlyPaths = append(readOnlyPaths, pathInApex) |
| 891 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 892 | dir := f.installDir |
| 893 | for !android.InList(dir, executablePaths) && dir != "" { |
| 894 | executablePaths = append(executablePaths, dir) |
| 895 | dir, _ = filepath.Split(dir) // move up to the parent |
| 896 | if len(dir) > 0 { |
| 897 | // remove trailing slash |
| 898 | dir = dir[:len(dir)-1] |
| 899 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 900 | } |
| 901 | } |
| 902 | sort.Strings(readOnlyPaths) |
| 903 | sort.Strings(executablePaths) |
| 904 | cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config") |
| 905 | ctx.Build(pctx, android.BuildParams{ |
| 906 | Rule: generateFsConfig, |
| 907 | Output: cannedFsConfig, |
| 908 | Description: "generate fs config", |
| 909 | Args: map[string]string{ |
| 910 | "ro_paths": strings.Join(readOnlyPaths, " "), |
| 911 | "exec_paths": strings.Join(executablePaths, " "), |
| 912 | }, |
| 913 | }) |
| 914 | |
| 915 | fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName()) |
| 916 | fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts" |
| 917 | fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath) |
| 918 | if !fileContextsOptionalPath.Valid() { |
| 919 | ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath) |
| 920 | return |
| 921 | } |
| 922 | fileContexts := fileContextsOptionalPath.Path() |
| 923 | |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 924 | optFlags := []string{} |
| 925 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 926 | // Additional implicit inputs. |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 927 | implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file) |
| 928 | if a.bundle_public_key { |
| 929 | implicitInputs = append(implicitInputs, a.public_key_file) |
| 930 | optFlags = append(optFlags, "--pubkey "+a.public_key_file.String()) |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 931 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 932 | |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 933 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
| 934 | if overridden { |
| 935 | optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName) |
| 936 | } |
| 937 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 938 | if a.properties.AndroidManifest != nil { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame^] | 939 | androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest)) |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 940 | implicitInputs = append(implicitInputs, androidManifestFile) |
| 941 | optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String()) |
| 942 | } |
| 943 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 944 | ctx.Build(pctx, android.BuildParams{ |
| 945 | Rule: apexRule, |
| 946 | Implicits: implicitInputs, |
| 947 | Output: unsignedOutputFile, |
| 948 | Description: "apex (" + apexType.name() + ")", |
| 949 | Args: map[string]string{ |
| 950 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
| 951 | "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(), |
| 952 | "copy_commands": strings.Join(copyCommands, " && "), |
| 953 | "manifest": manifest.String(), |
| 954 | "file_contexts": fileContexts.String(), |
| 955 | "canned_fs_config": cannedFsConfig.String(), |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 956 | "key": a.private_key_file.String(), |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 957 | "opt_flags": strings.Join(optFlags, " "), |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 958 | }, |
| 959 | }) |
| 960 | |
| 961 | apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix) |
| 962 | bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip") |
| 963 | a.bundleModuleFile = bundleModuleFile |
| 964 | |
| 965 | ctx.Build(pctx, android.BuildParams{ |
| 966 | Rule: apexProtoConvertRule, |
| 967 | Input: unsignedOutputFile, |
| 968 | Output: apexProtoFile, |
| 969 | Description: "apex proto convert", |
| 970 | }) |
| 971 | |
| 972 | ctx.Build(pctx, android.BuildParams{ |
| 973 | Rule: apexBundleRule, |
| 974 | Input: apexProtoFile, |
| 975 | Output: a.bundleModuleFile, |
| 976 | Description: "apex bundle module", |
| 977 | Args: map[string]string{ |
| 978 | "abi": strings.Join(abis, "."), |
| 979 | }, |
| 980 | }) |
| 981 | } else { |
| 982 | ctx.Build(pctx, android.BuildParams{ |
| 983 | Rule: zipApexRule, |
| 984 | Implicits: implicitInputs, |
| 985 | Output: unsignedOutputFile, |
| 986 | Description: "apex (" + apexType.name() + ")", |
| 987 | Args: map[string]string{ |
| 988 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
| 989 | "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(), |
| 990 | "copy_commands": strings.Join(copyCommands, " && "), |
| 991 | "manifest": manifest.String(), |
| 992 | }, |
| 993 | }) |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 994 | } |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 995 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 996 | a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 997 | ctx.Build(pctx, android.BuildParams{ |
| 998 | Rule: java.Signapk, |
| 999 | Description: "signapk", |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1000 | Output: a.outputFiles[apexType], |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1001 | Input: unsignedOutputFile, |
| 1002 | Args: map[string]string{ |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1003 | "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(), |
Jiyong Park | bfe64a1 | 2018-11-22 02:51:54 +0900 | [diff] [blame] | 1004 | "flags": "-a 4096", //alignment |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1005 | }, |
| 1006 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1007 | |
| 1008 | // Install to $OUT/soong/{target,host}/.../apex |
Alex Light | 2a2561f | 2019-02-12 16:59:09 -0800 | [diff] [blame] | 1009 | if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1010 | ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType]) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1011 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1012 | } |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1013 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1014 | func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1015 | if a.installable() { |
| 1016 | // For flattened APEX, do nothing but make sure that apex_manifest.json file is also copied along |
| 1017 | // with other ordinary files. |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame^] | 1018 | manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) |
Jiyong Park | d699cb9 | 2019-01-10 00:23:16 +0900 | [diff] [blame] | 1019 | |
| 1020 | // rename to apex_manifest.json |
| 1021 | copiedManifest := android.PathForModuleOut(ctx, "apex_manifest.json") |
| 1022 | ctx.Build(pctx, android.BuildParams{ |
| 1023 | Rule: android.Cp, |
| 1024 | Input: manifest, |
| 1025 | Output: copiedManifest, |
| 1026 | }) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1027 | a.filesInfo = append(a.filesInfo, apexFile{copiedManifest, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil}) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1028 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1029 | if ctx.Config().FlattenApex() { |
| 1030 | for _, fi := range a.filesInfo { |
| 1031 | dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir) |
Alex Light | f4857cf | 2019-02-22 13:00:04 -0800 | [diff] [blame] | 1032 | target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile) |
| 1033 | for _, sym := range fi.symlinks { |
| 1034 | ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target) |
| 1035 | } |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1036 | } |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1037 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1038 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | func (a *apexBundle) AndroidMk() android.AndroidMkData { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1042 | writers := []android.AndroidMkData{} |
| 1043 | if a.apexTypes.image() { |
| 1044 | writers = append(writers, a.androidMkForType(imageApex)) |
| 1045 | } |
| 1046 | if a.apexTypes.zip() { |
| 1047 | writers = append(writers, a.androidMkForType(zipApex)) |
| 1048 | } |
| 1049 | return android.AndroidMkData{ |
| 1050 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 1051 | for _, data := range writers { |
| 1052 | data.Custom(w, name, prefix, moduleDir, data) |
| 1053 | } |
| 1054 | }} |
| 1055 | } |
| 1056 | |
Alex Light | f1801bc | 2019-02-13 11:10:07 -0800 | [diff] [blame] | 1057 | 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] | 1058 | moduleNames := []string{} |
| 1059 | |
| 1060 | for _, fi := range a.filesInfo { |
| 1061 | if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake { |
| 1062 | continue |
| 1063 | } |
| 1064 | if !android.InList(fi.moduleName, moduleNames) { |
| 1065 | moduleNames = append(moduleNames, fi.moduleName) |
| 1066 | } |
| 1067 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1068 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 1069 | fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName) |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1070 | // /apex/<name>/{lib|framework|...} |
| 1071 | pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", |
| 1072 | proptools.StringDefault(a.properties.Apex_name, name), fi.installDir) |
Alex Light | f1801bc | 2019-02-13 11:10:07 -0800 | [diff] [blame] | 1073 | if a.flattened && apexType.image() { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1074 | // /system/apex/<name>/{lib|framework|...} |
| 1075 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", |
| 1076 | a.installDir.RelPathString(), name, fi.installDir)) |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1077 | fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated) |
Alex Light | f4857cf | 2019-02-22 13:00:04 -0800 | [diff] [blame] | 1078 | if len(fi.symlinks) > 0 { |
| 1079 | fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " ")) |
| 1080 | } |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1081 | } else { |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1082 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1083 | } |
| 1084 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String()) |
| 1085 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake()) |
| 1086 | if fi.module != nil { |
| 1087 | archStr := fi.module.Target().Arch.ArchType.String() |
| 1088 | host := false |
| 1089 | switch fi.module.Target().Os.Class { |
| 1090 | case android.Host: |
| 1091 | if archStr != "common" { |
| 1092 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) |
| 1093 | } |
| 1094 | host = true |
| 1095 | case android.HostCross: |
| 1096 | if archStr != "common" { |
| 1097 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) |
| 1098 | } |
| 1099 | host = true |
| 1100 | case android.Device: |
| 1101 | if archStr != "common" { |
| 1102 | fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr) |
| 1103 | } |
| 1104 | } |
| 1105 | if host { |
| 1106 | makeOs := fi.module.Target().Os.String() |
| 1107 | if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic { |
| 1108 | makeOs = "linux" |
| 1109 | } |
| 1110 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs) |
| 1111 | fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") |
| 1112 | } |
| 1113 | } |
| 1114 | if fi.class == javaSharedLib { |
| 1115 | javaModule := fi.module.(*java.Library) |
| 1116 | // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore |
| 1117 | // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise |
| 1118 | // we will have foo.jar.jar |
| 1119 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar")) |
| 1120 | fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String()) |
| 1121 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String()) |
| 1122 | fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String()) |
| 1123 | fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") |
| 1124 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") |
| 1125 | } else if fi.class == nativeSharedLib || fi.class == nativeExecutable { |
| 1126 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base()) |
| 1127 | if cc, ok := fi.module.(*cc.Module); ok && cc.UnstrippedOutputFile() != nil { |
| 1128 | fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String()) |
| 1129 | } |
| 1130 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk") |
| 1131 | } else { |
| 1132 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base()) |
| 1133 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
| 1134 | } |
| 1135 | } |
| 1136 | return moduleNames |
| 1137 | } |
| 1138 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1139 | func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData { |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1140 | return android.AndroidMkData{ |
| 1141 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 1142 | moduleNames := []string{} |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1143 | if a.installable() { |
Alex Light | f1801bc | 2019-02-13 11:10:07 -0800 | [diff] [blame] | 1144 | moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1145 | } |
| 1146 | |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1147 | if a.flattened && apexType.image() { |
| 1148 | // Only image APEXes can be flattened. |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1149 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1150 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 1151 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1152 | if len(moduleNames) > 0 { |
| 1153 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " ")) |
| 1154 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1155 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1156 | } else { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1157 | // zip-apex is the less common type so have the name refer to the image-apex |
| 1158 | // only and use {name}.zip if you want the zip-apex |
| 1159 | if apexType == zipApex && a.apexTypes == both { |
| 1160 | name = name + ".zip" |
| 1161 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1162 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1163 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 1164 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) |
| 1165 | 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] | 1166 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String()) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1167 | 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] | 1168 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix()) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1169 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable()) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1170 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", String(a.properties.Key)) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1171 | if len(moduleNames) > 0 { |
| 1172 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " ")) |
| 1173 | } |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 1174 | if len(a.externalDeps) > 0 { |
| 1175 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " ")) |
| 1176 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1177 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1178 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1179 | if apexType == imageApex { |
| 1180 | fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String()) |
| 1181 | } |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1182 | } |
| 1183 | }} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1184 | } |
| 1185 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1186 | func testApexBundleFactory() android.Module { |
| 1187 | return ApexBundleFactory( /*testApex*/ true) |
| 1188 | } |
| 1189 | |
| 1190 | func apexBundleFactory() android.Module { |
| 1191 | return ApexBundleFactory( /*testApex*/ false) |
| 1192 | } |
| 1193 | |
| 1194 | func ApexBundleFactory(testApex bool) android.Module { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1195 | module := &apexBundle{ |
| 1196 | outputFiles: map[apexPackaging]android.WritablePath{}, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1197 | testApex: testApex, |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1198 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1199 | module.AddProperties(&module.properties) |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1200 | module.AddProperties(&module.targetProperties) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1201 | 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] | 1202 | return class == android.Device && ctx.Config().DevicePrefer32BitExecutables() |
| 1203 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1204 | android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1205 | android.InitDefaultableModule(module) |
| 1206 | return module |
| 1207 | } |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1208 | |
| 1209 | // |
| 1210 | // Defaults |
| 1211 | // |
| 1212 | type Defaults struct { |
| 1213 | android.ModuleBase |
| 1214 | android.DefaultsModuleBase |
| 1215 | } |
| 1216 | |
| 1217 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1218 | } |
| 1219 | |
| 1220 | func defaultsFactory() android.Module { |
| 1221 | return DefaultsFactory() |
| 1222 | } |
| 1223 | |
| 1224 | func DefaultsFactory(props ...interface{}) android.Module { |
| 1225 | module := &Defaults{} |
| 1226 | |
| 1227 | module.AddProperties(props...) |
| 1228 | module.AddProperties( |
| 1229 | &apexBundleProperties{}, |
| 1230 | &apexTargetBundleProperties{}, |
| 1231 | ) |
| 1232 | |
| 1233 | android.InitDefaultsModule(module) |
| 1234 | return module |
| 1235 | } |