blob: 14a6b7a6aa5b0b725fbaea75c13b4780a118da3b [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 (
Ivan Lozanod67a6b02021-05-20 13:01:32 -040018 "path/filepath"
19 "testing"
20
Inseob Kimc0907f12019-02-08 21:00:45 +090021 "android/soong/android"
Colin Crosse9fe2942020-11-10 18:12:15 -080022 "android/soong/genrule"
Inseob Kimc0907f12019-02-08 21:00:45 +090023)
24
Paul Duffin77980a82019-12-19 16:01:36 +000025func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000026 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000027 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000028 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000029 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000030 RegisterLibraryHeadersBuildComponents(ctx)
Kiyoung Kim487689e2022-07-26 09:48:22 +090031
Sam Delmericof2b16062023-09-25 12:13:17 +000032 ctx.RegisterModuleType("prebuilt_build_tool", android.NewPrebuiltBuildTool)
Jiyong Park46a512f2020-12-04 18:02:13 +090033 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Hao Chen1c8ea5b2023-10-20 23:03:45 +000034 ctx.RegisterModuleType("cc_cmake_snapshot", CmakeSnapshotFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000035 ctx.RegisterModuleType("cc_object", ObjectFactory)
Wei Libcd39942021-09-16 23:57:28 +000036 ctx.RegisterModuleType("cc_genrule", GenRuleFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070037 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Spandan Das319711b2023-09-19 19:04:41 +000038 ctx.RegisterModuleType("ndk_headers", NdkHeadersFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000039}
40
Paul Duffina04c1072020-03-02 10:16:35 +000041func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000042 ret := commonDefaultModules()
43
44 supportLinuxBionic := false
45 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000046 if os == android.Windows {
47 ret += withWindowsModules()
48 }
49 if os == android.LinuxBionic {
50 supportLinuxBionic = true
51 ret += withLinuxBionic()
52 }
53 }
54
55 if !supportLinuxBionic {
56 ret += withoutLinuxBionic()
57 }
58
59 return ret
60}
61
62func commonDefaultModules() string {
63 return `
Liz Kammer718eb272022-01-07 10:53:37 -050064 cc_defaults {
65 name: "toolchain_libs_defaults",
Colin Cross5dc62c92023-02-15 12:20:19 -080066 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090067 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090068 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090069 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050070 no_libcrt: true,
71 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090072 nocrt: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -080073 no_crt_pad_segment: true,
Jooyung Han75568392020-03-20 04:29:24 +090074 system_shared_libs: [],
75 stl: "none",
Jooyung Han75568392020-03-20 04:29:24 +090076 check_elf_files: false,
77 sanitize: {
78 never: true,
79 },
Spandan Das4de7b492023-05-05 21:13:01 +000080 apex_available: [
81 "//apex_available:anyapex",
82 "//apex_available:platform",
83 ],
Jooyung Han75568392020-03-20 04:29:24 +090084 }
85
Liz Kammer718eb272022-01-07 10:53:37 -050086 cc_prebuilt_library_static {
87 name: "libcompiler_rt-extras",
88 defaults: ["toolchain_libs_defaults"],
89 vendor_ramdisk_available: true,
Colin Cross3e5e7782022-06-17 22:17:05 +000090 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -050091 }
92
93 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -080094 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -080095 defaults: ["toolchain_libs_defaults"],
96 host_supported: true,
Colin Cross4c4c1be2022-02-10 11:41:18 -080097 vendor_available: true,
98 vendor_ramdisk_available: true,
99 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000100 srcs: [""],
Colin Cross06c80eb2022-02-10 10:34:19 -0800101 }
102
Liz Kammer718eb272022-01-07 10:53:37 -0500103 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800104 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500105 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000106 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500107 }
108
109 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800110 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500111 defaults: [
112 "linux_bionic_supported",
113 "toolchain_libs_defaults",
114 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500115 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800116 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000117 srcs: [""],
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800118 }
119
Liz Kammer718eb272022-01-07 10:53:37 -0500120 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800121 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500122 defaults: [
123 "linux_bionic_supported",
124 "toolchain_libs_defaults",
125 ],
Colin Cross3e5e7782022-06-17 22:17:05 +0000126 srcs: [""],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700127 }
128
Paul Duffind6867912019-12-19 14:38:36 +0000129 // Needed for sanitizer
130 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800131 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500132 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000133 srcs: [""],
Paul Duffind6867912019-12-19 14:38:36 +0000134 }
135
Colin Cross06c80eb2022-02-10 10:34:19 -0800136 cc_prebuilt_library_static {
Colin Cross5dc62c92023-02-15 12:20:19 -0800137 name: "libclang_rt.ubsan_standalone.static",
138 defaults: ["toolchain_libs_defaults"],
139 srcs: [""],
140 }
141
142 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800143 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800144 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000145 host_supported: true,
146 target: {
147 android_arm64: {
148 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
149 },
150 android_arm: {
151 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
152 },
153 linux_glibc_x86_64: {
154 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
155 },
156 linux_glibc_x86: {
157 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
158 },
Colin Cross5dc62c92023-02-15 12:20:19 -0800159 linux_musl_x86_64: {
160 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
161 },
162 linux_musl_x86: {
163 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
164 },
Colin Cross3e5e7782022-06-17 22:17:05 +0000165 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800166 }
167
Inseob Kimc0907f12019-02-08 21:00:45 +0900168 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900169 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100170 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700171 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900172 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800173 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900174 system_shared_libs: [],
175 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800176 stubs: {
177 versions: ["27", "28", "29"],
178 },
Colin Cross203b4212021-04-26 17:19:41 -0700179 llndk: {
180 symbol_file: "libc.map.txt",
181 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900182 }
183 cc_library {
184 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100185 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700186 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900187 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800188 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900189 system_shared_libs: [],
190 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800191 stubs: {
192 versions: ["27", "28", "29"],
193 },
194 apex_available: [
195 "//apex_available:platform",
196 "myapex"
197 ],
Colin Cross203b4212021-04-26 17:19:41 -0700198 llndk: {
199 symbol_file: "libm.map.txt",
200 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900201 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400202
203 // Coverage libraries
204 cc_library {
205 name: "libprofile-extras",
206 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500207 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900208 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400209 recovery_available: true,
210 native_coverage: false,
211 system_shared_libs: [],
212 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400213 }
214 cc_library {
215 name: "libprofile-clang-extras",
216 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500217 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900218 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400219 recovery_available: true,
220 native_coverage: false,
221 system_shared_libs: [],
222 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400223 }
224 cc_library {
225 name: "libprofile-extras_ndk",
226 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900227 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400228 native_coverage: false,
229 system_shared_libs: [],
230 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400231 sdk_version: "current",
232 }
233 cc_library {
234 name: "libprofile-clang-extras_ndk",
235 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900236 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400237 native_coverage: false,
238 system_shared_libs: [],
239 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400240 sdk_version: "current",
241 }
242
Inseob Kimc0907f12019-02-08 21:00:45 +0900243 cc_library {
244 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100245 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700246 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900247 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800248 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900249 system_shared_libs: [],
250 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800251 stubs: {
252 versions: ["27", "28", "29"],
253 },
254 apex_available: [
255 "//apex_available:platform",
256 "myapex"
257 ],
Colin Cross203b4212021-04-26 17:19:41 -0700258 llndk: {
259 symbol_file: "libdl.map.txt",
260 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900261 }
262 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900263 name: "libft2",
264 no_libcrt: true,
265 nocrt: true,
266 system_shared_libs: [],
267 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700268 llndk: {
269 symbol_file: "libft2.map.txt",
270 private: true,
271 }
Jooyung Han097087b2019-10-22 19:32:18 +0900272 }
273 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900274 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700275 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900276 nocrt: true,
277 system_shared_libs: [],
278 stl: "none",
279 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500280 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900281 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900282 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900283 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900284 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900285 apex_available: [
286 "//apex_available:platform",
287 "//apex_available:anyapex",
288 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900289 }
290 cc_library {
291 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700292 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900293 nocrt: true,
294 system_shared_libs: [],
295 stl: "none",
296 vendor_available: true,
Ivan Lozano0a468a42024-05-13 21:03:34 -0400297 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900298 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900299 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900300 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900301 min_sdk_version: "29",
Kiyoung Kim0d1c1e62024-03-26 16:33:58 +0900302 double_loadable: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800303 apex_available: [
304 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500305 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800306 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 }
308 cc_library {
Ryan Prichard2a69eb62024-07-30 01:58:54 +0000309 name: "ndk_libc++_shared",
310 export_include_dirs: ["ndk_libc++_shared_include_dirs"],
311 no_libcrt: true,
312 nocrt: true,
313 system_shared_libs: [],
314 stl: "none",
315 vendor_available: true,
316 vendor_ramdisk_available: true,
317 product_available: true,
318 recovery_available: true,
319 host_supported: false,
320 sdk_version: "minimum",
321 double_loadable: true,
322 apex_available: [
323 "//apex_available:platform",
324 "//apex_available:anyapex",
325 ],
326 }
327 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700328 name: "libc++demangle",
329 no_libcrt: true,
330 nocrt: true,
331 system_shared_libs: [],
332 stl: "none",
333 host_supported: false,
334 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500335 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900336 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700337 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900338 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900339 apex_available: [
340 "//apex_available:platform",
341 "//apex_available:anyapex",
342 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700343 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900344
Jiyong Park541142c2020-03-07 16:35:46 +0900345 cc_defaults {
346 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100347 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900348 recovery_available: true,
349 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500350 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900351 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900352 native_bridge_supported: true,
353 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700354 min_sdk_version: "16",
355 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700356 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900357 apex_available: [
358 "//apex_available:platform",
359 "//apex_available:anyapex",
360 ],
361 }
362
Inseob Kimc0907f12019-02-08 21:00:45 +0900363 cc_object {
364 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900365 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900366 srcs: ["crtbegin_so.c"],
367 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900368 }
369
370 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700371 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900372 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900373 srcs: ["crtbegin.c"],
374 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700375 }
376
377 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900378 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900379 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900380 srcs: ["crtbegin.c"],
381 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900382 }
383
384 cc_object {
385 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900386 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900387 srcs: ["crtend_so.c"],
388 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900389 }
390
391 cc_object {
392 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900393 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900394 srcs: ["crtend.c"],
395 objs: ["crtbrand"],
396 }
397
398 cc_object {
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800399 name: "crt_pad_segment",
400 defaults: ["crt_defaults"],
401 }
402
403 cc_object {
Jiyong Park7549d462021-08-25 16:16:03 +0900404 name: "crtbrand",
405 defaults: ["crt_defaults"],
406 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900407 }
408
409 cc_library {
410 name: "libprotobuf-cpp-lite",
411 }
Colin Crossf28329d2020-02-15 11:00:10 -0800412
Dan Albertde5aade2020-06-30 12:32:51 -0700413 ndk_library {
414 name: "libc",
415 first_version: "minimum",
416 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800417 }
418
Dan Albertde5aade2020-06-30 12:32:51 -0700419 ndk_library {
420 name: "libm",
421 first_version: "minimum",
422 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800423 }
424
Dan Albertde5aade2020-06-30 12:32:51 -0700425 ndk_library {
426 name: "libdl",
427 first_version: "minimum",
428 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800429 }
430
Jiyong Park46a512f2020-12-04 18:02:13 +0900431 cc_library_static {
432 name: "libgoogle-benchmark",
433 sdk_version: "current",
434 stl: "none",
435 system_shared_libs: [],
436 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700437
438 cc_library_static {
439 name: "note_memtag_heap_async",
440 }
441
442 cc_library_static {
443 name: "note_memtag_heap_sync",
444 }
Colin Cross528d67e2021-07-23 22:23:07 +0000445
Colin Cross528d67e2021-07-23 22:23:07 +0000446 cc_library {
447 name: "libc_musl",
448 host_supported: true,
449 no_libcrt: true,
450 nocrt: true,
451 system_shared_libs: [],
452 stl: "none",
453 }
Colin Crossf28329d2020-02-15 11:00:10 -0800454 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000455}
Colin Crossf28329d2020-02-15 11:00:10 -0800456
Paul Duffin02a3d652021-02-24 18:51:54 +0000457func withWindowsModules() string {
458 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500459 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000460 name: "libwinpthread",
461 host_supported: true,
462 enabled: false,
463 target: {
464 windows: {
465 enabled: true,
466 },
467 },
Liz Kammer718eb272022-01-07 10:53:37 -0500468 stl: "none",
469 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000470 }
471 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000472}
473
Paul Duffin02a3d652021-02-24 18:51:54 +0000474func withLinuxBionic() string {
475 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100476 cc_binary {
477 name: "linker",
478 defaults: ["linux_bionic_supported"],
479 recovery_available: true,
480 stl: "none",
481 nocrt: true,
482 static_executable: true,
483 native_coverage: false,
484 system_shared_libs: [],
485 }
486
487 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700488 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100489 host_supported: true,
490 device_supported: false,
491 target: {
492 host: {
493 enabled: false,
494 },
495 linux_bionic: {
496 enabled: true,
497 },
498 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700499 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100500 }
501
502 cc_defaults {
503 name: "linux_bionic_supported",
504 host_supported: true,
505 target: {
506 host: {
507 enabled: false,
508 },
509 linux_bionic: {
510 enabled: true,
511 },
512 },
513 }
514 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000515}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100516
Paul Duffin02a3d652021-02-24 18:51:54 +0000517func withoutLinuxBionic() string {
518 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100519 cc_defaults {
520 name: "linux_bionic_supported",
521 }
522 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900523}
Colin Cross9a942872019-05-14 15:44:26 -0700524
Colin Crossf28329d2020-02-15 11:00:10 -0800525func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800526}
527
Paul Duffin02a3d652021-02-24 18:51:54 +0000528// The directory in which cc linux bionic default modules will be defined.
529//
530// Placing them here ensures that their location does not conflict with default test modules
531// defined by other packages.
532const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
533
534// The directory in which the default cc common test modules will be defined.
535//
536// Placing them here ensures that their location does not conflict with default test modules
537// defined by other packages.
538const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
539
540// Test fixture preparer that will register most cc build components.
541//
542// Singletons and mutators should only be added here if they are needed for a majority of cc
543// module types, otherwise they should be added under a separate preparer to allow them to be
544// selected only when needed to reduce test execution time.
545//
546// Module types do not have much of an overhead unless they are used so this should include as many
547// module types as possible. The exceptions are those module types that require mutators and/or
548// singletons in order to function in which case they should be kept together in a separate
549// preparer.
550var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
551 android.PrepareForTestWithAndroidBuildComponents,
552 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
553 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000554 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000555 ctx.RegisterModuleType("cc_test", TestFactory)
556 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000557 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
558
Kiyoung Kim973cb6f2024-04-29 14:14:53 +0900559 RegisterLlndkLibraryTxtType(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000560 }),
561)
562
563// Preparer that will define default cc modules, e.g. standard prebuilt modules.
564var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
565 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000566
567 // Additional files needed in tests that disallow non-existent source.
568 android.MockFS{
Ryan Prichard2a69eb62024-07-30 01:58:54 +0000569 "defaults/cc/common/libc.map.txt": nil,
570 "defaults/cc/common/libdl.map.txt": nil,
571 "defaults/cc/common/libft2.map.txt": nil,
572 "defaults/cc/common/libm.map.txt": nil,
573 "defaults/cc/common/ndk_libc++_shared_include_dirs": nil,
574 "defaults/cc/common/crtbegin_so.c": nil,
575 "defaults/cc/common/crtbegin.c": nil,
576 "defaults/cc/common/crtend_so.c": nil,
577 "defaults/cc/common/crtend.c": nil,
578 "defaults/cc/common/crtbrand.c": nil,
579 "external/compiler-rt/lib/cfi/cfi_blocklist.txt": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000580
581 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
582 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
583 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
584 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000585 }.AddToFixture(),
586
Paul Duffin02a3d652021-02-24 18:51:54 +0000587 // Place the default cc test modules that are common to all platforms in a location that will not
588 // conflict with default test modules defined by other packages.
589 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
590 // Disable linux bionic by default.
591 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
592)
593
594// Prepare a fixture to use all cc module types, mutators and singletons fully.
595//
596// This should only be used by tests that want to run with as much of the build enabled as possible.
597var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
598 android.PrepareForIntegrationTestWithAndroid,
599 genrule.PrepareForIntegrationTestWithGenrule,
600 PrepareForTestWithCcDefaultModules,
601)
602
603// The preparer to include if running a cc related test for windows.
604var PrepareForTestOnWindows = android.GroupFixturePreparers(
605 // Place the default cc test modules for windows platforms in a location that will not conflict
606 // with default test modules defined by other packages.
607 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
608)
609
610// The preparer to include if running a cc related test for linux bionic.
611var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000612 // Enable linux bionic
613 //
614 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
615 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
616 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000617)
618
Colin Cross5dc62c92023-02-15 12:20:19 -0800619// PrepareForTestWithHostMusl sets the host configuration to musl libc instead of glibc. It also disables the test
620// on mac, which doesn't support musl libc, and adds musl modules.
621var PrepareForTestWithHostMusl = android.GroupFixturePreparers(
622 android.FixtureModifyConfig(android.ModifyTestConfigForMusl),
623 android.PrepareForSkipTestOnMac,
624 android.FixtureAddTextFile("external/musl/Android.bp", `
625 cc_defaults {
626 name: "libc_musl_crt_defaults",
627 host_supported: true,
628 device_supported: false,
629 }
630
631 cc_object {
632 name: "libc_musl_crtbegin_so",
633 defaults: ["libc_musl_crt_defaults"],
634 }
635
636 cc_object {
637 name: "libc_musl_crtend_so",
638 defaults: ["libc_musl_crt_defaults"],
639 }
640
641 cc_object {
642 name: "libc_musl_crtbegin_dynamic",
643 defaults: ["libc_musl_crt_defaults"],
644 }
645
646 cc_object {
647 name: "libc_musl_crtbegin_static",
648 defaults: ["libc_musl_crt_defaults"],
649 }
650
651 cc_object {
652 name: "libc_musl_crtend",
653 defaults: ["libc_musl_crt_defaults"],
654 }
655 `),
656)
657
Vinh Trancde10162023-03-09 22:07:19 -0500658// PrepareForTestWithFdoProfile registers module types to test with fdo_profile
659var PrepareForTestWithFdoProfile = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
660 ctx.RegisterModuleType("soong_namespace", android.NamespaceFactory)
Vinh Trance40b922023-06-05 12:57:55 -0400661 ctx.RegisterModuleType("fdo_profile", FdoProfileFactory)
Vinh Trancde10162023-03-09 22:07:19 -0500662})
663
Paul Duffin02a3d652021-02-24 18:51:54 +0000664// TestConfig is the legacy way of creating a test Config for testing cc modules.
665//
666// See testCc for an explanation as to how to stop using this deprecated method.
667//
668// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800669func TestConfig(buildDir string, os android.OsType, env map[string]string,
670 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700671
Colin Cross98be1bb2019-12-13 20:41:13 -0800672 // add some modules that are required by the compiler and/or linker
673 bp = bp + GatherRequiredDepsForTest(os)
674
Colin Cross2fce23a2020-06-07 17:02:48 -0700675 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800676
Colin Crossf28329d2020-02-15 11:00:10 -0800677 GatherRequiredFilesForTest(mockFS)
678
Colin Cross98be1bb2019-12-13 20:41:13 -0800679 for k, v := range fs {
680 mockFS[k] = v
681 }
682
Colin Crosscb0ac952021-07-20 13:17:15 -0700683 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800684}
685
Paul Duffin02a3d652021-02-24 18:51:54 +0000686// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
687//
688// See testCc for an explanation as to how to stop using this deprecated method.
689//
690// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700691func CreateTestContext(config android.Config) *android.TestContext {
692 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000693 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000694 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800695 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400696 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800697 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
698 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000699
Kiyoung Kim973cb6f2024-04-29 14:14:53 +0900700 RegisterLlndkLibraryTxtType(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000701
Colin Crosse1bb5d02019-09-24 14:55:04 -0700702 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100703 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100704 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700705
Colin Cross9a942872019-05-14 15:44:26 -0700706 return ctx
707}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400708
709func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
710 t.Helper()
711 mod := ctx.ModuleForTests(moduleName, variant)
Yu Liu51c22312024-08-20 23:56:15 +0000712 outputFiles := mod.OutputFiles(ctx, t, "")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400713 if len(outputFiles) != 1 {
714 t.Errorf("%q must have single output\n", moduleName)
715 return
716 }
717 snapshotPath := filepath.Join(subDir, snapshotFilename)
718
719 if include {
720 out := singleton.Output(snapshotPath)
721 if fake {
722 if out.Rule == nil {
723 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
724 }
725 } else {
726 if out.Input.String() != outputFiles[0].String() {
727 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
728 }
729 }
730 } else {
731 out := singleton.MaybeOutput(snapshotPath)
732 if out.Rule != nil {
733 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
734 }
735 }
736}
737
738func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
739 t.Helper()
740 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
741}
742
743func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
744 t.Helper()
745 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
746}
747
748func CheckSnapshotRule(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, true)
751}
752
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400753func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
754 for _, moduleName := range moduleNames {
755 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
756 output := module.outputFile.Path().RelativeToTop()
757 paths = append(paths, output)
758 }
759 return paths
760}