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