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