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