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