Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1 | // Copyright (C) 2018 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "io" |
| 20 | "path/filepath" |
| 21 | "runtime" |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 22 | "sort" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 23 | "strings" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/cc" |
| 27 | "android/soong/java" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 28 | "android/soong/python" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 29 | |
| 30 | "github.com/google/blueprint" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 31 | "github.com/google/blueprint/bootstrap" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 32 | "github.com/google/blueprint/proptools" |
| 33 | ) |
| 34 | |
| 35 | var ( |
| 36 | pctx = android.NewPackageContext("android/apex") |
| 37 | |
| 38 | // Create a canned fs config file where all files and directories are |
| 39 | // by default set to (uid/gid/mode) = (1000/1000/0644) |
| 40 | // TODO(b/113082813) make this configurable using config.fs syntax |
| 41 | generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{ |
Roland Levillain | 2b11f74 | 2018-11-02 11:50:42 +0000 | [diff] [blame] | 42 | Command: `echo '/ 1000 1000 0755' > ${out} && ` + |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 43 | `echo '/apex_manifest.json 1000 1000 0644' >> ${out} && ` + |
Jiyong Park | 92905d6 | 2018-10-11 13:23:09 +0900 | [diff] [blame] | 44 | `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` + |
Jiyong Park | 805cbc3 | 2019-01-08 14:04:17 +0900 | [diff] [blame] | 45 | `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 46 | Description: "fs_config ${out}", |
Jiyong Park | 92905d6 | 2018-10-11 13:23:09 +0900 | [diff] [blame] | 47 | }, "ro_paths", "exec_paths") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 48 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 49 | injectApexDependency = pctx.StaticRule("injectApexDependency", blueprint.RuleParams{ |
| 50 | Command: `rm -f $out && ${jsonmodify} $in ` + |
| 51 | `-a provideNativeLibs ${provideNativeLibs} ` + |
| 52 | `-a requireNativeLibs ${requireNativeLibs} -o $out`, |
| 53 | CommandDeps: []string{"${jsonmodify}"}, |
| 54 | Description: "Inject dependency into ${out}", |
| 55 | }, "provideNativeLibs", "requireNativeLibs") |
| 56 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 57 | // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate |
| 58 | // against the binary policy using sefcontext_compiler -p <policy>. |
| 59 | |
| 60 | // TODO(b/114327326): automate the generation of file_contexts |
| 61 | apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{ |
| 62 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
Roland Levillain | 96cf4d4 | 2019-07-30 19:56:56 +0100 | [diff] [blame] | 63 | `(. ${out}.copy_commands) && ` + |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 64 | `APEXER_TOOL_PATH=${tool_path} ` + |
Jiyong Park | 2556015 | 2018-11-20 09:57:52 +0900 | [diff] [blame] | 65 | `${apexer} --force --manifest ${manifest} ` + |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 66 | `--file_contexts ${file_contexts} ` + |
| 67 | `--canned_fs_config ${canned_fs_config} ` + |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 68 | `--payload_type image ` + |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 69 | `--key ${key} ${opt_flags} ${image_dir} ${out} `, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 70 | CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}", |
| 71 | "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", |
Dan Willemsen | dd651fa | 2019-06-13 04:48:54 +0000 | [diff] [blame] | 72 | "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"}, |
Roland Levillain | 96cf4d4 | 2019-07-30 19:56:56 +0100 | [diff] [blame] | 73 | Rspfile: "${out}.copy_commands", |
| 74 | RspfileContent: "${copy_commands}", |
| 75 | Description: "APEX ${image_dir} => ${out}", |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 76 | }, "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] | 77 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 78 | zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ |
| 79 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
Roland Levillain | 96cf4d4 | 2019-07-30 19:56:56 +0100 | [diff] [blame] | 80 | `(. ${out}.copy_commands) && ` + |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 81 | `APEXER_TOOL_PATH=${tool_path} ` + |
| 82 | `${apexer} --force --manifest ${manifest} ` + |
| 83 | `--payload_type zip ` + |
| 84 | `${image_dir} ${out} `, |
Roland Levillain | 96cf4d4 | 2019-07-30 19:56:56 +0100 | [diff] [blame] | 85 | CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"}, |
| 86 | Rspfile: "${out}.copy_commands", |
| 87 | RspfileContent: "${copy_commands}", |
| 88 | Description: "ZipAPEX ${image_dir} => ${out}", |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 89 | }, "tool_path", "image_dir", "copy_commands", "manifest") |
| 90 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 91 | apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule", |
| 92 | blueprint.RuleParams{ |
| 93 | Command: `${aapt2} convert --output-format proto $in -o $out`, |
| 94 | CommandDeps: []string{"${aapt2}"}, |
| 95 | }) |
| 96 | |
| 97 | apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{ |
Jiyong Park | 1ed0fc5 | 2018-11-23 13:22:21 +0900 | [diff] [blame] | 98 | Command: `${zip2zip} -i $in -o $out ` + |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 99 | `apex_payload.img:apex/${abi}.img ` + |
| 100 | `apex_manifest.json:root/apex_manifest.json ` + |
Shahar Amitai | 328b077 | 2018-11-26 14:12:02 +0000 | [diff] [blame] | 101 | `AndroidManifest.xml:manifest/AndroidManifest.xml`, |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 102 | CommandDeps: []string{"${zip2zip}"}, |
| 103 | Description: "app bundle", |
| 104 | }, "abi") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 105 | ) |
| 106 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 107 | var imageApexSuffix = ".apex" |
| 108 | var zipApexSuffix = ".zipapex" |
| 109 | |
| 110 | var imageApexType = "image" |
| 111 | var zipApexType = "zip" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 112 | |
| 113 | type dependencyTag struct { |
| 114 | blueprint.BaseDependencyTag |
| 115 | name string |
| 116 | } |
| 117 | |
| 118 | var ( |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 119 | sharedLibTag = dependencyTag{name: "sharedLib"} |
| 120 | executableTag = dependencyTag{name: "executable"} |
| 121 | javaLibTag = dependencyTag{name: "javaLib"} |
| 122 | prebuiltTag = dependencyTag{name: "prebuilt"} |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 123 | testTag = dependencyTag{name: "test"} |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 124 | keyTag = dependencyTag{name: "key"} |
| 125 | certificateTag = dependencyTag{name: "certificate"} |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 126 | usesTag = dependencyTag{name: "uses"} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 127 | ) |
| 128 | |
| 129 | func init() { |
Colin Cross | cc0ce80 | 2019-04-02 16:14:11 -0700 | [diff] [blame] | 130 | pctx.Import("android/soong/android") |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 131 | pctx.Import("android/soong/java") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 132 | pctx.HostBinToolVariable("apexer", "apexer") |
Roland Levillain | 54bdfda | 2018-10-05 19:34:32 +0100 | [diff] [blame] | 133 | // ART minimal builds (using the master-art manifest) do not have the "frameworks/base" |
| 134 | // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead. |
| 135 | hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) { |
| 136 | pctx.VariableFunc(name, func(ctx android.PackageVarContext) string { |
David Brazdil | 91b4e3e | 2019-01-23 21:04:05 +0000 | [diff] [blame] | 137 | if !ctx.Config().FrameworksBaseDirExists(ctx) { |
Roland Levillain | 54bdfda | 2018-10-05 19:34:32 +0100 | [diff] [blame] | 138 | return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool) |
| 139 | } else { |
| 140 | return pctx.HostBinToolPath(ctx, tool).String() |
| 141 | } |
| 142 | }) |
| 143 | } |
| 144 | hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 145 | pctx.HostBinToolVariable("avbtool", "avbtool") |
| 146 | pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid") |
| 147 | pctx.HostBinToolVariable("merge_zips", "merge_zips") |
| 148 | pctx.HostBinToolVariable("mke2fs", "mke2fs") |
| 149 | pctx.HostBinToolVariable("resize2fs", "resize2fs") |
| 150 | pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile") |
| 151 | pctx.HostBinToolVariable("soong_zip", "soong_zip") |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 152 | pctx.HostBinToolVariable("zip2zip", "zip2zip") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 153 | pctx.HostBinToolVariable("zipalign", "zipalign") |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 154 | pctx.HostBinToolVariable("jsonmodify", "jsonmodify") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 155 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 156 | android.RegisterModuleType("apex", apexBundleFactory) |
| 157 | android.RegisterModuleType("apex_test", testApexBundleFactory) |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 158 | android.RegisterModuleType("apex_defaults", defaultsFactory) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 159 | android.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 160 | |
| 161 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 162 | ctx.TopDown("apex_deps", apexDepsMutator) |
Colin Cross | 643614d | 2019-06-19 22:51:38 -0700 | [diff] [blame] | 163 | ctx.BottomUp("apex", apexMutator).Parallel() |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 164 | ctx.BottomUp("apex_uses", apexUsesMutator).Parallel() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 165 | }) |
| 166 | } |
| 167 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 168 | // Mark the direct and transitive dependencies of apex bundles so that they |
| 169 | // can be built for the apex bundles. |
| 170 | func apexDepsMutator(mctx android.TopDownMutatorContext) { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 171 | if a, ok := mctx.Module().(*apexBundle); ok { |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 172 | apexBundleName := mctx.ModuleName() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 173 | mctx.WalkDeps(func(child, parent android.Module) bool { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 174 | depName := mctx.OtherModuleName(child) |
| 175 | // If the parent is apexBundle, this child is directly depended. |
| 176 | _, directDep := parent.(*apexBundle) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 177 | if a.installable() && !a.testApex { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 178 | // TODO(b/123892969): Workaround for not having any way to annotate test-apexs |
| 179 | // non-installable apex's cannot be installed and so should not prevent libraries from being |
| 180 | // installed to the system. |
| 181 | android.UpdateApexDependency(apexBundleName, depName, directDep) |
| 182 | } |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 183 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 184 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 185 | am.BuildForApex(apexBundleName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 186 | return true |
| 187 | } else { |
| 188 | return false |
| 189 | } |
| 190 | }) |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | // Create apex variations if a module is included in APEX(s). |
| 195 | func apexMutator(mctx android.BottomUpMutatorContext) { |
| 196 | if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 197 | am.CreateApexVariations(mctx) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 198 | } else if _, ok := mctx.Module().(*apexBundle); ok { |
| 199 | // apex bundle itself is mutated so that it and its modules have same |
| 200 | // apex variant. |
| 201 | apexBundleName := mctx.ModuleName() |
| 202 | mctx.CreateVariations(apexBundleName) |
| 203 | } |
| 204 | } |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 205 | func apexUsesMutator(mctx android.BottomUpMutatorContext) { |
| 206 | if ab, ok := mctx.Module().(*apexBundle); ok { |
| 207 | mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...) |
| 208 | } |
| 209 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 210 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 211 | type apexNativeDependencies struct { |
| 212 | // List of native libraries |
| 213 | Native_shared_libs []string |
| 214 | // List of native executables |
| 215 | Binaries []string |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 216 | // List of native tests |
| 217 | Tests []string |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 218 | } |
| 219 | type apexMultilibProperties struct { |
| 220 | // Native dependencies whose compile_multilib is "first" |
| 221 | First apexNativeDependencies |
| 222 | |
| 223 | // Native dependencies whose compile_multilib is "both" |
| 224 | Both apexNativeDependencies |
| 225 | |
| 226 | // Native dependencies whose compile_multilib is "prefer32" |
| 227 | Prefer32 apexNativeDependencies |
| 228 | |
| 229 | // Native dependencies whose compile_multilib is "32" |
| 230 | Lib32 apexNativeDependencies |
| 231 | |
| 232 | // Native dependencies whose compile_multilib is "64" |
| 233 | Lib64 apexNativeDependencies |
| 234 | } |
| 235 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 236 | type apexBundleProperties struct { |
| 237 | // Json manifest file describing meta info of this APEX bundle. Default: |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 238 | // "apex_manifest.json" |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 239 | Manifest *string `android:"path"` |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 240 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 241 | // AndroidManifest.xml file used for the zip container of this APEX bundle. |
| 242 | // If unspecified, a default one is automatically generated. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 243 | AndroidManifest *string `android:"path"` |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 244 | |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 245 | // Canonical name of the APEX bundle in the manifest file. |
| 246 | // If unspecified, defaults to the value of name |
| 247 | Apex_name *string |
| 248 | |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 249 | // Determines the file contexts file for setting security context to each file in this APEX bundle. |
| 250 | // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is |
| 251 | // used. |
| 252 | // Default: <name_of_this_module> |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 253 | File_contexts *string |
| 254 | |
| 255 | // List of native shared libs that are embedded inside this APEX bundle |
| 256 | Native_shared_libs []string |
| 257 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 258 | // List of executables that are embedded inside this APEX bundle |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 259 | Binaries []string |
| 260 | |
| 261 | // List of java libraries that are embedded inside this APEX bundle |
| 262 | Java_libs []string |
| 263 | |
| 264 | // List of prebuilt files that are embedded inside this APEX bundle |
| 265 | Prebuilts []string |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 266 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 267 | // List of tests that are embedded inside this APEX bundle |
| 268 | Tests []string |
| 269 | |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 270 | // Name of the apex_key module that provides the private key to sign APEX |
| 271 | Key *string |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 272 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 273 | // The type of APEX to build. Controls what the APEX payload is. Either |
| 274 | // 'image', 'zip' or 'both'. Default: 'image'. |
| 275 | Payload_type *string |
| 276 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 277 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 278 | // or an android_app_certificate module name in the form ":module". |
| 279 | Certificate *string |
| 280 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 281 | // Whether this APEX is installable to one of the partitions. Default: true. |
| 282 | Installable *bool |
| 283 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 284 | // For native libraries and binaries, use the vendor variant instead of the core (platform) variant. |
| 285 | // Default is false. |
| 286 | Use_vendor *bool |
| 287 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 288 | // For telling the apex to ignore special handling for system libraries such as bionic. Default is false. |
| 289 | Ignore_system_library_special_case *bool |
| 290 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 291 | Multilib apexMultilibProperties |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 292 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 293 | // List of sanitizer names that this APEX is enabled for |
| 294 | SanitizerNames []string `blueprint:"mutated"` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 295 | |
| 296 | // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false. |
| 297 | Provide_cpp_shared_libs *bool |
| 298 | |
| 299 | // List of providing APEXes' names so that this APEX can depend on provided shared libraries. |
| 300 | Uses []string |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | type apexTargetBundleProperties struct { |
| 304 | Target struct { |
| 305 | // Multilib properties only for android. |
| 306 | Android struct { |
| 307 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 308 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 309 | // Multilib properties only for host. |
| 310 | Host struct { |
| 311 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 312 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 313 | // Multilib properties only for host linux_bionic. |
| 314 | Linux_bionic struct { |
| 315 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 316 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 317 | // Multilib properties only for host linux_glibc. |
| 318 | Linux_glibc struct { |
| 319 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 320 | } |
| 321 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 322 | } |
| 323 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 324 | type apexFileClass int |
| 325 | |
| 326 | const ( |
| 327 | etc apexFileClass = iota |
| 328 | nativeSharedLib |
| 329 | nativeExecutable |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 330 | shBinary |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 331 | pyBinary |
| 332 | goBinary |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 333 | javaSharedLib |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 334 | nativeTest |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 335 | ) |
| 336 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 337 | type apexPackaging int |
| 338 | |
| 339 | const ( |
| 340 | imageApex apexPackaging = iota |
| 341 | zipApex |
| 342 | both |
| 343 | ) |
| 344 | |
| 345 | func (a apexPackaging) image() bool { |
| 346 | switch a { |
| 347 | case imageApex, both: |
| 348 | return true |
| 349 | } |
| 350 | return false |
| 351 | } |
| 352 | |
| 353 | func (a apexPackaging) zip() bool { |
| 354 | switch a { |
| 355 | case zipApex, both: |
| 356 | return true |
| 357 | } |
| 358 | return false |
| 359 | } |
| 360 | |
| 361 | func (a apexPackaging) suffix() string { |
| 362 | switch a { |
| 363 | case imageApex: |
| 364 | return imageApexSuffix |
| 365 | case zipApex: |
| 366 | return zipApexSuffix |
| 367 | case both: |
| 368 | panic(fmt.Errorf("must be either zip or image")) |
| 369 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 370 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | func (a apexPackaging) name() string { |
| 375 | switch a { |
| 376 | case imageApex: |
| 377 | return imageApexType |
| 378 | case zipApex: |
| 379 | return zipApexType |
| 380 | case both: |
| 381 | panic(fmt.Errorf("must be either zip or image")) |
| 382 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 383 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 387 | func (class apexFileClass) NameInMake() string { |
| 388 | switch class { |
| 389 | case etc: |
| 390 | return "ETC" |
| 391 | case nativeSharedLib: |
| 392 | return "SHARED_LIBRARIES" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 393 | case nativeExecutable, shBinary, pyBinary, goBinary: |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 394 | return "EXECUTABLES" |
| 395 | case javaSharedLib: |
| 396 | return "JAVA_LIBRARIES" |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 397 | case nativeTest: |
| 398 | return "NATIVE_TESTS" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 399 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 400 | panic(fmt.Errorf("unknown class %d", class)) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
| 404 | type apexFile struct { |
| 405 | builtFile android.Path |
| 406 | moduleName string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 407 | installDir string |
| 408 | class apexFileClass |
Jiyong Park | a889484 | 2018-12-19 17:36:39 +0900 | [diff] [blame] | 409 | module android.Module |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 410 | symlinks []string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 411 | } |
| 412 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 413 | type apexBundle struct { |
| 414 | android.ModuleBase |
| 415 | android.DefaultableModuleBase |
| 416 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 417 | properties apexBundleProperties |
| 418 | targetProperties apexTargetBundleProperties |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 419 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 420 | apexTypes apexPackaging |
| 421 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 422 | bundleModuleFile android.WritablePath |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 423 | outputFiles map[apexPackaging]android.WritablePath |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 424 | installDir android.OutputPath |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 425 | |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 426 | prebuiltFileToDelete string |
| 427 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 428 | public_key_file android.Path |
| 429 | private_key_file android.Path |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 430 | |
| 431 | container_certificate_file android.Path |
| 432 | container_private_key_file android.Path |
| 433 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 434 | // list of files to be included in this apex |
| 435 | filesInfo []apexFile |
| 436 | |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 437 | // list of module names that this APEX is depending on |
| 438 | externalDeps []string |
| 439 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 440 | flattened bool |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 441 | |
| 442 | testApex bool |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 443 | |
| 444 | // intermediate path for apex_manifest.json |
| 445 | manifestOut android.WritablePath |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 446 | } |
| 447 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 448 | func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 449 | native_shared_libs []string, binaries []string, tests []string, |
| 450 | arch string, imageVariation string) { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 451 | // Use *FarVariation* to be able to depend on modules having |
| 452 | // conflicting variations with this module. This is required since |
| 453 | // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64' |
| 454 | // for native shared libs. |
| 455 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 456 | {Mutator: "arch", Variation: arch}, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 457 | {Mutator: "image", Variation: imageVariation}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 458 | {Mutator: "link", Variation: "shared"}, |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 459 | {Mutator: "version", Variation: ""}, // "" is the non-stub variant |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 460 | }, sharedLibTag, native_shared_libs...) |
| 461 | |
| 462 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 463 | {Mutator: "arch", Variation: arch}, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 464 | {Mutator: "image", Variation: imageVariation}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 465 | }, executableTag, binaries...) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 466 | |
| 467 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 468 | {Mutator: "arch", Variation: arch}, |
| 469 | {Mutator: "image", Variation: imageVariation}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 470 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 471 | }, testTag, tests...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 472 | } |
| 473 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 474 | func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { |
| 475 | if ctx.Os().Class == android.Device { |
| 476 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil) |
| 477 | } else { |
| 478 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil) |
| 479 | if ctx.Os().Bionic() { |
| 480 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil) |
| 481 | } else { |
| 482 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil) |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 487 | func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 488 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 489 | targets := ctx.MultiTargets() |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 490 | config := ctx.DeviceConfig() |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 491 | |
| 492 | a.combineProperties(ctx) |
| 493 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 494 | has32BitTarget := false |
| 495 | for _, target := range targets { |
| 496 | if target.Arch.ArchType.Multilib == "lib32" { |
| 497 | has32BitTarget = true |
| 498 | } |
| 499 | } |
| 500 | for i, target := range targets { |
| 501 | // When multilib.* is omitted for native_shared_libs, it implies |
| 502 | // multilib.both. |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 503 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 504 | {Mutator: "arch", Variation: target.String()}, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 505 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 506 | {Mutator: "link", Variation: "shared"}, |
| 507 | }, sharedLibTag, a.properties.Native_shared_libs...) |
| 508 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 509 | // When multilib.* is omitted for tests, it implies |
| 510 | // multilib.both. |
| 511 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 512 | {Mutator: "arch", Variation: target.String()}, |
| 513 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 514 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 515 | }, testTag, a.properties.Tests...) |
| 516 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 517 | // Add native modules targetting both ABIs |
| 518 | addDependenciesForNativeModules(ctx, |
| 519 | a.properties.Multilib.Both.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 520 | a.properties.Multilib.Both.Binaries, |
| 521 | a.properties.Multilib.Both.Tests, |
| 522 | target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 523 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 524 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 525 | isPrimaryAbi := i == 0 |
| 526 | if isPrimaryAbi { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 527 | // When multilib.* is omitted for binaries, it implies |
| 528 | // multilib.first. |
| 529 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 530 | {Mutator: "arch", Variation: target.String()}, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 531 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 532 | }, executableTag, a.properties.Binaries...) |
| 533 | |
| 534 | // Add native modules targetting the first ABI |
| 535 | addDependenciesForNativeModules(ctx, |
| 536 | a.properties.Multilib.First.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 537 | a.properties.Multilib.First.Binaries, |
| 538 | a.properties.Multilib.First.Tests, |
| 539 | target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 540 | a.getImageVariation(config)) |
Jaewoong Jung | b9a1151 | 2019-01-15 10:47:05 -0800 | [diff] [blame] | 541 | |
| 542 | // When multilib.* is omitted for prebuilts, it implies multilib.first. |
| 543 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 544 | {Mutator: "arch", Variation: target.String()}, |
| 545 | }, prebuiltTag, a.properties.Prebuilts...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | switch target.Arch.ArchType.Multilib { |
| 549 | case "lib32": |
| 550 | // Add native modules targetting 32-bit ABI |
| 551 | addDependenciesForNativeModules(ctx, |
| 552 | a.properties.Multilib.Lib32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 553 | a.properties.Multilib.Lib32.Binaries, |
| 554 | a.properties.Multilib.Lib32.Tests, |
| 555 | target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 556 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 557 | |
| 558 | addDependenciesForNativeModules(ctx, |
| 559 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 560 | a.properties.Multilib.Prefer32.Binaries, |
| 561 | a.properties.Multilib.Prefer32.Tests, |
| 562 | target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 563 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 564 | case "lib64": |
| 565 | // Add native modules targetting 64-bit ABI |
| 566 | addDependenciesForNativeModules(ctx, |
| 567 | a.properties.Multilib.Lib64.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 568 | a.properties.Multilib.Lib64.Binaries, |
| 569 | a.properties.Multilib.Lib64.Tests, |
| 570 | target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 571 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 572 | |
| 573 | if !has32BitTarget { |
| 574 | addDependenciesForNativeModules(ctx, |
| 575 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 576 | a.properties.Multilib.Prefer32.Binaries, |
| 577 | a.properties.Multilib.Prefer32.Tests, |
| 578 | target.String(), |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 579 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 580 | } |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 581 | |
| 582 | if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device { |
| 583 | for _, sanitizer := range ctx.Config().SanitizeDevice() { |
| 584 | if sanitizer == "hwaddress" { |
| 585 | addDependenciesForNativeModules(ctx, |
| 586 | []string{"libclang_rt.hwasan-aarch64-android"}, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 587 | nil, nil, target.String(), a.getImageVariation(config)) |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 588 | break |
| 589 | } |
| 590 | } |
| 591 | } |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 592 | } |
| 593 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 594 | } |
| 595 | |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 596 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 597 | {Mutator: "arch", Variation: "android_common"}, |
| 598 | }, javaLibTag, a.properties.Java_libs...) |
| 599 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 600 | if String(a.properties.Key) == "" { |
| 601 | ctx.ModuleErrorf("key is missing") |
| 602 | return |
| 603 | } |
| 604 | ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key)) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 605 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 606 | cert := android.SrcIsModule(a.getCertString(ctx)) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 607 | if cert != "" { |
| 608 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 609 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 610 | } |
| 611 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 612 | func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 613 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName()) |
| 614 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 615 | return ":" + certificate |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 616 | } |
| 617 | return String(a.properties.Certificate) |
| 618 | } |
| 619 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 620 | func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) { |
| 621 | switch tag { |
| 622 | case "": |
| 623 | if file, ok := a.outputFiles[imageApex]; ok { |
| 624 | return android.Paths{file}, nil |
| 625 | } else { |
| 626 | return nil, nil |
| 627 | } |
| 628 | default: |
| 629 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Jiyong Park | 5a83202 | 2018-12-20 09:54:35 +0900 | [diff] [blame] | 630 | } |
Jiyong Park | 74e240b | 2018-11-27 21:27:08 +0900 | [diff] [blame] | 631 | } |
| 632 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 633 | func (a *apexBundle) installable() bool { |
| 634 | return a.properties.Installable == nil || proptools.Bool(a.properties.Installable) |
| 635 | } |
| 636 | |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 637 | func (a *apexBundle) getImageVariation(config android.DeviceConfig) string { |
| 638 | if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 639 | return "vendor" |
| 640 | } else { |
| 641 | return "core" |
| 642 | } |
| 643 | } |
| 644 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 645 | func (a *apexBundle) EnableSanitizer(sanitizerName string) { |
| 646 | if !android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 647 | a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName) |
| 648 | } |
| 649 | } |
| 650 | |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 651 | func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool { |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 652 | if android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 653 | return true |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | // Then follow the global setting |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 657 | globalSanitizerNames := []string{} |
| 658 | if a.Host() { |
| 659 | globalSanitizerNames = ctx.Config().SanitizeHost() |
| 660 | } else { |
| 661 | arches := ctx.Config().SanitizeDeviceArch() |
| 662 | if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) { |
| 663 | globalSanitizerNames = ctx.Config().SanitizeDevice() |
| 664 | } |
| 665 | } |
| 666 | return android.InList(sanitizerName, globalSanitizerNames) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 667 | } |
| 668 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 669 | func getCopyManifestForNativeLibrary(cc *cc.Module, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 670 | // Decide the APEX-local directory by the multilib of the library |
| 671 | // In the future, we may query this to the module. |
| 672 | switch cc.Arch().ArchType.Multilib { |
| 673 | case "lib32": |
| 674 | dirInApex = "lib" |
| 675 | case "lib64": |
| 676 | dirInApex = "lib64" |
| 677 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 678 | dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath()) |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 679 | if !cc.Arch().Native { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 680 | dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String()) |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 681 | } else if cc.Target().NativeBridge == android.NativeBridgeEnabled { |
| 682 | dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 683 | } |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 684 | if handleSpecialLibs { |
| 685 | switch cc.Name() { |
| 686 | case "libc", "libm", "libdl": |
| 687 | // Special case for bionic libs. This is to prevent the bionic libs |
| 688 | // from being included in the search path /apex/com.android.apex/lib. |
| 689 | // This exclusion is required because bionic libs in the runtime APEX |
| 690 | // are available via the legacy paths /system/lib/libc.so, etc. By the |
| 691 | // init process, the bionic libs in the APEX are bind-mounted to the |
| 692 | // legacy paths and thus will be loaded into the default linker namespace. |
| 693 | // If the bionic libs are directly in /apex/com.android.apex/lib then |
| 694 | // the same libs will be again loaded to the runtime linker namespace, |
| 695 | // which will result double loading of bionic libs that isn't supported. |
| 696 | dirInApex = filepath.Join(dirInApex, "bionic") |
| 697 | } |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 698 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 699 | |
| 700 | fileToCopy = cc.OutputFile().Path() |
| 701 | return |
| 702 | } |
| 703 | |
| 704 | func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 705 | dirInApex = filepath.Join("bin", cc.RelativeInstallPath()) |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 706 | if !cc.Arch().Native { |
Jiyong Park | acbf6c7 | 2019-07-09 16:19:16 +0900 | [diff] [blame] | 707 | dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String()) |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 708 | } else if cc.Target().NativeBridge == android.NativeBridgeEnabled { |
| 709 | dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath) |
Jiyong Park | acbf6c7 | 2019-07-09 16:19:16 +0900 | [diff] [blame] | 710 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 711 | fileToCopy = cc.OutputFile().Path() |
| 712 | return |
| 713 | } |
| 714 | |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 715 | func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) { |
| 716 | dirInApex = "bin" |
| 717 | fileToCopy = py.HostToolPath().Path() |
| 718 | return |
| 719 | } |
| 720 | func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) { |
| 721 | dirInApex = "bin" |
| 722 | s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath()) |
| 723 | if err != nil { |
| 724 | ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath()) |
| 725 | return |
| 726 | } |
| 727 | fileToCopy = android.PathForOutput(ctx, s) |
| 728 | return |
| 729 | } |
| 730 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 731 | func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) { |
| 732 | dirInApex = filepath.Join("bin", sh.SubDir()) |
| 733 | fileToCopy = sh.OutputFile() |
| 734 | return |
| 735 | } |
| 736 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 737 | func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) { |
| 738 | dirInApex = "javalib" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 739 | fileToCopy = java.DexJarFile() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 740 | return |
| 741 | } |
| 742 | |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame^] | 743 | func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) { |
| 744 | dirInApex = "javalib" |
| 745 | // The output is only one, but for some reason, ImplementationJars returns Paths, not Path |
| 746 | implJars := java.ImplementationJars() |
| 747 | if len(implJars) != 1 { |
| 748 | panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s", |
| 749 | strings.Join(implJars.Strings(), ", "))) |
| 750 | } |
| 751 | fileToCopy = implJars[0] |
| 752 | return |
| 753 | } |
| 754 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 755 | func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) { |
| 756 | dirInApex = filepath.Join("etc", prebuilt.SubDir()) |
| 757 | fileToCopy = prebuilt.OutputFile() |
| 758 | return |
| 759 | } |
| 760 | |
| 761 | func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 762 | filesInfo := []apexFile{} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 763 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 764 | if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" { |
| 765 | a.apexTypes = imageApex |
| 766 | } else if *a.properties.Payload_type == "zip" { |
| 767 | a.apexTypes = zipApex |
| 768 | } else if *a.properties.Payload_type == "both" { |
| 769 | a.apexTypes = both |
| 770 | } else { |
| 771 | ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type) |
| 772 | return |
| 773 | } |
| 774 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 775 | if len(a.properties.Tests) > 0 && !a.testApex { |
| 776 | ctx.PropertyErrorf("tests", "property not allowed in apex module type") |
| 777 | return |
| 778 | } |
| 779 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 780 | handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case) |
| 781 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 782 | // native lib dependencies |
| 783 | var provideNativeLibs []string |
| 784 | var requireNativeLibs []string |
| 785 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 786 | // Check if "uses" requirements are met with dependent apexBundles |
| 787 | var providedNativeSharedLibs []string |
| 788 | useVendor := proptools.Bool(a.properties.Use_vendor) |
| 789 | ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) { |
| 790 | if ctx.OtherModuleDependencyTag(m) != usesTag { |
| 791 | return |
| 792 | } |
| 793 | otherName := ctx.OtherModuleName(m) |
| 794 | other, ok := m.(*apexBundle) |
| 795 | if !ok { |
| 796 | ctx.PropertyErrorf("uses", "%q is not a provider", otherName) |
| 797 | return |
| 798 | } |
| 799 | if proptools.Bool(other.properties.Use_vendor) != useVendor { |
| 800 | ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName) |
| 801 | return |
| 802 | } |
| 803 | if !proptools.Bool(other.properties.Provide_cpp_shared_libs) { |
| 804 | ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName) |
| 805 | return |
| 806 | } |
| 807 | providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...) |
| 808 | }) |
| 809 | |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 810 | ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 811 | depTag := ctx.OtherModuleDependencyTag(child) |
| 812 | depName := ctx.OtherModuleName(child) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 813 | if _, ok := parent.(*apexBundle); ok { |
| 814 | // direct dependencies |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 815 | switch depTag { |
| 816 | case sharedLibTag: |
| 817 | if cc, ok := child.(*cc.Module); ok { |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 818 | if cc.HasStubsVariants() { |
| 819 | provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base()) |
| 820 | } |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 821 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 822 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 823 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 824 | } else { |
| 825 | 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] | 826 | } |
| 827 | case executableTag: |
| 828 | if cc, ok := child.(*cc.Module); ok { |
| 829 | fileToCopy, dirInApex := getCopyManifestForExecutable(cc) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 830 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 831 | return true |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 832 | } else if sh, ok := child.(*android.ShBinary); ok { |
| 833 | fileToCopy, dirInApex := getCopyManifestForShBinary(sh) |
| 834 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil}) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 835 | } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() { |
| 836 | fileToCopy, dirInApex := getCopyManifestForPyBinary(py) |
| 837 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil}) |
| 838 | } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() { |
| 839 | fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb) |
| 840 | // NB: Since go binaries are static we don't need the module for anything here, which is |
| 841 | // good since the go tool is a blueprint.Module not an android.Module like we would |
| 842 | // normally use. |
| 843 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil}) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 844 | } else { |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 845 | ctx.PropertyErrorf("binaries", "%q is neither cc_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 846 | } |
| 847 | case javaLibTag: |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame^] | 848 | if javaLib, ok := child.(*java.Library); ok { |
| 849 | fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 850 | if fileToCopy == nil { |
| 851 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 852 | } else { |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame^] | 853 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil}) |
| 854 | } |
| 855 | return true |
| 856 | } else if javaLib, ok := child.(*java.Import); ok { |
| 857 | fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib) |
| 858 | if fileToCopy == nil { |
| 859 | ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName) |
| 860 | } else { |
| 861 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil}) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 862 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 863 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 864 | } else { |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame^] | 865 | ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child)) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 866 | } |
| 867 | case prebuiltTag: |
| 868 | if prebuilt, ok := child.(*android.PrebuiltEtc); ok { |
| 869 | fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 870 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 871 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 872 | } else { |
| 873 | ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName) |
| 874 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 875 | case testTag: |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 876 | if ccTest, ok := child.(*cc.Module); ok { |
| 877 | if ccTest.IsTestPerSrcAllTestsVariation() { |
| 878 | // Multiple-output test module (where `test_per_src: true`). |
| 879 | // |
| 880 | // `ccTest` is the "" ("all tests") variation of a `test_per_src` module. |
| 881 | // We do not add this variation to `filesInfo`, as it has no output; |
| 882 | // however, we do add the other variations of this module as indirect |
| 883 | // dependencies (see below). |
| 884 | return true |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 885 | } else { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 886 | // Single-output test module (where `test_per_src: false`). |
| 887 | fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest) |
| 888 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil}) |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 889 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 890 | return true |
| 891 | } else { |
| 892 | ctx.PropertyErrorf("tests", "%q is not a cc module", depName) |
| 893 | } |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 894 | case keyTag: |
| 895 | if key, ok := child.(*apexKey); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 896 | a.private_key_file = key.private_key_file |
| 897 | a.public_key_file = key.public_key_file |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 898 | return false |
| 899 | } else { |
| 900 | ctx.PropertyErrorf("key", "%q is not an apex_key module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 901 | } |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 902 | case certificateTag: |
| 903 | if dep, ok := child.(*java.AndroidAppCertificate); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 904 | a.container_certificate_file = dep.Certificate.Pem |
| 905 | a.container_private_key_file = dep.Certificate.Key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 906 | return false |
| 907 | } else { |
| 908 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName) |
| 909 | } |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 910 | case android.PrebuiltDepTag: |
| 911 | // If the prebuilt is force disabled, remember to delete the prebuilt file |
| 912 | // that might have been installed in the previous builds |
| 913 | if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() { |
| 914 | a.prebuiltFileToDelete = prebuilt.InstallFilename() |
| 915 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 916 | } |
| 917 | } else { |
| 918 | // indirect dependencies |
| 919 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && am.IsInstallableToApex() { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 920 | // We cannot use a switch statement on `depTag` here as the checked |
| 921 | // tags used below are private (e.g. `cc.sharedDepTag`). |
| 922 | if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) { |
| 923 | if cc, ok := child.(*cc.Module); ok { |
| 924 | if android.InList(cc.Name(), providedNativeSharedLibs) { |
| 925 | // If we're using a shared library which is provided from other APEX, |
| 926 | // don't include it in this APEX |
| 927 | return false |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 928 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 929 | if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) { |
| 930 | // If the dependency is a stubs lib, don't include it in this APEX, |
| 931 | // but make sure that the lib is installed on the device. |
| 932 | // In case no APEX is having the lib, the lib is installed to the system |
| 933 | // partition. |
| 934 | // |
| 935 | // Always include if we are a host-apex however since those won't have any |
| 936 | // system libraries. |
| 937 | if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) { |
| 938 | a.externalDeps = append(a.externalDeps, cc.Name()) |
| 939 | } |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 940 | requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base()) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 941 | // Don't track further |
| 942 | return false |
| 943 | } |
| 944 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs) |
| 945 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
| 946 | return true |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 947 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 948 | } else if cc.IsTestPerSrcDepTag(depTag) { |
| 949 | if cc, ok := child.(*cc.Module); ok { |
| 950 | fileToCopy, dirInApex := getCopyManifestForExecutable(cc) |
| 951 | // Handle modules created as `test_per_src` variations of a single test module: |
| 952 | // use the name of the generated test binary (`fileToCopy`) instead of the name |
| 953 | // of the original test module (`depName`, shared by all `test_per_src` |
| 954 | // variations of that module). |
| 955 | moduleName := filepath.Base(fileToCopy.String()) |
| 956 | filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil}) |
| 957 | return true |
| 958 | } |
| 959 | } else { |
| 960 | ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | } |
| 964 | return false |
| 965 | }) |
| 966 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 967 | a.flattened = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild() |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 968 | if a.private_key_file == nil { |
Jiyong Park | fa0a373 | 2018-11-09 05:52:26 +0900 | [diff] [blame] | 969 | ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key)) |
| 970 | return |
| 971 | } |
| 972 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 973 | // remove duplicates in filesInfo |
| 974 | removeDup := func(filesInfo []apexFile) []apexFile { |
| 975 | encountered := make(map[android.Path]bool) |
| 976 | result := []apexFile{} |
| 977 | for _, f := range filesInfo { |
| 978 | if !encountered[f.builtFile] { |
| 979 | encountered[f.builtFile] = true |
| 980 | result = append(result, f) |
| 981 | } |
| 982 | } |
| 983 | return result |
| 984 | } |
| 985 | filesInfo = removeDup(filesInfo) |
| 986 | |
| 987 | // to have consistent build rules |
| 988 | sort.Slice(filesInfo, func(i, j int) bool { |
| 989 | return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String() |
| 990 | }) |
| 991 | |
| 992 | // prepend the name of this APEX to the module names. These names will be the names of |
| 993 | // modules that will be defined if the APEX is flattened. |
| 994 | for i := range filesInfo { |
| 995 | filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName |
| 996 | } |
| 997 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 998 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 999 | a.filesInfo = filesInfo |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1000 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1001 | a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json") |
| 1002 | // put dependency({provide|require}NativeLibs) in apex_manifest.json |
| 1003 | manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) |
| 1004 | provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs) |
| 1005 | requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs)) |
| 1006 | ctx.Build(pctx, android.BuildParams{ |
| 1007 | Rule: injectApexDependency, |
| 1008 | Input: manifestSrc, |
| 1009 | Output: a.manifestOut, |
| 1010 | Args: map[string]string{ |
| 1011 | "provideNativeLibs": strings.Join(provideNativeLibs, " "), |
| 1012 | "requireNativeLibs": strings.Join(requireNativeLibs, " "), |
| 1013 | }, |
| 1014 | }) |
| 1015 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1016 | if a.apexTypes.zip() { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1017 | a.buildUnflattenedApex(ctx, zipApex) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1018 | } |
| 1019 | if a.apexTypes.image() { |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1020 | // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex() |
Roland Levillain | dfe75b3 | 2019-07-23 16:53:32 +0100 | [diff] [blame] | 1021 | // is true. This is to support referencing APEX via ":<module_name>" syntax |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1022 | // in other modules. It is in AndroidMk where the selection of flattened |
| 1023 | // or unflattened APEX is made. |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1024 | a.buildUnflattenedApex(ctx, imageApex) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1025 | a.buildFlattenedApex(ctx) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 1029 | func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath { |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1030 | noticeFiles := []android.Path{} |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1031 | for _, f := range a.filesInfo { |
| 1032 | if f.module != nil { |
| 1033 | notice := f.module.NoticeFile() |
| 1034 | if notice.Valid() { |
| 1035 | noticeFiles = append(noticeFiles, notice.Path()) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | // append the notice file specified in the apex module itself |
| 1040 | if a.NoticeFile().Valid() { |
| 1041 | noticeFiles = append(noticeFiles, a.NoticeFile().Path()) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1042 | } |
| 1043 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 1044 | if len(noticeFiles) == 0 { |
| 1045 | return android.OptionalPath{} |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1046 | } |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 1047 | |
Jaewoong Jung | 9877279 | 2019-07-01 17:15:13 -0700 | [diff] [blame] | 1048 | return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1049 | } |
| 1050 | |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1051 | func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) { |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1052 | cert := String(a.properties.Certificate) |
| 1053 | if cert != "" && android.SrcIsModule(cert) == "" { |
| 1054 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1055 | a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem") |
| 1056 | a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8") |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1057 | } else if cert == "" { |
| 1058 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1059 | a.container_certificate_file = pem |
| 1060 | a.container_private_key_file = key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1061 | } |
| 1062 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1063 | var abis []string |
| 1064 | for _, target := range ctx.MultiTargets() { |
| 1065 | if len(target.Arch.Abi) > 0 { |
| 1066 | abis = append(abis, target.Arch.Abi[0]) |
| 1067 | } |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 1068 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1069 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1070 | abis = android.FirstUniqueStrings(abis) |
| 1071 | |
| 1072 | suffix := apexType.suffix() |
| 1073 | unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1074 | |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 1075 | filesToCopy := []android.Path{} |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1076 | for _, f := range a.filesInfo { |
| 1077 | filesToCopy = append(filesToCopy, f.builtFile) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1078 | } |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 1079 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1080 | copyCommands := []string{} |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1081 | for i, src := range filesToCopy { |
| 1082 | dest := filepath.Join(a.filesInfo[i].installDir, src.Base()) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1083 | dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1084 | copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path)) |
| 1085 | copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 1086 | for _, sym := range a.filesInfo[i].symlinks { |
| 1087 | symlinkDest := filepath.Join(filepath.Dir(dest_path), sym) |
| 1088 | copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest) |
| 1089 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1090 | } |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 1091 | implicitInputs := append(android.Paths(nil), filesToCopy...) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1092 | implicitInputs = append(implicitInputs, a.manifestOut) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1093 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1094 | outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String() |
| 1095 | prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1096 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1097 | if apexType.image() { |
| 1098 | // files and dirs that will be created in APEX |
| 1099 | var readOnlyPaths []string |
| 1100 | var executablePaths []string // this also includes dirs |
| 1101 | for _, f := range a.filesInfo { |
| 1102 | pathInApex := filepath.Join(f.installDir, f.builtFile.Base()) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1103 | if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1104 | executablePaths = append(executablePaths, pathInApex) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 1105 | for _, s := range f.symlinks { |
Jiyong Park | c80b5fa | 2019-07-20 14:24:33 +0900 | [diff] [blame] | 1106 | executablePaths = append(executablePaths, filepath.Join(f.installDir, s)) |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 1107 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1108 | } else { |
| 1109 | readOnlyPaths = append(readOnlyPaths, pathInApex) |
| 1110 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1111 | dir := f.installDir |
| 1112 | for !android.InList(dir, executablePaths) && dir != "" { |
| 1113 | executablePaths = append(executablePaths, dir) |
| 1114 | dir, _ = filepath.Split(dir) // move up to the parent |
| 1115 | if len(dir) > 0 { |
| 1116 | // remove trailing slash |
| 1117 | dir = dir[:len(dir)-1] |
| 1118 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | sort.Strings(readOnlyPaths) |
| 1122 | sort.Strings(executablePaths) |
| 1123 | cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config") |
| 1124 | ctx.Build(pctx, android.BuildParams{ |
| 1125 | Rule: generateFsConfig, |
| 1126 | Output: cannedFsConfig, |
| 1127 | Description: "generate fs config", |
| 1128 | Args: map[string]string{ |
| 1129 | "ro_paths": strings.Join(readOnlyPaths, " "), |
| 1130 | "exec_paths": strings.Join(executablePaths, " "), |
| 1131 | }, |
| 1132 | }) |
| 1133 | |
| 1134 | fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName()) |
| 1135 | fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts" |
| 1136 | fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath) |
| 1137 | if !fileContextsOptionalPath.Valid() { |
| 1138 | ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath) |
| 1139 | return |
| 1140 | } |
| 1141 | fileContexts := fileContextsOptionalPath.Path() |
| 1142 | |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 1143 | optFlags := []string{} |
| 1144 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1145 | // Additional implicit inputs. |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 1146 | implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file) |
| 1147 | optFlags = append(optFlags, "--pubkey "+a.public_key_file.String()) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1148 | |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 1149 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
| 1150 | if overridden { |
| 1151 | optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName) |
| 1152 | } |
| 1153 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 1154 | if a.properties.AndroidManifest != nil { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1155 | androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest)) |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 1156 | implicitInputs = append(implicitInputs, androidManifestFile) |
| 1157 | optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String()) |
| 1158 | } |
| 1159 | |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 1160 | targetSdkVersion := ctx.Config().DefaultAppTargetSdk() |
| 1161 | if targetSdkVersion == ctx.Config().PlatformSdkCodename() && |
| 1162 | ctx.Config().UnbundledBuild() && |
| 1163 | !ctx.Config().UnbundledBuildUsePrebuiltSdks() && |
| 1164 | ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") { |
| 1165 | apiFingerprint := java.ApiFingerprintPath(ctx) |
| 1166 | targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String()) |
| 1167 | implicitInputs = append(implicitInputs, apiFingerprint) |
| 1168 | } |
| 1169 | optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion) |
| 1170 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 1171 | noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix) |
| 1172 | if noticeFile.Valid() { |
| 1173 | // If there's a NOTICE file, embed it as an asset file in the APEX. |
| 1174 | implicitInputs = append(implicitInputs, noticeFile.Path()) |
| 1175 | optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String())) |
| 1176 | } |
| 1177 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1178 | ctx.Build(pctx, android.BuildParams{ |
| 1179 | Rule: apexRule, |
| 1180 | Implicits: implicitInputs, |
| 1181 | Output: unsignedOutputFile, |
| 1182 | Description: "apex (" + apexType.name() + ")", |
| 1183 | Args: map[string]string{ |
| 1184 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
| 1185 | "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(), |
| 1186 | "copy_commands": strings.Join(copyCommands, " && "), |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1187 | "manifest": a.manifestOut.String(), |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1188 | "file_contexts": fileContexts.String(), |
| 1189 | "canned_fs_config": cannedFsConfig.String(), |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1190 | "key": a.private_key_file.String(), |
Jiyong Park | 835d82b | 2018-12-27 16:04:18 +0900 | [diff] [blame] | 1191 | "opt_flags": strings.Join(optFlags, " "), |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1192 | }, |
| 1193 | }) |
| 1194 | |
| 1195 | apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix) |
| 1196 | bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip") |
| 1197 | a.bundleModuleFile = bundleModuleFile |
| 1198 | |
| 1199 | ctx.Build(pctx, android.BuildParams{ |
| 1200 | Rule: apexProtoConvertRule, |
| 1201 | Input: unsignedOutputFile, |
| 1202 | Output: apexProtoFile, |
| 1203 | Description: "apex proto convert", |
| 1204 | }) |
| 1205 | |
| 1206 | ctx.Build(pctx, android.BuildParams{ |
| 1207 | Rule: apexBundleRule, |
| 1208 | Input: apexProtoFile, |
| 1209 | Output: a.bundleModuleFile, |
| 1210 | Description: "apex bundle module", |
| 1211 | Args: map[string]string{ |
| 1212 | "abi": strings.Join(abis, "."), |
| 1213 | }, |
| 1214 | }) |
| 1215 | } else { |
| 1216 | ctx.Build(pctx, android.BuildParams{ |
| 1217 | Rule: zipApexRule, |
| 1218 | Implicits: implicitInputs, |
| 1219 | Output: unsignedOutputFile, |
| 1220 | Description: "apex (" + apexType.name() + ")", |
| 1221 | Args: map[string]string{ |
| 1222 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
| 1223 | "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(), |
| 1224 | "copy_commands": strings.Join(copyCommands, " && "), |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1225 | "manifest": a.manifestOut.String(), |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1226 | }, |
| 1227 | }) |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1228 | } |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1229 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1230 | a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1231 | ctx.Build(pctx, android.BuildParams{ |
| 1232 | Rule: java.Signapk, |
| 1233 | Description: "signapk", |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1234 | Output: a.outputFiles[apexType], |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1235 | Input: unsignedOutputFile, |
Dan Willemsen | dd651fa | 2019-06-13 04:48:54 +0000 | [diff] [blame] | 1236 | Implicits: []android.Path{ |
| 1237 | a.container_certificate_file, |
| 1238 | a.container_private_key_file, |
| 1239 | }, |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1240 | Args: map[string]string{ |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1241 | "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(), |
Jiyong Park | bfe64a1 | 2018-11-22 02:51:54 +0900 | [diff] [blame] | 1242 | "flags": "-a 4096", //alignment |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1243 | }, |
| 1244 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1245 | |
| 1246 | // Install to $OUT/soong/{target,host}/.../apex |
Alex Light | 2a2561f | 2019-02-12 16:59:09 -0800 | [diff] [blame] | 1247 | if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1248 | ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType]) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1249 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1250 | } |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1251 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1252 | func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1253 | if a.installable() { |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 1254 | // For flattened APEX, do nothing but make sure that apex_manifest.json and apex_pubkey are also copied along |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1255 | // with other ordinary files. |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1256 | a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil}) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1257 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 1258 | // rename to apex_pubkey |
| 1259 | copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey") |
| 1260 | ctx.Build(pctx, android.BuildParams{ |
| 1261 | Rule: android.Cp, |
| 1262 | Input: a.public_key_file, |
| 1263 | Output: copiedPubkey, |
| 1264 | }) |
| 1265 | a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil}) |
| 1266 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1267 | if ctx.Config().FlattenApex() { |
| 1268 | for _, fi := range a.filesInfo { |
| 1269 | dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir) |
Alex Light | f4857cf | 2019-02-22 13:00:04 -0800 | [diff] [blame] | 1270 | target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile) |
| 1271 | for _, sym := range fi.symlinks { |
| 1272 | ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target) |
| 1273 | } |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 1274 | } |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1275 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1276 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | func (a *apexBundle) AndroidMk() android.AndroidMkData { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1280 | writers := []android.AndroidMkData{} |
| 1281 | if a.apexTypes.image() { |
| 1282 | writers = append(writers, a.androidMkForType(imageApex)) |
| 1283 | } |
| 1284 | if a.apexTypes.zip() { |
| 1285 | writers = append(writers, a.androidMkForType(zipApex)) |
| 1286 | } |
| 1287 | return android.AndroidMkData{ |
| 1288 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 1289 | for _, data := range writers { |
| 1290 | data.Custom(w, name, prefix, moduleDir, data) |
| 1291 | } |
| 1292 | }} |
| 1293 | } |
| 1294 | |
Alex Light | f1801bc | 2019-02-13 11:10:07 -0800 | [diff] [blame] | 1295 | func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1296 | moduleNames := []string{} |
| 1297 | |
| 1298 | for _, fi := range a.filesInfo { |
| 1299 | if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake { |
| 1300 | continue |
| 1301 | } |
| 1302 | if !android.InList(fi.moduleName, moduleNames) { |
| 1303 | moduleNames = append(moduleNames, fi.moduleName) |
| 1304 | } |
| 1305 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1306 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 1307 | fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName) |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1308 | // /apex/<name>/{lib|framework|...} |
| 1309 | pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", |
| 1310 | proptools.StringDefault(a.properties.Apex_name, name), fi.installDir) |
Alex Light | f1801bc | 2019-02-13 11:10:07 -0800 | [diff] [blame] | 1311 | if a.flattened && apexType.image() { |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1312 | // /system/apex/<name>/{lib|framework|...} |
| 1313 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", |
| 1314 | a.installDir.RelPathString(), name, fi.installDir)) |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1315 | fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated) |
Alex Light | f4857cf | 2019-02-22 13:00:04 -0800 | [diff] [blame] | 1316 | if len(fi.symlinks) > 0 { |
| 1317 | fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " ")) |
| 1318 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 1319 | |
| 1320 | if fi.module != nil && fi.module.NoticeFile().Valid() { |
| 1321 | fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String()) |
| 1322 | } |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1323 | } else { |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 1324 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1325 | } |
| 1326 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String()) |
| 1327 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake()) |
| 1328 | if fi.module != nil { |
| 1329 | archStr := fi.module.Target().Arch.ArchType.String() |
| 1330 | host := false |
| 1331 | switch fi.module.Target().Os.Class { |
| 1332 | case android.Host: |
| 1333 | if archStr != "common" { |
| 1334 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) |
| 1335 | } |
| 1336 | host = true |
| 1337 | case android.HostCross: |
| 1338 | if archStr != "common" { |
| 1339 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) |
| 1340 | } |
| 1341 | host = true |
| 1342 | case android.Device: |
| 1343 | if archStr != "common" { |
| 1344 | fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr) |
| 1345 | } |
| 1346 | } |
| 1347 | if host { |
| 1348 | makeOs := fi.module.Target().Os.String() |
| 1349 | if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic { |
| 1350 | makeOs = "linux" |
| 1351 | } |
| 1352 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs) |
| 1353 | fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") |
| 1354 | } |
| 1355 | } |
| 1356 | if fi.class == javaSharedLib { |
| 1357 | javaModule := fi.module.(*java.Library) |
| 1358 | // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore |
| 1359 | // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise |
| 1360 | // we will have foo.jar.jar |
| 1361 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar")) |
| 1362 | fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String()) |
| 1363 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String()) |
| 1364 | fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String()) |
| 1365 | fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") |
| 1366 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") |
| 1367 | } else if fi.class == nativeSharedLib || fi.class == nativeExecutable { |
| 1368 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base()) |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 1369 | if cc, ok := fi.module.(*cc.Module); ok { |
| 1370 | if cc.UnstrippedOutputFile() != nil { |
| 1371 | fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String()) |
| 1372 | } |
| 1373 | cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1374 | } |
| 1375 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk") |
| 1376 | } else { |
| 1377 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base()) |
| 1378 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
| 1379 | } |
| 1380 | } |
| 1381 | return moduleNames |
| 1382 | } |
| 1383 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1384 | func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData { |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1385 | return android.AndroidMkData{ |
| 1386 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 1387 | moduleNames := []string{} |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1388 | if a.installable() { |
Alex Light | f1801bc | 2019-02-13 11:10:07 -0800 | [diff] [blame] | 1389 | moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1390 | } |
| 1391 | |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1392 | if a.flattened && apexType.image() { |
| 1393 | // Only image APEXes can be flattened. |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1394 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1395 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 1396 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1397 | if len(moduleNames) > 0 { |
| 1398 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " ")) |
| 1399 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1400 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1401 | } else { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1402 | // zip-apex is the less common type so have the name refer to the image-apex |
| 1403 | // only and use {name}.zip if you want the zip-apex |
| 1404 | if apexType == zipApex && a.apexTypes == both { |
| 1405 | name = name + ".zip" |
| 1406 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1407 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 1408 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 1409 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) |
| 1410 | 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] | 1411 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String()) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1412 | 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] | 1413 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix()) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1414 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable()) |
Jiyong Park | 9442726 | 2019-02-05 23:18:47 +0900 | [diff] [blame] | 1415 | if len(moduleNames) > 0 { |
| 1416 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " ")) |
| 1417 | } |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 1418 | if len(a.externalDeps) > 0 { |
| 1419 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " ")) |
| 1420 | } |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1421 | if a.prebuiltFileToDelete != "" { |
| 1422 | fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+ |
| 1423 | filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete)) |
| 1424 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1425 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 1426 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1427 | if apexType == imageApex { |
| 1428 | fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String()) |
| 1429 | } |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 1430 | } |
| 1431 | }} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1432 | } |
| 1433 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1434 | func testApexBundleFactory() android.Module { |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1435 | return ApexBundleFactory(true /*testApex*/) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | func apexBundleFactory() android.Module { |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1439 | return ApexBundleFactory(false /*testApex*/) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | func ApexBundleFactory(testApex bool) android.Module { |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1443 | module := &apexBundle{ |
| 1444 | outputFiles: map[apexPackaging]android.WritablePath{}, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1445 | testApex: testApex, |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1446 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1447 | module.AddProperties(&module.properties) |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1448 | module.AddProperties(&module.targetProperties) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1449 | 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] | 1450 | return class == android.Device && ctx.Config().DevicePrefer32BitExecutables() |
| 1451 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1452 | android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1453 | android.InitDefaultableModule(module) |
| 1454 | return module |
| 1455 | } |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1456 | |
| 1457 | // |
| 1458 | // Defaults |
| 1459 | // |
| 1460 | type Defaults struct { |
| 1461 | android.ModuleBase |
| 1462 | android.DefaultsModuleBase |
| 1463 | } |
| 1464 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1465 | func defaultsFactory() android.Module { |
| 1466 | return DefaultsFactory() |
| 1467 | } |
| 1468 | |
| 1469 | func DefaultsFactory(props ...interface{}) android.Module { |
| 1470 | module := &Defaults{} |
| 1471 | |
| 1472 | module.AddProperties(props...) |
| 1473 | module.AddProperties( |
| 1474 | &apexBundleProperties{}, |
| 1475 | &apexTargetBundleProperties{}, |
| 1476 | ) |
| 1477 | |
| 1478 | android.InitDefaultsModule(module) |
| 1479 | return module |
| 1480 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1481 | |
| 1482 | // |
| 1483 | // Prebuilt APEX |
| 1484 | // |
| 1485 | type Prebuilt struct { |
| 1486 | android.ModuleBase |
| 1487 | prebuilt android.Prebuilt |
| 1488 | |
| 1489 | properties PrebuiltProperties |
| 1490 | |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1491 | inputApex android.Path |
| 1492 | installDir android.OutputPath |
| 1493 | installFilename string |
Nikita Ioffe | 89ecd59 | 2019-04-05 02:10:45 +0100 | [diff] [blame] | 1494 | outputApex android.WritablePath |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | type PrebuiltProperties struct { |
| 1498 | // the path to the prebuilt .apex file to import. |
Jiyong Park | 2cb5288 | 2019-07-07 12:39:16 +0900 | [diff] [blame] | 1499 | Source string `blueprint:"mutated"` |
| 1500 | ForceDisable bool `blueprint:"mutated"` |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1501 | |
| 1502 | Src *string |
| 1503 | Arch struct { |
| 1504 | Arm struct { |
| 1505 | Src *string |
| 1506 | } |
| 1507 | Arm64 struct { |
| 1508 | Src *string |
| 1509 | } |
| 1510 | X86 struct { |
| 1511 | Src *string |
| 1512 | } |
| 1513 | X86_64 struct { |
| 1514 | Src *string |
| 1515 | } |
| 1516 | } |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1517 | |
| 1518 | Installable *bool |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1519 | // Optional name for the installed apex. If unspecified, name of the |
| 1520 | // module is used as the file name |
| 1521 | Filename *string |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1522 | |
| 1523 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 1524 | // (in Make or Soong). |
| 1525 | // This does not completely prevent installation of the overridden binaries, but if both |
| 1526 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 1527 | // from PRODUCT_PACKAGES. |
| 1528 | Overrides []string |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | func (p *Prebuilt) installable() bool { |
| 1532 | return p.properties.Installable == nil || proptools.Bool(p.properties.Installable) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | e3ef3c8 | 2019-07-15 15:31:16 +0900 | [diff] [blame] | 1536 | // If the device is configured to use flattened APEX, force disable the prebuilt because |
| 1537 | // the prebuilt is a non-flattened one. |
| 1538 | forceDisable := ctx.Config().FlattenApex() |
| 1539 | |
| 1540 | // Force disable the prebuilts when we are doing unbundled build. We do unbundled build |
| 1541 | // to build the prebuilts themselves. |
Jiyong Park | ca8992e | 2019-07-17 08:21:36 +0900 | [diff] [blame] | 1542 | forceDisable = forceDisable || ctx.Config().UnbundledBuild() |
Jiyong Park | 50b81e5 | 2019-07-11 11:24:41 +0900 | [diff] [blame] | 1543 | |
Kun Niu | 10c9f83 | 2019-07-29 16:28:57 -0700 | [diff] [blame] | 1544 | // Force disable the prebuilts when coverage is enabled. |
| 1545 | forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled() |
| 1546 | forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") |
| 1547 | |
Jiyong Park | 50b81e5 | 2019-07-11 11:24:41 +0900 | [diff] [blame] | 1548 | // b/137216042 don't use prebuilts when address sanitizer is on |
| 1549 | forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) || |
| 1550 | android.InList("hwaddress", ctx.Config().SanitizeDevice()) |
| 1551 | |
| 1552 | if forceDisable && p.prebuilt.SourceExists() { |
Jiyong Park | 2cb5288 | 2019-07-07 12:39:16 +0900 | [diff] [blame] | 1553 | p.properties.ForceDisable = true |
| 1554 | return |
| 1555 | } |
| 1556 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1557 | // This is called before prebuilt_select and prebuilt_postdeps mutators |
| 1558 | // The mutators requires that src to be set correctly for each arch so that |
| 1559 | // arch variants are disabled when src is not provided for the arch. |
| 1560 | if len(ctx.MultiTargets()) != 1 { |
| 1561 | ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex") |
| 1562 | return |
| 1563 | } |
| 1564 | var src string |
| 1565 | switch ctx.MultiTargets()[0].Arch.ArchType { |
| 1566 | case android.Arm: |
| 1567 | src = String(p.properties.Arch.Arm.Src) |
| 1568 | case android.Arm64: |
| 1569 | src = String(p.properties.Arch.Arm64.Src) |
| 1570 | case android.X86: |
| 1571 | src = String(p.properties.Arch.X86.Src) |
| 1572 | case android.X86_64: |
| 1573 | src = String(p.properties.Arch.X86_64.Src) |
| 1574 | default: |
| 1575 | ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String()) |
| 1576 | return |
| 1577 | } |
| 1578 | if src == "" { |
| 1579 | src = String(p.properties.Src) |
| 1580 | } |
| 1581 | p.properties.Source = src |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1584 | func (p *Prebuilt) isForceDisabled() bool { |
| 1585 | return p.properties.ForceDisable |
| 1586 | } |
| 1587 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1588 | func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) { |
| 1589 | switch tag { |
| 1590 | case "": |
| 1591 | return android.Paths{p.outputApex}, nil |
| 1592 | default: |
| 1593 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 1594 | } |
Nikita Ioffe | 89ecd59 | 2019-04-05 02:10:45 +0100 | [diff] [blame] | 1595 | } |
| 1596 | |
Jiyong Park | 4d27704 | 2019-04-23 18:00:10 +0900 | [diff] [blame] | 1597 | func (p *Prebuilt) InstallFilename() string { |
| 1598 | return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix) |
| 1599 | } |
| 1600 | |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1601 | func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 2cb5288 | 2019-07-07 12:39:16 +0900 | [diff] [blame] | 1602 | if p.properties.ForceDisable { |
| 1603 | return |
| 1604 | } |
| 1605 | |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1606 | // TODO(jungjw): Check the key validity. |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1607 | p.inputApex = p.Prebuilt().SingleSourcePath(ctx) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1608 | p.installDir = android.PathForModuleInstall(ctx, "apex") |
Jiyong Park | 4d27704 | 2019-04-23 18:00:10 +0900 | [diff] [blame] | 1609 | p.installFilename = p.InstallFilename() |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1610 | if !strings.HasSuffix(p.installFilename, imageApexSuffix) { |
| 1611 | ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix) |
| 1612 | } |
Nikita Ioffe | 89ecd59 | 2019-04-05 02:10:45 +0100 | [diff] [blame] | 1613 | p.outputApex = android.PathForModuleOut(ctx, p.installFilename) |
| 1614 | ctx.Build(pctx, android.BuildParams{ |
| 1615 | Rule: android.Cp, |
| 1616 | Input: p.inputApex, |
| 1617 | Output: p.outputApex, |
| 1618 | }) |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1619 | if p.installable() { |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1620 | ctx.InstallFile(p.installDir, p.installFilename, p.inputApex) |
Nikita Ioffe | dd53e8b | 2019-04-04 13:42:00 +0100 | [diff] [blame] | 1621 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | func (p *Prebuilt) Prebuilt() *android.Prebuilt { |
| 1625 | return &p.prebuilt |
| 1626 | } |
| 1627 | |
| 1628 | func (p *Prebuilt) Name() string { |
| 1629 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 1630 | } |
| 1631 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1632 | func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries { |
| 1633 | return android.AndroidMkEntries{ |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1634 | Class: "ETC", |
| 1635 | OutputFile: android.OptionalPathForPath(p.inputApex), |
| 1636 | Include: "$(BUILD_PREBUILT)", |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1637 | AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) { |
| 1638 | entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString())) |
| 1639 | entries.SetString("LOCAL_MODULE_STEM", p.installFilename) |
| 1640 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) |
| 1641 | entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1642 | }, |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 1647 | func PrebuiltFactory() android.Module { |
| 1648 | module := &Prebuilt{} |
| 1649 | module.AddProperties(&module.properties) |
Jaewoong Jung | 3e18b19 | 2019-06-11 12:25:34 -0700 | [diff] [blame] | 1650 | android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source") |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1651 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1652 | return module |
| 1653 | } |