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