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