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