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}", |
Dan Willemsen | dd651fa | 2019-06-13 04:48:54 +0000 | [diff] [blame] | 64 | "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"}, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 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() { |
Colin Cross | cc0ce80 | 2019-04-02 16:14:11 -0700 | [diff] [blame] | 116 | pctx.Import("android/soong/android") |
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) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 144 | android.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 145 | |
| 146 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 147 | ctx.TopDown("apex_deps", apexDepsMutator) |
Colin Cross | 643614d | 2019-06-19 22:51:38 -0700 | [diff] [blame] | 148 | ctx.BottomUp("apex", apexMutator).Parallel() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 149 | }) |
| 150 | } |
| 151 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 152 | // Mark the direct and transitive dependencies of apex bundles so that they |
| 153 | // can be built for the apex bundles. |
| 154 | func apexDepsMutator(mctx android.TopDownMutatorContext) { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 155 | if a, ok := mctx.Module().(*apexBundle); ok { |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 156 | apexBundleName := mctx.ModuleName() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 157 | mctx.WalkDeps(func(child, parent android.Module) bool { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 158 | depName := mctx.OtherModuleName(child) |
| 159 | // If the parent is apexBundle, this child is directly depended. |
| 160 | _, directDep := parent.(*apexBundle) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 161 | if a.installable() && !a.testApex { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 162 | // TODO(b/123892969): Workaround for not having any way to annotate test-apexs |
| 163 | // non-installable apex's cannot be installed and so should not prevent libraries from being |
| 164 | // installed to the system. |
| 165 | android.UpdateApexDependency(apexBundleName, depName, directDep) |
| 166 | } |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 167 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 168 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 169 | am.BuildForApex(apexBundleName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 170 | return true |
| 171 | } else { |
| 172 | return false |
| 173 | } |
| 174 | }) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | // Create apex variations if a module is included in APEX(s). |
| 179 | func apexMutator(mctx android.BottomUpMutatorContext) { |
| 180 | if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 181 | am.CreateApexVariations(mctx) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 182 | } else if _, ok := mctx.Module().(*apexBundle); ok { |
| 183 | // apex bundle itself is mutated so that it and its modules have same |
| 184 | // apex variant. |
| 185 | apexBundleName := mctx.ModuleName() |
| 186 | mctx.CreateVariations(apexBundleName) |
| 187 | } |
| 188 | } |
| 189 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 190 | type apexNativeDependencies struct { |
| 191 | // List of native libraries |
| 192 | Native_shared_libs []string |
| 193 | // List of native executables |
| 194 | Binaries []string |
| 195 | } |
| 196 | type apexMultilibProperties struct { |
| 197 | // Native dependencies whose compile_multilib is "first" |
| 198 | First apexNativeDependencies |
| 199 | |
| 200 | // Native dependencies whose compile_multilib is "both" |
| 201 | Both apexNativeDependencies |
| 202 | |
| 203 | // Native dependencies whose compile_multilib is "prefer32" |
| 204 | Prefer32 apexNativeDependencies |
| 205 | |
| 206 | // Native dependencies whose compile_multilib is "32" |
| 207 | Lib32 apexNativeDependencies |
| 208 | |
| 209 | // Native dependencies whose compile_multilib is "64" |
| 210 | Lib64 apexNativeDependencies |
| 211 | } |
| 212 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 213 | type apexBundleProperties struct { |
| 214 | // Json manifest file describing meta info of this APEX bundle. Default: |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 215 | // "apex_manifest.json" |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 216 | Manifest *string `android:"path"` |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 217 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 218 | // AndroidManifest.xml file used for the zip container of this APEX bundle. |
| 219 | // If unspecified, a default one is automatically generated. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 220 | AndroidManifest *string `android:"path"` |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 221 | |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 222 | // Canonical name of the APEX bundle in the manifest file. |
| 223 | // If unspecified, defaults to the value of name |
| 224 | Apex_name *string |
| 225 | |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 226 | // Determines the file contexts file for setting security context to each file in this APEX bundle. |
| 227 | // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is |
| 228 | // used. |
| 229 | // Default: <name_of_this_module> |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 230 | File_contexts *string |
| 231 | |
| 232 | // List of native shared libs that are embedded inside this APEX bundle |
| 233 | Native_shared_libs []string |
| 234 | |
| 235 | // List of native executables that are embedded inside this APEX bundle |
| 236 | Binaries []string |
| 237 | |
| 238 | // List of java libraries that are embedded inside this APEX bundle |
| 239 | Java_libs []string |
| 240 | |
| 241 | // List of prebuilt files that are embedded inside this APEX bundle |
| 242 | Prebuilts []string |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 243 | |
| 244 | // Name of the apex_key module that provides the private key to sign APEX |
| 245 | Key *string |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 246 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 247 | // The type of APEX to build. Controls what the APEX payload is. Either |
| 248 | // 'image', 'zip' or 'both'. Default: 'image'. |
| 249 | Payload_type *string |
| 250 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 251 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 252 | // or an android_app_certificate module name in the form ":module". |
| 253 | Certificate *string |
| 254 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 255 | // Whether this APEX is installable to one of the partitions. Default: true. |
| 256 | Installable *bool |
| 257 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 258 | // For native libraries and binaries, use the vendor variant instead of the core (platform) variant. |
| 259 | // Default is false. |
| 260 | Use_vendor *bool |
| 261 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 262 | // For telling the apex to ignore special handling for system libraries such as bionic. Default is false. |
| 263 | Ignore_system_library_special_case *bool |
| 264 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 265 | Multilib apexMultilibProperties |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 266 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 267 | // List of sanitizer names that this APEX is enabled for |
| 268 | SanitizerNames []string `blueprint:"mutated"` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | type apexTargetBundleProperties struct { |
| 272 | Target struct { |
| 273 | // Multilib properties only for android. |
| 274 | Android struct { |
| 275 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 276 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 277 | // Multilib properties only for host. |
| 278 | Host struct { |
| 279 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 280 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 281 | // Multilib properties only for host linux_bionic. |
| 282 | Linux_bionic struct { |
| 283 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 284 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 285 | // Multilib properties only for host linux_glibc. |
| 286 | Linux_glibc struct { |
| 287 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 288 | } |
| 289 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 290 | } |
| 291 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 292 | type apexFileClass int |
| 293 | |
| 294 | const ( |
| 295 | etc apexFileClass = iota |
| 296 | nativeSharedLib |
| 297 | nativeExecutable |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 298 | shBinary |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 299 | pyBinary |
| 300 | goBinary |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 301 | javaSharedLib |
| 302 | ) |
| 303 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 304 | type apexPackaging int |
| 305 | |
| 306 | const ( |
| 307 | imageApex apexPackaging = iota |
| 308 | zipApex |
| 309 | both |
| 310 | ) |
| 311 | |
| 312 | func (a apexPackaging) image() bool { |
| 313 | switch a { |
| 314 | case imageApex, both: |
| 315 | return true |
| 316 | } |
| 317 | return false |
| 318 | } |
| 319 | |
| 320 | func (a apexPackaging) zip() bool { |
| 321 | switch a { |
| 322 | case zipApex, both: |
| 323 | return true |
| 324 | } |
| 325 | return false |
| 326 | } |
| 327 | |
| 328 | func (a apexPackaging) suffix() string { |
| 329 | switch a { |
| 330 | case imageApex: |
| 331 | return imageApexSuffix |
| 332 | case zipApex: |
| 333 | return zipApexSuffix |
| 334 | case both: |
| 335 | panic(fmt.Errorf("must be either zip or image")) |
| 336 | default: |
| 337 | panic(fmt.Errorf("unkonwn APEX type %d", a)) |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | func (a apexPackaging) name() string { |
| 342 | switch a { |
| 343 | case imageApex: |
| 344 | return imageApexType |
| 345 | case zipApex: |
| 346 | return zipApexType |
| 347 | case both: |
| 348 | panic(fmt.Errorf("must be either zip or image")) |
| 349 | default: |
| 350 | panic(fmt.Errorf("unkonwn APEX type %d", a)) |
| 351 | } |
| 352 | } |
| 353 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 354 | func (class apexFileClass) NameInMake() string { |
| 355 | switch class { |
| 356 | case etc: |
| 357 | return "ETC" |
| 358 | case nativeSharedLib: |
| 359 | return "SHARED_LIBRARIES" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 360 | case nativeExecutable, shBinary, pyBinary, goBinary: |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 361 | return "EXECUTABLES" |
| 362 | case javaSharedLib: |
| 363 | return "JAVA_LIBRARIES" |
| 364 | default: |
| 365 | panic(fmt.Errorf("unkonwn class %d", class)) |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | type apexFile struct { |
| 370 | builtFile android.Path |
| 371 | moduleName string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 372 | installDir string |
| 373 | class apexFileClass |
Jiyong Park | a889484 | 2018-12-19 17:36:39 +0900 | [diff] [blame] | 374 | module android.Module |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 375 | symlinks []string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 376 | } |
| 377 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 378 | type apexBundle struct { |
| 379 | android.ModuleBase |
| 380 | android.DefaultableModuleBase |
| 381 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 382 | properties apexBundleProperties |
| 383 | targetProperties apexTargetBundleProperties |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 384 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 385 | apexTypes apexPackaging |
| 386 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 387 | bundleModuleFile android.WritablePath |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 388 | outputFiles map[apexPackaging]android.WritablePath |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 389 | installDir android.OutputPath |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 390 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 391 | public_key_file android.Path |
| 392 | private_key_file android.Path |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 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 | } |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 514 | |
| 515 | if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device { |
| 516 | for _, sanitizer := range ctx.Config().SanitizeDevice() { |
| 517 | if sanitizer == "hwaddress" { |
| 518 | addDependenciesForNativeModules(ctx, |
| 519 | []string{"libclang_rt.hwasan-aarch64-android"}, |
| 520 | nil, target.String(), a.getImageVariation(config)) |
| 521 | break |
| 522 | } |
| 523 | } |
| 524 | } |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 525 | } |
| 526 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 527 | } |
| 528 | |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 529 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 530 | {Mutator: "arch", Variation: "android_common"}, |
| 531 | }, javaLibTag, a.properties.Java_libs...) |
| 532 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 533 | if String(a.properties.Key) == "" { |
| 534 | ctx.ModuleErrorf("key is missing") |
| 535 | return |
| 536 | } |
| 537 | ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key)) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 538 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 539 | cert := android.SrcIsModule(a.getCertString(ctx)) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 540 | if cert != "" { |
| 541 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 542 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 543 | } |
| 544 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 545 | func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 546 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName()) |
| 547 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 548 | return ":" + certificate |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 549 | } |
| 550 | return String(a.properties.Certificate) |
| 551 | } |
| 552 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 553 | func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) { |
| 554 | switch tag { |
| 555 | case "": |
| 556 | if file, ok := a.outputFiles[imageApex]; ok { |
| 557 | return android.Paths{file}, nil |
| 558 | } else { |
| 559 | return nil, nil |
| 560 | } |
| 561 | default: |
| 562 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Jiyong Park | 5a83202 | 2018-12-20 09:54:35 +0900 | [diff] [blame] | 563 | } |
Jiyong Park | 74e240b | 2018-11-27 21:27:08 +0900 | [diff] [blame] | 564 | } |
| 565 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 566 | func (a *apexBundle) installable() bool { |
| 567 | return a.properties.Installable == nil || proptools.Bool(a.properties.Installable) |
| 568 | } |
| 569 | |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 570 | func (a *apexBundle) getImageVariation(config android.DeviceConfig) string { |
| 571 | if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 572 | return "vendor" |
| 573 | } else { |
| 574 | return "core" |
| 575 | } |
| 576 | } |
| 577 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 578 | func (a *apexBundle) EnableSanitizer(sanitizerName string) { |
| 579 | if !android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 580 | a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName) |
| 581 | } |
| 582 | } |
| 583 | |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 584 | func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool { |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 585 | if android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 586 | return true |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | // Then follow the global setting |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 590 | globalSanitizerNames := []string{} |
| 591 | if a.Host() { |
| 592 | globalSanitizerNames = ctx.Config().SanitizeHost() |
| 593 | } else { |
| 594 | arches := ctx.Config().SanitizeDeviceArch() |
| 595 | if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) { |
| 596 | globalSanitizerNames = ctx.Config().SanitizeDevice() |
| 597 | } |
| 598 | } |
| 599 | return android.InList(sanitizerName, globalSanitizerNames) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 600 | } |
| 601 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 602 | func getCopyManifestForNativeLibrary(cc *cc.Module, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 603 | // Decide the APEX-local directory by the multilib of the library |
| 604 | // In the future, we may query this to the module. |
| 605 | switch cc.Arch().ArchType.Multilib { |
| 606 | case "lib32": |
| 607 | dirInApex = "lib" |
| 608 | case "lib64": |
| 609 | dirInApex = "lib64" |
| 610 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 611 | dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath()) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 612 | if !cc.Arch().Native { |
| 613 | dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String()) |
| 614 | } |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 615 | if handleSpecialLibs { |
| 616 | switch cc.Name() { |
| 617 | case "libc", "libm", "libdl": |
| 618 | // Special case for bionic libs. This is to prevent the bionic libs |
| 619 | // from being included in the search path /apex/com.android.apex/lib. |
| 620 | // This exclusion is required because bionic libs in the runtime APEX |
| 621 | // are available via the legacy paths /system/lib/libc.so, etc. By the |
| 622 | // init process, the bionic libs in the APEX are bind-mounted to the |
| 623 | // legacy paths and thus will be loaded into the default linker namespace. |
| 624 | // If the bionic libs are directly in /apex/com.android.apex/lib then |
| 625 | // the same libs will be again loaded to the runtime linker namespace, |
| 626 | // which will result double loading of bionic libs that isn't supported. |
| 627 | dirInApex = filepath.Join(dirInApex, "bionic") |
| 628 | } |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 629 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 630 | |
| 631 | fileToCopy = cc.OutputFile().Path() |
| 632 | return |
| 633 | } |
| 634 | |
| 635 | func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 636 | dirInApex = filepath.Join("bin", cc.RelativeInstallPath()) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 637 | fileToCopy = cc.OutputFile().Path() |
| 638 | return |
| 639 | } |
| 640 | |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 641 | func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) { |
| 642 | dirInApex = "bin" |
| 643 | fileToCopy = py.HostToolPath().Path() |
| 644 | return |
| 645 | } |
| 646 | func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) { |
| 647 | dirInApex = "bin" |
| 648 | s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath()) |
| 649 | if err != nil { |
| 650 | ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath()) |
| 651 | return |
| 652 | } |
| 653 | fileToCopy = android.PathForOutput(ctx, s) |
| 654 | return |
| 655 | } |
| 656 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 657 | func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) { |
| 658 | dirInApex = filepath.Join("bin", sh.SubDir()) |
| 659 | fileToCopy = sh.OutputFile() |
| 660 | return |
| 661 | } |
| 662 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 663 | func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) { |
| 664 | dirInApex = "javalib" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 665 | fileToCopy = java.DexJarFile() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 666 | return |
| 667 | } |
| 668 | |
| 669 | func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) { |
| 670 | dirInApex = filepath.Join("etc", prebuilt.SubDir()) |
| 671 | fileToCopy = prebuilt.OutputFile() |
| 672 | return |
| 673 | } |
| 674 | |
| 675 | func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 676 | filesInfo := []apexFile{} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 677 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 678 | if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" { |
| 679 | a.apexTypes = imageApex |
| 680 | } else if *a.properties.Payload_type == "zip" { |
| 681 | a.apexTypes = zipApex |
| 682 | } else if *a.properties.Payload_type == "both" { |
| 683 | a.apexTypes = both |
| 684 | } else { |
| 685 | ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type) |
| 686 | return |
| 687 | } |
| 688 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 689 | handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case) |
| 690 | |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 691 | ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 692 | if _, ok := parent.(*apexBundle); ok { |
| 693 | // direct dependencies |
| 694 | depTag := ctx.OtherModuleDependencyTag(child) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 695 | depName := ctx.OtherModuleName(child) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 696 | switch depTag { |
| 697 | case sharedLibTag: |
| 698 | if cc, ok := child.(*cc.Module); ok { |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 699 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 700 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 701 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 702 | } else { |
| 703 | 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] | 704 | } |
| 705 | case executableTag: |
| 706 | if cc, ok := child.(*cc.Module); ok { |
Alex Light | 16df4e8 | 2019-01-24 11:37:55 -0800 | [diff] [blame] | 707 | if !cc.Arch().Native { |
| 708 | // There is only one 'bin' directory so we shouldn't bother copying in |
| 709 | // native-bridge'd binaries and only use main ones. |
| 710 | return true |
| 711 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 712 | fileToCopy, dirInApex := getCopyManifestForExecutable(cc) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 713 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 714 | return true |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 715 | } else if sh, ok := child.(*android.ShBinary); ok { |
| 716 | fileToCopy, dirInApex := getCopyManifestForShBinary(sh) |
| 717 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil}) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 718 | } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() { |
| 719 | fileToCopy, dirInApex := getCopyManifestForPyBinary(py) |
| 720 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil}) |
| 721 | } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() { |
| 722 | fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb) |
| 723 | // NB: Since go binaries are static we don't need the module for anything here, which is |
| 724 | // good since the go tool is a blueprint.Module not an android.Module like we would |
| 725 | // normally use. |
| 726 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil}) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 727 | } else { |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 728 | 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] | 729 | } |
| 730 | case javaLibTag: |
| 731 | if java, ok := child.(*java.Library); ok { |
| 732 | fileToCopy, dirInApex := getCopyManifestForJavaLibrary(java) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 733 | if fileToCopy == nil { |
| 734 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 735 | } else { |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 736 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, java, nil}) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 737 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 738 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 739 | } else { |
| 740 | ctx.PropertyErrorf("java_libs", "%q is not a java_library module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 741 | } |
| 742 | case prebuiltTag: |
| 743 | if prebuilt, ok := child.(*android.PrebuiltEtc); ok { |
| 744 | fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 745 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 746 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 747 | } else { |
| 748 | ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName) |
| 749 | } |
| 750 | case keyTag: |
| 751 | if key, ok := child.(*apexKey); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 752 | a.private_key_file = key.private_key_file |
| 753 | a.public_key_file = key.public_key_file |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 754 | return false |
| 755 | } else { |
| 756 | ctx.PropertyErrorf("key", "%q is not an apex_key module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 757 | } |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 758 | case certificateTag: |
| 759 | if dep, ok := child.(*java.AndroidAppCertificate); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 760 | a.container_certificate_file = dep.Certificate.Pem |
| 761 | a.container_private_key_file = dep.Certificate.Key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 762 | return false |
| 763 | } else { |
| 764 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName) |
| 765 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 766 | } |
| 767 | } else { |
| 768 | // indirect dependencies |
| 769 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && am.IsInstallableToApex() { |
| 770 | if cc, ok := child.(*cc.Module); ok { |
Alex Light | 49ae3d9 | 2019-02-21 14:02:46 -0800 | [diff] [blame] | 771 | if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) { |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 772 | // If the dependency is a stubs lib, don't include it in this APEX, |
| 773 | // but make sure that the lib is installed on the device. |
| 774 | // In case no APEX is having the lib, the lib is installed to the system |
| 775 | // partition. |
Alex Light | 49ae3d9 | 2019-02-21 14:02:46 -0800 | [diff] [blame] | 776 | // |
| 777 | // Always include if we are a host-apex however since those won't have any |
| 778 | // system libraries. |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 779 | if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) { |
| 780 | a.externalDeps = append(a.externalDeps, cc.Name()) |
| 781 | } |
| 782 | // Don't track further |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 783 | return false |
| 784 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 785 | depName := ctx.OtherModuleName(child) |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 786 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 787 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 788 | return true |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | return false |
| 793 | }) |
| 794 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 795 | a.flattened = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild() |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 796 | if a.private_key_file == nil { |
Jiyong Park | fa0a373 | 2018-11-09 05:52:26 +0900 | [diff] [blame] | 797 | ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key)) |
| 798 | return |
| 799 | } |
| 800 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 801 | // remove duplicates in filesInfo |
| 802 | removeDup := func(filesInfo []apexFile) []apexFile { |
| 803 | encountered := make(map[android.Path]bool) |
| 804 | result := []apexFile{} |
| 805 | for _, f := range filesInfo { |
| 806 | if !encountered[f.builtFile] { |
| 807 | encountered[f.builtFile] = true |
| 808 | result = append(result, f) |
| 809 | } |
| 810 | } |
| 811 | return result |
| 812 | } |
| 813 | filesInfo = removeDup(filesInfo) |
| 814 | |
| 815 | // to have consistent build rules |
| 816 | sort.Slice(filesInfo, func(i, j int) bool { |
| 817 | return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String() |
| 818 | }) |
| 819 | |
| 820 | // prepend the name of this APEX to the module names. These names will be the names of |
| 821 | // modules that will be defined if the APEX is flattened. |
| 822 | for i := range filesInfo { |
| 823 | filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName |
| 824 | } |
| 825 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 826 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 827 | a.filesInfo = filesInfo |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 828 | |
| 829 | if a.apexTypes.zip() { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 830 | a.buildUnflattenedApex(ctx, zipApex) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 831 | } |
| 832 | if a.apexTypes.image() { |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 833 | // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex() |
| 834 | // is true. This is to support referencing APEX via ":<module_name" syntax |
| 835 | // in other modules. It is in AndroidMk where the selection of flattened |
| 836 | // or unflattened APEX is made. |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 837 | a.buildUnflattenedApex(ctx, imageApex) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 838 | a.buildFlattenedApex(ctx) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 842 | func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath { |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 843 | noticeFiles := []android.Path{} |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 844 | for _, f := range a.filesInfo { |
| 845 | if f.module != nil { |
| 846 | notice := f.module.NoticeFile() |
| 847 | if notice.Valid() { |
| 848 | noticeFiles = append(noticeFiles, notice.Path()) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | } |
| 852 | // append the notice file specified in the apex module itself |
| 853 | if a.NoticeFile().Valid() { |
| 854 | noticeFiles = append(noticeFiles, a.NoticeFile().Path()) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 855 | } |
| 856 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 857 | if len(noticeFiles) == 0 { |
| 858 | return android.OptionalPath{} |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 859 | } |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 860 | |
Jaewoong Jung | 9877279 | 2019-07-01 17:15:13 -0700 | [diff] [blame^] | 861 | return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 862 | } |
| 863 | |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 864 | func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) { |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 865 | cert := String(a.properties.Certificate) |
| 866 | if cert != "" && android.SrcIsModule(cert) == "" { |
| 867 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 868 | a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem") |
| 869 | a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8") |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 870 | } else if cert == "" { |
| 871 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 872 | a.container_certificate_file = pem |
| 873 | a.container_private_key_file = key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 874 | } |
| 875 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 876 | manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 877 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 878 | var abis []string |
| 879 | for _, target := range ctx.MultiTargets() { |
| 880 | if len(target.Arch.Abi) > 0 { |
| 881 | abis = append(abis, target.Arch.Abi[0]) |
| 882 | } |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 883 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 884 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 885 | abis = android.FirstUniqueStrings(abis) |
| 886 | |
| 887 | suffix := apexType.suffix() |
| 888 | unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 889 | |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 890 | filesToCopy := []android.Path{} |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 891 | for _, f := range a.filesInfo { |
| 892 | filesToCopy = append(filesToCopy, f.builtFile) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 893 | } |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 894 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 895 | copyCommands := []string{} |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 896 | for i, src := range filesToCopy { |
| 897 | dest := filepath.Join(a.filesInfo[i].installDir, src.Base()) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 898 | dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 899 | copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path)) |
| 900 | copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 901 | for _, sym := range a.filesInfo[i].symlinks { |
| 902 | symlinkDest := filepath.Join(filepath.Dir(dest_path), sym) |
| 903 | copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest) |
| 904 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 905 | } |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 906 | implicitInputs := append(android.Paths(nil), filesToCopy...) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 907 | implicitInputs = append(implicitInputs, manifest) |
| 908 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 909 | outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String() |
| 910 | prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 911 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 912 | if apexType.image() { |
| 913 | // files and dirs that will be created in APEX |
| 914 | var readOnlyPaths []string |
| 915 | var executablePaths []string // this also includes dirs |
| 916 | for _, f := range a.filesInfo { |
| 917 | pathInApex := filepath.Join(f.installDir, f.builtFile.Base()) |
| 918 | if f.installDir == "bin" { |
| 919 | executablePaths = append(executablePaths, pathInApex) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 920 | for _, s := range f.symlinks { |
| 921 | executablePaths = append(executablePaths, filepath.Join("bin", s)) |
| 922 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 923 | } else { |
| 924 | readOnlyPaths = append(readOnlyPaths, pathInApex) |
| 925 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 926 | dir := f.installDir |
| 927 | for !android.InList(dir, executablePaths) && dir != "" { |
| 928 | executablePaths = append(executablePaths, dir) |
| 929 | dir, _ = filepath.Split(dir) // move up to the parent |
| 930 | if len(dir) > 0 { |
| 931 | // remove trailing slash |
| 932 | dir = dir[:len(dir)-1] |
| 933 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | sort.Strings(readOnlyPaths) |
| 937 | sort.Strings(executablePaths) |
| 938 | cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config") |
| 939 | ctx.Build(pctx, android.BuildParams{ |
| 940 | Rule: generateFsConfig, |
| 941 | Output: cannedFsConfig, |
| 942 | Description: "generate fs config", |
| 943 | Args: map[string]string{ |
| 944 | "ro_paths": strings.Join(readOnlyPaths, " "), |
| 945 | "exec_paths": strings.Join(executablePaths, " "), |
| 946 | }, |
| 947 | }) |
| 948 | |
| 949 | fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName()) |
| 950 | fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts" |
| 951 | fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath) |
| 952 | if !fileContextsOptionalPath.Valid() { |
| 953 | ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath) |
| 954 | return |
| 955 | } |
| 956 | fileContexts := fileContextsOptionalPath.Path() |
| 957 | |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 958 | optFlags := []string{} |
| 959 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 960 | // Additional implicit inputs. |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 961 | implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file) |
| 962 | optFlags = append(optFlags, "--pubkey "+a.public_key_file.String()) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 963 | |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 964 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
| 965 | if overridden { |
| 966 | optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName) |
| 967 | } |
| 968 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 969 | if a.properties.AndroidManifest != nil { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 970 | androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest)) |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 971 | implicitInputs = append(implicitInputs, androidManifestFile) |
| 972 | optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String()) |
| 973 | } |
| 974 | |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 975 | targetSdkVersion := ctx.Config().DefaultAppTargetSdk() |
| 976 | if targetSdkVersion == ctx.Config().PlatformSdkCodename() && |
| 977 | ctx.Config().UnbundledBuild() && |
| 978 | !ctx.Config().UnbundledBuildUsePrebuiltSdks() && |
| 979 | ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") { |
| 980 | apiFingerprint := java.ApiFingerprintPath(ctx) |
| 981 | targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String()) |
| 982 | implicitInputs = append(implicitInputs, apiFingerprint) |
| 983 | } |
| 984 | optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion) |
| 985 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 986 | noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix) |
| 987 | if noticeFile.Valid() { |
| 988 | // If there's a NOTICE file, embed it as an asset file in the APEX. |
| 989 | implicitInputs = append(implicitInputs, noticeFile.Path()) |
| 990 | optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String())) |
| 991 | } |
| 992 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 993 | ctx.Build(pctx, android.BuildParams{ |
| 994 | Rule: apexRule, |
| 995 | Implicits: implicitInputs, |
| 996 | Output: unsignedOutputFile, |
| 997 | Description: "apex (" + apexType.name() + ")", |
| 998 | Args: map[string]string{ |
| 999 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
| 1000 | "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(), |
| 1001 | "copy_commands": strings.Join(copyCommands, " && "), |
| 1002 | "manifest": manifest.String(), |
| 1003 | "file_contexts": fileContexts.String(), |
| 1004 | "canned_fs_config": cannedFsConfig.String(), |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1005 | "key": a.private_key_file.String(), |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 1006 | "opt_flags": strings.Join(optFlags, " "), |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1007 | }, |
| 1008 | }) |
| 1009 | |
| 1010 | apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix) |
| 1011 | bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip") |
| 1012 | a.bundleModuleFile = bundleModuleFile |
| 1013 | |
| 1014 | ctx.Build(pctx, android.BuildParams{ |
| 1015 | Rule: apexProtoConvertRule, |
| 1016 | Input: unsignedOutputFile, |
| 1017 | Output: apexProtoFile, |
| 1018 | Description: "apex proto convert", |
| 1019 | }) |
| 1020 | |
| 1021 | ctx.Build(pctx, android.BuildParams{ |
| 1022 | Rule: apexBundleRule, |
| 1023 | Input: apexProtoFile, |
| 1024 | Output: a.bundleModuleFile, |
| 1025 | Description: "apex bundle module", |
| 1026 | Args: map[string]string{ |
| 1027 | "abi": strings.Join(abis, "."), |
| 1028 | }, |
| 1029 | }) |
| 1030 | } else { |
| 1031 | ctx.Build(pctx, android.BuildParams{ |
| 1032 | Rule: zipApexRule, |
| 1033 | Implicits: implicitInputs, |
| 1034 | Output: unsignedOutputFile, |
| 1035 | Description: "apex (" + apexType.name() + ")", |
| 1036 | Args: map[string]string{ |
| 1037 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
| 1038 | "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(), |
| 1039 | "copy_commands": strings.Join(copyCommands, " && "), |
| 1040 | "manifest": manifest.String(), |
| 1041 | }, |
| 1042 | }) |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1043 | } |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1044 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1045 | a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1046 | ctx.Build(pctx, android.BuildParams{ |
| 1047 | Rule: java.Signapk, |
| 1048 | Description: "signapk", |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1049 | Output: a.outputFiles[apexType], |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1050 | Input: unsignedOutputFile, |
Dan Willemsen | dd651fa | 2019-06-13 04:48:54 +0000 | [diff] [blame] | 1051 | Implicits: []android.Path{ |
| 1052 | a.container_certificate_file, |
| 1053 | a.container_private_key_file, |
| 1054 | }, |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1055 | Args: map[string]string{ |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1056 | "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(), |
Jiyong Park | bfe64a1 | 2018-11-22 02:51:54 +0900 | [diff] [blame] | 1057 | "flags": "-a 4096", //alignment |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1058 | }, |
| 1059 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1060 | |
| 1061 | // Install to $OUT/soong/{target,host}/.../apex |
Alex Light | 2a2561f | 2019-02-12 16:59:09 -0800 | [diff] [blame] | 1062 | if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1063 | ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType]) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1064 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1065 | } |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1066 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1067 | func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1068 | if a.installable() { |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 1069 | // For flattened APEX, do nothing but make sure that apex_manifest.json and apex_pubkey are also copied along |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1070 | // with other ordinary files. |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1071 | manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) |
Jiyong Park | d699cb9 | 2019-01-10 00:23:16 +0900 | [diff] [blame] | 1072 | |
| 1073 | // rename to apex_manifest.json |
| 1074 | copiedManifest := android.PathForModuleOut(ctx, "apex_manifest.json") |
| 1075 | ctx.Build(pctx, android.BuildParams{ |
| 1076 | Rule: android.Cp, |
| 1077 | Input: manifest, |
| 1078 | Output: copiedManifest, |
| 1079 | }) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1080 | 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] | 1081 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 1082 | // rename to apex_pubkey |
| 1083 | copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey") |
| 1084 | ctx.Build(pctx, android.BuildParams{ |
| 1085 | Rule: android.Cp, |
| 1086 | Input: a.public_key_file, |
| 1087 | Output: copiedPubkey, |
| 1088 | }) |
| 1089 | a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil}) |
| 1090 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1091 | if ctx.Config().FlattenApex() { |
| 1092 | for _, fi := range a.filesInfo { |
| 1093 | dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir) |
Alex Light | f4857cf | 2019-02-22 13:00:04 -0800 | [diff] [blame] | 1094 | target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile) |
| 1095 | for _, sym := range fi.symlinks { |
| 1096 | ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target) |
| 1097 | } |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1098 | } |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1099 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1100 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | func (a *apexBundle) AndroidMk() android.AndroidMkData { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1104 | writers := []android.AndroidMkData{} |
| 1105 | if a.apexTypes.image() { |
| 1106 | writers = append(writers, a.androidMkForType(imageApex)) |
| 1107 | } |
| 1108 | if a.apexTypes.zip() { |
| 1109 | writers = append(writers, a.androidMkForType(zipApex)) |
| 1110 | } |
| 1111 | return android.AndroidMkData{ |
| 1112 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 1113 | for _, data := range writers { |
| 1114 | data.Custom(w, name, prefix, moduleDir, data) |
| 1115 | } |
| 1116 | }} |
| 1117 | } |
| 1118 | |
Alex Light | f1801bc | 2019-02-13 11:10:07 -0800 | [diff] [blame] | 1119 | 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] | 1120 | moduleNames := []string{} |
| 1121 | |
| 1122 | for _, fi := range a.filesInfo { |
| 1123 | if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake { |
| 1124 | continue |
| 1125 | } |
| 1126 | if !android.InList(fi.moduleName, moduleNames) { |
| 1127 | moduleNames = append(moduleNames, fi.moduleName) |
| 1128 | } |
| 1129 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1130 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 1131 | fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName) |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1132 | // /apex/<name>/{lib|framework|...} |
| 1133 | pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", |
| 1134 | proptools.StringDefault(a.properties.Apex_name, name), fi.installDir) |
Alex Light | f1801bc | 2019-02-13 11:10:07 -0800 | [diff] [blame] | 1135 | if a.flattened && apexType.image() { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1136 | // /system/apex/<name>/{lib|framework|...} |
| 1137 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", |
| 1138 | a.installDir.RelPathString(), name, fi.installDir)) |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1139 | fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated) |
Alex Light | f4857cf | 2019-02-22 13:00:04 -0800 | [diff] [blame] | 1140 | if len(fi.symlinks) > 0 { |
| 1141 | fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " ")) |
| 1142 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1143 | |
| 1144 | if fi.module != nil && fi.module.NoticeFile().Valid() { |
| 1145 | fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String()) |
| 1146 | } |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1147 | } else { |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1148 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1149 | } |
| 1150 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String()) |
| 1151 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake()) |
| 1152 | if fi.module != nil { |
| 1153 | archStr := fi.module.Target().Arch.ArchType.String() |
| 1154 | host := false |
| 1155 | switch fi.module.Target().Os.Class { |
| 1156 | case android.Host: |
| 1157 | if archStr != "common" { |
| 1158 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) |
| 1159 | } |
| 1160 | host = true |
| 1161 | case android.HostCross: |
| 1162 | if archStr != "common" { |
| 1163 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) |
| 1164 | } |
| 1165 | host = true |
| 1166 | case android.Device: |
| 1167 | if archStr != "common" { |
| 1168 | fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr) |
| 1169 | } |
| 1170 | } |
| 1171 | if host { |
| 1172 | makeOs := fi.module.Target().Os.String() |
| 1173 | if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic { |
| 1174 | makeOs = "linux" |
| 1175 | } |
| 1176 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs) |
| 1177 | fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") |
| 1178 | } |
| 1179 | } |
| 1180 | if fi.class == javaSharedLib { |
| 1181 | javaModule := fi.module.(*java.Library) |
| 1182 | // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore |
| 1183 | // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise |
| 1184 | // we will have foo.jar.jar |
| 1185 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar")) |
| 1186 | fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String()) |
| 1187 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String()) |
| 1188 | fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String()) |
| 1189 | fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") |
| 1190 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") |
| 1191 | } else if fi.class == nativeSharedLib || fi.class == nativeExecutable { |
| 1192 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base()) |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 1193 | if cc, ok := fi.module.(*cc.Module); ok { |
| 1194 | if cc.UnstrippedOutputFile() != nil { |
| 1195 | fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String()) |
| 1196 | } |
| 1197 | cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1198 | } |
| 1199 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk") |
| 1200 | } else { |
| 1201 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base()) |
| 1202 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
| 1203 | } |
| 1204 | } |
| 1205 | return moduleNames |
| 1206 | } |
| 1207 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1208 | func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData { |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1209 | return android.AndroidMkData{ |
| 1210 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 1211 | moduleNames := []string{} |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1212 | if a.installable() { |
Alex Light | f1801bc | 2019-02-13 11:10:07 -0800 | [diff] [blame] | 1213 | moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1214 | } |
| 1215 | |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1216 | if a.flattened && apexType.image() { |
| 1217 | // Only image APEXes can be flattened. |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1218 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1219 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 1220 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1221 | if len(moduleNames) > 0 { |
| 1222 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " ")) |
| 1223 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1224 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1225 | } else { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1226 | // zip-apex is the less common type so have the name refer to the image-apex |
| 1227 | // only and use {name}.zip if you want the zip-apex |
| 1228 | if apexType == zipApex && a.apexTypes == both { |
| 1229 | name = name + ".zip" |
| 1230 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1231 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1232 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 1233 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) |
| 1234 | 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] | 1235 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String()) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1236 | 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] | 1237 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix()) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1238 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable()) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1239 | if len(moduleNames) > 0 { |
| 1240 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " ")) |
| 1241 | } |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 1242 | if len(a.externalDeps) > 0 { |
| 1243 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " ")) |
| 1244 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1245 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1246 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1247 | if apexType == imageApex { |
| 1248 | fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String()) |
| 1249 | } |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1250 | } |
| 1251 | }} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1252 | } |
| 1253 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1254 | func testApexBundleFactory() android.Module { |
| 1255 | return ApexBundleFactory( /*testApex*/ true) |
| 1256 | } |
| 1257 | |
| 1258 | func apexBundleFactory() android.Module { |
| 1259 | return ApexBundleFactory( /*testApex*/ false) |
| 1260 | } |
| 1261 | |
| 1262 | func ApexBundleFactory(testApex bool) android.Module { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1263 | module := &apexBundle{ |
| 1264 | outputFiles: map[apexPackaging]android.WritablePath{}, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1265 | testApex: testApex, |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1266 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1267 | module.AddProperties(&module.properties) |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1268 | module.AddProperties(&module.targetProperties) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1269 | 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] | 1270 | return class == android.Device && ctx.Config().DevicePrefer32BitExecutables() |
| 1271 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1272 | android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1273 | android.InitDefaultableModule(module) |
| 1274 | return module |
| 1275 | } |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1276 | |
| 1277 | // |
| 1278 | // Defaults |
| 1279 | // |
| 1280 | type Defaults struct { |
| 1281 | android.ModuleBase |
| 1282 | android.DefaultsModuleBase |
| 1283 | } |
| 1284 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1285 | func defaultsFactory() android.Module { |
| 1286 | return DefaultsFactory() |
| 1287 | } |
| 1288 | |
| 1289 | func DefaultsFactory(props ...interface{}) android.Module { |
| 1290 | module := &Defaults{} |
| 1291 | |
| 1292 | module.AddProperties(props...) |
| 1293 | module.AddProperties( |
| 1294 | &apexBundleProperties{}, |
| 1295 | &apexTargetBundleProperties{}, |
| 1296 | ) |
| 1297 | |
| 1298 | android.InitDefaultsModule(module) |
| 1299 | return module |
| 1300 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1301 | |
| 1302 | // |
| 1303 | // Prebuilt APEX |
| 1304 | // |
| 1305 | type Prebuilt struct { |
| 1306 | android.ModuleBase |
| 1307 | prebuilt android.Prebuilt |
| 1308 | |
| 1309 | properties PrebuiltProperties |
| 1310 | |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1311 | inputApex android.Path |
| 1312 | installDir android.OutputPath |
| 1313 | installFilename string |
Nikita Ioffe | 89ecd59 | 2019-04-05 02:10:45 +0100 | [diff] [blame] | 1314 | outputApex android.WritablePath |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | type PrebuiltProperties struct { |
| 1318 | // the path to the prebuilt .apex file to import. |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1319 | Source string `blueprint:"mutated"` |
| 1320 | |
| 1321 | Src *string |
| 1322 | Arch struct { |
| 1323 | Arm struct { |
| 1324 | Src *string |
| 1325 | } |
| 1326 | Arm64 struct { |
| 1327 | Src *string |
| 1328 | } |
| 1329 | X86 struct { |
| 1330 | Src *string |
| 1331 | } |
| 1332 | X86_64 struct { |
| 1333 | Src *string |
| 1334 | } |
| 1335 | } |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1336 | |
| 1337 | Installable *bool |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1338 | // Optional name for the installed apex. If unspecified, name of the |
| 1339 | // module is used as the file name |
| 1340 | Filename *string |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | func (p *Prebuilt) installable() bool { |
| 1344 | return p.properties.Installable == nil || proptools.Bool(p.properties.Installable) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1348 | // This is called before prebuilt_select and prebuilt_postdeps mutators |
| 1349 | // The mutators requires that src to be set correctly for each arch so that |
| 1350 | // arch variants are disabled when src is not provided for the arch. |
| 1351 | if len(ctx.MultiTargets()) != 1 { |
| 1352 | ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex") |
| 1353 | return |
| 1354 | } |
| 1355 | var src string |
| 1356 | switch ctx.MultiTargets()[0].Arch.ArchType { |
| 1357 | case android.Arm: |
| 1358 | src = String(p.properties.Arch.Arm.Src) |
| 1359 | case android.Arm64: |
| 1360 | src = String(p.properties.Arch.Arm64.Src) |
| 1361 | case android.X86: |
| 1362 | src = String(p.properties.Arch.X86.Src) |
| 1363 | case android.X86_64: |
| 1364 | src = String(p.properties.Arch.X86_64.Src) |
| 1365 | default: |
| 1366 | ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String()) |
| 1367 | return |
| 1368 | } |
| 1369 | if src == "" { |
| 1370 | src = String(p.properties.Src) |
| 1371 | } |
| 1372 | p.properties.Source = src |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1375 | func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) { |
| 1376 | switch tag { |
| 1377 | case "": |
| 1378 | return android.Paths{p.outputApex}, nil |
| 1379 | default: |
| 1380 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 1381 | } |
Nikita Ioffe | 89ecd59 | 2019-04-05 02:10:45 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
Jiyong Park | 4d27704 | 2019-04-23 18:00:10 +0900 | [diff] [blame] | 1384 | func (p *Prebuilt) InstallFilename() string { |
| 1385 | return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix) |
| 1386 | } |
| 1387 | |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1388 | func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1389 | // TODO(jungjw): Check the key validity. |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1390 | p.inputApex = p.Prebuilt().SingleSourcePath(ctx) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1391 | p.installDir = android.PathForModuleInstall(ctx, "apex") |
Jiyong Park | 4d27704 | 2019-04-23 18:00:10 +0900 | [diff] [blame] | 1392 | p.installFilename = p.InstallFilename() |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1393 | if !strings.HasSuffix(p.installFilename, imageApexSuffix) { |
| 1394 | ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix) |
| 1395 | } |
Nikita Ioffe | 89ecd59 | 2019-04-05 02:10:45 +0100 | [diff] [blame] | 1396 | p.outputApex = android.PathForModuleOut(ctx, p.installFilename) |
| 1397 | ctx.Build(pctx, android.BuildParams{ |
| 1398 | Rule: android.Cp, |
| 1399 | Input: p.inputApex, |
| 1400 | Output: p.outputApex, |
| 1401 | }) |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1402 | if p.installable() { |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1403 | ctx.InstallFile(p.installDir, p.installFilename, p.inputApex) |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1404 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | func (p *Prebuilt) Prebuilt() *android.Prebuilt { |
| 1408 | return &p.prebuilt |
| 1409 | } |
| 1410 | |
| 1411 | func (p *Prebuilt) Name() string { |
| 1412 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 1413 | } |
| 1414 | |
| 1415 | func (p *Prebuilt) AndroidMk() android.AndroidMkData { |
| 1416 | return android.AndroidMkData{ |
| 1417 | Class: "ETC", |
| 1418 | OutputFile: android.OptionalPathForPath(p.inputApex), |
| 1419 | Include: "$(BUILD_PREBUILT)", |
| 1420 | Extra: []android.AndroidMkExtraFunc{ |
| 1421 | func(w io.Writer, outputFile android.Path) { |
| 1422 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString())) |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1423 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", p.installFilename) |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1424 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !p.installable()) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1425 | }, |
| 1426 | }, |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 1431 | func PrebuiltFactory() android.Module { |
| 1432 | module := &Prebuilt{} |
| 1433 | module.AddProperties(&module.properties) |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1434 | android.InitSingleSourcePrebuiltModule(module, &module.properties.Source) |
| 1435 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1436 | return module |
| 1437 | } |