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