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