blob: 1ede2bd419f8f69d797391919bc6937b6b678b15 [file] [log] [blame]
Inseob Kimc0907f12019-02-08 21:00:45 +09001// Copyright (C) 2019 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
15package cc
16
17import (
Inseob Kima1888ce2022-10-04 14:42:02 +090018 "encoding/json"
Ivan Lozanod67a6b02021-05-20 13:01:32 -040019 "path/filepath"
20 "testing"
21
Inseob Kimc0907f12019-02-08 21:00:45 +090022 "android/soong/android"
Colin Crosse9fe2942020-11-10 18:12:15 -080023 "android/soong/genrule"
Kiyoung Kim487689e2022-07-26 09:48:22 +090024 "android/soong/multitree"
Kiyoung Kim48f37782021-07-07 12:42:39 +090025 "android/soong/snapshot"
Inseob Kimc0907f12019-02-08 21:00:45 +090026)
27
Paul Duffin77980a82019-12-19 16:01:36 +000028func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000029 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000030 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000031 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000032 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000033 RegisterLibraryHeadersBuildComponents(ctx)
Inseob Kim5eb7ee92022-04-27 10:30:34 +090034 RegisterLibraryStubBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000035
Kiyoung Kim487689e2022-07-26 09:48:22 +090036 multitree.RegisterApiImportsModule(ctx)
37
Sam Delmericof2b16062023-09-25 12:13:17 +000038 ctx.RegisterModuleType("prebuilt_build_tool", android.NewPrebuiltBuildTool)
Jiyong Park46a512f2020-12-04 18:02:13 +090039 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000040 ctx.RegisterModuleType("cc_object", ObjectFactory)
Wei Libcd39942021-09-16 23:57:28 +000041 ctx.RegisterModuleType("cc_genrule", GenRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080042 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070043 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070044 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Spandan Das319711b2023-09-19 19:04:41 +000045 ctx.RegisterModuleType("ndk_headers", NdkHeadersFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000046}
47
Paul Duffina04c1072020-03-02 10:16:35 +000048func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000049 ret := commonDefaultModules()
50
51 supportLinuxBionic := false
52 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000053 if os == android.Windows {
54 ret += withWindowsModules()
55 }
56 if os == android.LinuxBionic {
57 supportLinuxBionic = true
58 ret += withLinuxBionic()
59 }
60 }
61
62 if !supportLinuxBionic {
63 ret += withoutLinuxBionic()
64 }
65
66 return ret
67}
68
69func commonDefaultModules() string {
70 return `
Liz Kammer718eb272022-01-07 10:53:37 -050071 cc_defaults {
72 name: "toolchain_libs_defaults",
Colin Cross5dc62c92023-02-15 12:20:19 -080073 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090074 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090075 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090076 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050077 no_libcrt: true,
78 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090079 nocrt: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -080080 no_crt_pad_segment: true,
Jooyung Han75568392020-03-20 04:29:24 +090081 system_shared_libs: [],
82 stl: "none",
Jooyung Han75568392020-03-20 04:29:24 +090083 check_elf_files: false,
84 sanitize: {
85 never: true,
86 },
Spandan Das4de7b492023-05-05 21:13:01 +000087 apex_available: [
88 "//apex_available:anyapex",
89 "//apex_available:platform",
90 ],
Jooyung Han75568392020-03-20 04:29:24 +090091 }
92
Liz Kammer718eb272022-01-07 10:53:37 -050093 cc_prebuilt_library_static {
94 name: "libcompiler_rt-extras",
95 defaults: ["toolchain_libs_defaults"],
96 vendor_ramdisk_available: true,
Colin Cross3e5e7782022-06-17 22:17:05 +000097 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -050098 }
99
100 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800101 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -0800102 defaults: ["toolchain_libs_defaults"],
103 host_supported: true,
Colin Cross4c4c1be2022-02-10 11:41:18 -0800104 vendor_available: true,
105 vendor_ramdisk_available: true,
106 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000107 srcs: [""],
Colin Cross06c80eb2022-02-10 10:34:19 -0800108 }
109
Liz Kammer718eb272022-01-07 10:53:37 -0500110 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800111 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500112 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000113 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500114 }
115
116 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800117 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500118 defaults: [
119 "linux_bionic_supported",
120 "toolchain_libs_defaults",
121 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500122 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800123 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000124 srcs: [""],
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800125 }
126
Liz Kammer718eb272022-01-07 10:53:37 -0500127 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800128 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500129 defaults: [
130 "linux_bionic_supported",
131 "toolchain_libs_defaults",
132 ],
Colin Cross3e5e7782022-06-17 22:17:05 +0000133 srcs: [""],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700134 }
135
Paul Duffind6867912019-12-19 14:38:36 +0000136 // Needed for sanitizer
137 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800138 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500139 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000140 srcs: [""],
Paul Duffind6867912019-12-19 14:38:36 +0000141 }
142
Colin Cross06c80eb2022-02-10 10:34:19 -0800143 cc_prebuilt_library_static {
Colin Cross5dc62c92023-02-15 12:20:19 -0800144 name: "libclang_rt.ubsan_standalone.static",
145 defaults: ["toolchain_libs_defaults"],
146 srcs: [""],
147 }
148
149 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800150 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800151 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000152 host_supported: true,
153 target: {
154 android_arm64: {
155 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
156 },
157 android_arm: {
158 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
159 },
160 linux_glibc_x86_64: {
161 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
162 },
163 linux_glibc_x86: {
164 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
165 },
Colin Cross5dc62c92023-02-15 12:20:19 -0800166 linux_musl_x86_64: {
167 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
168 },
169 linux_musl_x86: {
170 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
171 },
Colin Cross3e5e7782022-06-17 22:17:05 +0000172 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800173 }
174
Inseob Kimc0907f12019-02-08 21:00:45 +0900175 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900176 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100177 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700178 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900179 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800180 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900181 system_shared_libs: [],
182 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800183 stubs: {
184 versions: ["27", "28", "29"],
185 },
Colin Cross203b4212021-04-26 17:19:41 -0700186 llndk: {
187 symbol_file: "libc.map.txt",
188 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900189 }
190 cc_library {
191 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100192 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700193 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800195 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900196 system_shared_libs: [],
197 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800198 stubs: {
199 versions: ["27", "28", "29"],
200 },
201 apex_available: [
202 "//apex_available:platform",
203 "myapex"
204 ],
Colin Cross203b4212021-04-26 17:19:41 -0700205 llndk: {
206 symbol_file: "libm.map.txt",
207 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900208 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400209
210 // Coverage libraries
211 cc_library {
212 name: "libprofile-extras",
213 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500214 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900215 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400216 recovery_available: true,
217 native_coverage: false,
218 system_shared_libs: [],
219 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400220 }
221 cc_library {
222 name: "libprofile-clang-extras",
223 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500224 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900225 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400226 recovery_available: true,
227 native_coverage: false,
228 system_shared_libs: [],
229 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400230 }
231 cc_library {
232 name: "libprofile-extras_ndk",
233 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900234 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400235 native_coverage: false,
236 system_shared_libs: [],
237 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400238 sdk_version: "current",
239 }
240 cc_library {
241 name: "libprofile-clang-extras_ndk",
242 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900243 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400244 native_coverage: false,
245 system_shared_libs: [],
246 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400247 sdk_version: "current",
248 }
249
Inseob Kimc0907f12019-02-08 21:00:45 +0900250 cc_library {
251 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100252 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700253 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900254 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800255 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900256 system_shared_libs: [],
257 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800258 stubs: {
259 versions: ["27", "28", "29"],
260 },
261 apex_available: [
262 "//apex_available:platform",
263 "myapex"
264 ],
Colin Cross203b4212021-04-26 17:19:41 -0700265 llndk: {
266 symbol_file: "libdl.map.txt",
267 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900268 }
269 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900270 name: "libft2",
271 no_libcrt: true,
272 nocrt: true,
273 system_shared_libs: [],
274 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700275 llndk: {
276 symbol_file: "libft2.map.txt",
277 private: true,
278 }
Jooyung Han097087b2019-10-22 19:32:18 +0900279 }
280 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900281 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700282 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900283 nocrt: true,
284 system_shared_libs: [],
285 stl: "none",
286 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500287 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900288 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900289 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900290 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900291 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900292 apex_available: [
293 "//apex_available:platform",
294 "//apex_available:anyapex",
295 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900296 }
297 cc_library {
298 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700299 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 nocrt: true,
301 system_shared_libs: [],
302 stl: "none",
303 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900304 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900305 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900306 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900307 min_sdk_version: "29",
Kiyoung Kim0d1c1e62024-03-26 16:33:58 +0900308 double_loadable: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800309 apex_available: [
310 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500311 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800312 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900313 }
314 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700315 name: "libc++demangle",
316 no_libcrt: true,
317 nocrt: true,
318 system_shared_libs: [],
319 stl: "none",
320 host_supported: false,
321 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500322 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900323 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700324 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900325 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900326 apex_available: [
327 "//apex_available:platform",
328 "//apex_available:anyapex",
329 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700330 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900331
Jiyong Park541142c2020-03-07 16:35:46 +0900332 cc_defaults {
333 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100334 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900335 recovery_available: true,
336 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500337 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900338 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900339 native_bridge_supported: true,
340 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700341 min_sdk_version: "16",
342 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700343 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900344 apex_available: [
345 "//apex_available:platform",
346 "//apex_available:anyapex",
347 ],
348 }
349
Inseob Kimc0907f12019-02-08 21:00:45 +0900350 cc_object {
351 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900352 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900353 srcs: ["crtbegin_so.c"],
354 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900355 }
356
357 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700358 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900359 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900360 srcs: ["crtbegin.c"],
361 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700362 }
363
364 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900365 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900366 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900367 srcs: ["crtbegin.c"],
368 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900369 }
370
371 cc_object {
372 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900373 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900374 srcs: ["crtend_so.c"],
375 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900376 }
377
378 cc_object {
379 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900380 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900381 srcs: ["crtend.c"],
382 objs: ["crtbrand"],
383 }
384
385 cc_object {
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800386 name: "crt_pad_segment",
387 defaults: ["crt_defaults"],
388 }
389
390 cc_object {
Jiyong Park7549d462021-08-25 16:16:03 +0900391 name: "crtbrand",
392 defaults: ["crt_defaults"],
393 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900394 }
395
396 cc_library {
397 name: "libprotobuf-cpp-lite",
398 }
Colin Crossf28329d2020-02-15 11:00:10 -0800399
400 cc_library {
401 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700402 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800403 stl: "none",
404 system_shared_libs: [],
405 }
406
Dan Albertde5aade2020-06-30 12:32:51 -0700407 ndk_library {
408 name: "libc",
409 first_version: "minimum",
410 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800411 }
412
Dan Albertde5aade2020-06-30 12:32:51 -0700413 ndk_library {
414 name: "libm",
415 first_version: "minimum",
416 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800417 }
418
Dan Albertde5aade2020-06-30 12:32:51 -0700419 ndk_library {
420 name: "libdl",
421 first_version: "minimum",
422 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800423 }
424
Colin Crossf28329d2020-02-15 11:00:10 -0800425 ndk_prebuilt_shared_stl {
426 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700427 export_include_dirs: ["ndk_libc++_shared"],
428 }
429
Jiyong Park46a512f2020-12-04 18:02:13 +0900430 cc_library_static {
431 name: "libgoogle-benchmark",
432 sdk_version: "current",
433 stl: "none",
434 system_shared_libs: [],
435 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700436
437 cc_library_static {
438 name: "note_memtag_heap_async",
439 }
440
441 cc_library_static {
442 name: "note_memtag_heap_sync",
443 }
Colin Cross528d67e2021-07-23 22:23:07 +0000444
Colin Cross528d67e2021-07-23 22:23:07 +0000445 cc_library {
446 name: "libc_musl",
447 host_supported: true,
448 no_libcrt: true,
449 nocrt: true,
450 system_shared_libs: [],
451 stl: "none",
452 }
Colin Crossf28329d2020-02-15 11:00:10 -0800453 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000454}
Colin Crossf28329d2020-02-15 11:00:10 -0800455
Paul Duffin02a3d652021-02-24 18:51:54 +0000456func withWindowsModules() string {
457 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500458 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000459 name: "libwinpthread",
460 host_supported: true,
461 enabled: false,
462 target: {
463 windows: {
464 enabled: true,
465 },
466 },
Liz Kammer718eb272022-01-07 10:53:37 -0500467 stl: "none",
468 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000469 }
470 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000471}
472
Paul Duffin02a3d652021-02-24 18:51:54 +0000473func withLinuxBionic() string {
474 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100475 cc_binary {
476 name: "linker",
477 defaults: ["linux_bionic_supported"],
478 recovery_available: true,
479 stl: "none",
480 nocrt: true,
481 static_executable: true,
482 native_coverage: false,
483 system_shared_libs: [],
484 }
485
486 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700487 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100488 host_supported: true,
489 device_supported: false,
490 target: {
491 host: {
492 enabled: false,
493 },
494 linux_bionic: {
495 enabled: true,
496 },
497 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700498 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100499 }
500
501 cc_defaults {
502 name: "linux_bionic_supported",
503 host_supported: true,
504 target: {
505 host: {
506 enabled: false,
507 },
508 linux_bionic: {
509 enabled: true,
510 },
511 },
512 }
513 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000514}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100515
Paul Duffin02a3d652021-02-24 18:51:54 +0000516func withoutLinuxBionic() string {
517 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100518 cc_defaults {
519 name: "linux_bionic_supported",
520 }
521 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900522}
Colin Cross9a942872019-05-14 15:44:26 -0700523
Colin Crossf28329d2020-02-15 11:00:10 -0800524func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800525}
526
Paul Duffin02a3d652021-02-24 18:51:54 +0000527// The directory in which cc linux bionic default modules will be defined.
528//
529// Placing them here ensures that their location does not conflict with default test modules
530// defined by other packages.
531const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
532
533// The directory in which the default cc common test modules will be defined.
534//
535// Placing them here ensures that their location does not conflict with default test modules
536// defined by other packages.
537const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
538
539// Test fixture preparer that will register most cc build components.
540//
541// Singletons and mutators should only be added here if they are needed for a majority of cc
542// module types, otherwise they should be added under a separate preparer to allow them to be
543// selected only when needed to reduce test execution time.
544//
545// Module types do not have much of an overhead unless they are used so this should include as many
546// module types as possible. The exceptions are those module types that require mutators and/or
547// singletons in order to function in which case they should be kept together in a separate
548// preparer.
549var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
550 android.PrepareForTestWithAndroidBuildComponents,
551 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
552 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000553 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000554 ctx.RegisterModuleType("cc_test", TestFactory)
555 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000556 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
557
558 RegisterVndkLibraryTxtTypes(ctx)
559 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000560
561 // Additional files needed in tests that disallow non-existent source files.
562 // This includes files that are needed by all, or at least most, instances of a cc module type.
563 android.MockFS{
564 // Needed for ndk_prebuilt_(shared|static)_stl.
Spandan Das6e332d22023-09-13 17:58:52 +0000565 "defaults/cc/common/current/sources/cxx-stl/llvm-libc++/libs": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000566 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000567)
568
569// Preparer that will define default cc modules, e.g. standard prebuilt modules.
570var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
571 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000572
573 // Additional files needed in tests that disallow non-existent source.
574 android.MockFS{
Dan Albert94dd5652023-07-20 18:16:19 +0000575 "defaults/cc/common/libc.map.txt": nil,
576 "defaults/cc/common/libdl.map.txt": nil,
Kiyoung Kimaa394802024-01-08 12:55:45 +0900577 "defaults/cc/common/libft2.map.txt": nil,
Dan Albert94dd5652023-07-20 18:16:19 +0000578 "defaults/cc/common/libm.map.txt": nil,
579 "defaults/cc/common/ndk_libc++_shared": nil,
580 "defaults/cc/common/crtbegin_so.c": nil,
581 "defaults/cc/common/crtbegin.c": nil,
582 "defaults/cc/common/crtend_so.c": nil,
583 "defaults/cc/common/crtend.c": nil,
584 "defaults/cc/common/crtbrand.c": nil,
AdityaK6e6f5222024-04-03 14:53:22 -0700585 "external/compiler-rt/lib/cfi/cfi_blocklist.txt": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000586
587 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
588 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
589 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
590 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000591 }.AddToFixture(),
592
Paul Duffin02a3d652021-02-24 18:51:54 +0000593 // Place the default cc test modules that are common to all platforms in a location that will not
594 // conflict with default test modules defined by other packages.
595 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
596 // Disable linux bionic by default.
597 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
598)
599
600// Prepare a fixture to use all cc module types, mutators and singletons fully.
601//
602// This should only be used by tests that want to run with as much of the build enabled as possible.
603var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
604 android.PrepareForIntegrationTestWithAndroid,
605 genrule.PrepareForIntegrationTestWithGenrule,
606 PrepareForTestWithCcDefaultModules,
607)
608
609// The preparer to include if running a cc related test for windows.
610var PrepareForTestOnWindows = android.GroupFixturePreparers(
611 // Place the default cc test modules for windows platforms in a location that will not conflict
612 // with default test modules defined by other packages.
613 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
614)
615
616// The preparer to include if running a cc related test for linux bionic.
617var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000618 // Enable linux bionic
619 //
620 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
621 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
622 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000623)
624
Colin Cross5dc62c92023-02-15 12:20:19 -0800625// PrepareForTestWithHostMusl sets the host configuration to musl libc instead of glibc. It also disables the test
626// on mac, which doesn't support musl libc, and adds musl modules.
627var PrepareForTestWithHostMusl = android.GroupFixturePreparers(
628 android.FixtureModifyConfig(android.ModifyTestConfigForMusl),
629 android.PrepareForSkipTestOnMac,
630 android.FixtureAddTextFile("external/musl/Android.bp", `
631 cc_defaults {
632 name: "libc_musl_crt_defaults",
633 host_supported: true,
634 device_supported: false,
635 }
636
637 cc_object {
638 name: "libc_musl_crtbegin_so",
639 defaults: ["libc_musl_crt_defaults"],
640 }
641
642 cc_object {
643 name: "libc_musl_crtend_so",
644 defaults: ["libc_musl_crt_defaults"],
645 }
646
647 cc_object {
648 name: "libc_musl_crtbegin_dynamic",
649 defaults: ["libc_musl_crt_defaults"],
650 }
651
652 cc_object {
653 name: "libc_musl_crtbegin_static",
654 defaults: ["libc_musl_crt_defaults"],
655 }
656
657 cc_object {
658 name: "libc_musl_crtend",
659 defaults: ["libc_musl_crt_defaults"],
660 }
661 `),
662)
663
Vinh Trancde10162023-03-09 22:07:19 -0500664// PrepareForTestWithFdoProfile registers module types to test with fdo_profile
665var PrepareForTestWithFdoProfile = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
666 ctx.RegisterModuleType("soong_namespace", android.NamespaceFactory)
Vinh Trance40b922023-06-05 12:57:55 -0400667 ctx.RegisterModuleType("fdo_profile", FdoProfileFactory)
Vinh Trancde10162023-03-09 22:07:19 -0500668})
669
Paul Duffin02a3d652021-02-24 18:51:54 +0000670// TestConfig is the legacy way of creating a test Config for testing cc modules.
671//
672// See testCc for an explanation as to how to stop using this deprecated method.
673//
674// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800675func TestConfig(buildDir string, os android.OsType, env map[string]string,
676 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700677
Colin Cross98be1bb2019-12-13 20:41:13 -0800678 // add some modules that are required by the compiler and/or linker
679 bp = bp + GatherRequiredDepsForTest(os)
680
Colin Cross2fce23a2020-06-07 17:02:48 -0700681 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800682
Colin Crossf28329d2020-02-15 11:00:10 -0800683 GatherRequiredFilesForTest(mockFS)
684
Colin Cross98be1bb2019-12-13 20:41:13 -0800685 for k, v := range fs {
686 mockFS[k] = v
687 }
688
Colin Crosscb0ac952021-07-20 13:17:15 -0700689 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800690}
691
Paul Duffin02a3d652021-02-24 18:51:54 +0000692// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
693//
694// See testCc for an explanation as to how to stop using this deprecated method.
695//
696// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700697func CreateTestContext(config android.Config) *android.TestContext {
698 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000699 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000700 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800701 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400702 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800703 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
704 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000705
Kiyoung Kim48f37782021-07-07 12:42:39 +0900706 snapshot.VendorSnapshotImageSingleton.Init(ctx)
707 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
708 RegisterVendorSnapshotModules(ctx)
709 RegisterRecoverySnapshotModules(ctx)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800710 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000711
Colin Crosse1bb5d02019-09-24 14:55:04 -0700712 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100713 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100714 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700715
Colin Cross9a942872019-05-14 15:44:26 -0700716 return ctx
717}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400718
719func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
720 t.Helper()
721 mod := ctx.ModuleForTests(moduleName, variant)
722 outputFiles := mod.OutputFiles(t, "")
723 if len(outputFiles) != 1 {
724 t.Errorf("%q must have single output\n", moduleName)
725 return
726 }
727 snapshotPath := filepath.Join(subDir, snapshotFilename)
728
729 if include {
730 out := singleton.Output(snapshotPath)
731 if fake {
732 if out.Rule == nil {
733 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
734 }
735 } else {
736 if out.Input.String() != outputFiles[0].String() {
737 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
738 }
739 }
740 } else {
741 out := singleton.MaybeOutput(snapshotPath)
742 if out.Rule != nil {
743 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
744 }
745 }
746}
747
748func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
749 t.Helper()
750 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
751}
752
753func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
754 t.Helper()
755 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
756}
757
758func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
759 t.Helper()
760 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
761}
762
763func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
764 t.Helper()
765 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
766 if m.ExcludeFromVendorSnapshot() != expected {
767 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
768 }
769}
770
771func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
772 for _, moduleName := range moduleNames {
773 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
774 output := module.outputFile.Path().RelativeToTop()
775 paths = append(paths, output)
776 }
777 return paths
778}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500779
780func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
781 t.Helper()
782 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
783 if m.ExcludeFromRecoverySnapshot() != expected {
784 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
785 }
786}
Inseob Kima1888ce2022-10-04 14:42:02 +0900787
788func checkOverrides(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, jsonPath string, expected []string) {
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7a11dc82022-10-06 15:20:37 +0000789 t.Helper()
Inseob Kima1888ce2022-10-04 14:42:02 +0900790 out := singleton.MaybeOutput(jsonPath)
Colin Crossf61d03d2023-11-02 16:56:39 -0700791 content := android.ContentFromFileRuleForTests(t, ctx, out)
Inseob Kima1888ce2022-10-04 14:42:02 +0900792
793 var flags snapshotJsonFlags
794 if err := json.Unmarshal([]byte(content), &flags); err != nil {
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7a11dc82022-10-06 15:20:37 +0000795 t.Errorf("Error while unmarshalling json %q: %s", jsonPath, err.Error())
Inseob Kima1888ce2022-10-04 14:42:02 +0900796 return
797 }
798
799 for _, moduleName := range expected {
800 if !android.InList(moduleName, flags.Overrides) {
801 t.Errorf("expected %q to be in %q: %q", moduleName, flags.Overrides, content)
802 return
803 }
804 }
805}