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