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