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