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