blob: ed567af69cac899f17856dff76991bd83484d985 [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"
Kiyoung Kim487689e2022-07-26 09:48:22 +090023 "android/soong/multitree"
Inseob Kimc0907f12019-02-08 21:00:45 +090024)
25
Paul Duffin77980a82019-12-19 16:01:36 +000026func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000027 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000028 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000029 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000030 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000031 RegisterLibraryHeadersBuildComponents(ctx)
Inseob Kim5eb7ee92022-04-27 10:30:34 +090032 RegisterLibraryStubBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000033
Kiyoung Kim487689e2022-07-26 09:48:22 +090034 multitree.RegisterApiImportsModule(ctx)
35
Sam Delmericof2b16062023-09-25 12:13:17 +000036 ctx.RegisterModuleType("prebuilt_build_tool", android.NewPrebuiltBuildTool)
Jiyong Park46a512f2020-12-04 18:02:13 +090037 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Hao Chen1c8ea5b2023-10-20 23:03:45 +000038 ctx.RegisterModuleType("cc_cmake_snapshot", CmakeSnapshotFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000039 ctx.RegisterModuleType("cc_object", ObjectFactory)
Wei Libcd39942021-09-16 23:57:28 +000040 ctx.RegisterModuleType("cc_genrule", GenRuleFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070041 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Spandan Das319711b2023-09-19 19:04:41 +000042 ctx.RegisterModuleType("ndk_headers", NdkHeadersFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000043}
44
Paul Duffina04c1072020-03-02 10:16:35 +000045func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000046 ret := commonDefaultModules()
47
48 supportLinuxBionic := false
49 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000050 if os == android.Windows {
51 ret += withWindowsModules()
52 }
53 if os == android.LinuxBionic {
54 supportLinuxBionic = true
55 ret += withLinuxBionic()
56 }
57 }
58
59 if !supportLinuxBionic {
60 ret += withoutLinuxBionic()
61 }
62
63 return ret
64}
65
66func commonDefaultModules() string {
67 return `
Liz Kammer718eb272022-01-07 10:53:37 -050068 cc_defaults {
69 name: "toolchain_libs_defaults",
Colin Cross5dc62c92023-02-15 12:20:19 -080070 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090071 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090072 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090073 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050074 no_libcrt: true,
75 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090076 nocrt: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -080077 no_crt_pad_segment: true,
Jooyung Han75568392020-03-20 04:29:24 +090078 system_shared_libs: [],
79 stl: "none",
Jooyung Han75568392020-03-20 04:29:24 +090080 check_elf_files: false,
81 sanitize: {
82 never: true,
83 },
Spandan Das4de7b492023-05-05 21:13:01 +000084 apex_available: [
85 "//apex_available:anyapex",
86 "//apex_available:platform",
87 ],
Jooyung Han75568392020-03-20 04:29:24 +090088 }
89
Liz Kammer718eb272022-01-07 10:53:37 -050090 cc_prebuilt_library_static {
91 name: "libcompiler_rt-extras",
92 defaults: ["toolchain_libs_defaults"],
93 vendor_ramdisk_available: true,
Colin Cross3e5e7782022-06-17 22:17:05 +000094 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -050095 }
96
97 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -080098 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -080099 defaults: ["toolchain_libs_defaults"],
100 host_supported: true,
Colin Cross4c4c1be2022-02-10 11:41:18 -0800101 vendor_available: true,
102 vendor_ramdisk_available: true,
103 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000104 srcs: [""],
Colin Cross06c80eb2022-02-10 10:34:19 -0800105 }
106
Liz Kammer718eb272022-01-07 10:53:37 -0500107 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800108 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500109 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000110 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500111 }
112
113 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800114 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500115 defaults: [
116 "linux_bionic_supported",
117 "toolchain_libs_defaults",
118 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500119 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800120 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000121 srcs: [""],
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800122 }
123
Liz Kammer718eb272022-01-07 10:53:37 -0500124 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800125 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500126 defaults: [
127 "linux_bionic_supported",
128 "toolchain_libs_defaults",
129 ],
Colin Cross3e5e7782022-06-17 22:17:05 +0000130 srcs: [""],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700131 }
132
Paul Duffind6867912019-12-19 14:38:36 +0000133 // Needed for sanitizer
134 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800135 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500136 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000137 srcs: [""],
Paul Duffind6867912019-12-19 14:38:36 +0000138 }
139
Colin Cross06c80eb2022-02-10 10:34:19 -0800140 cc_prebuilt_library_static {
Colin Cross5dc62c92023-02-15 12:20:19 -0800141 name: "libclang_rt.ubsan_standalone.static",
142 defaults: ["toolchain_libs_defaults"],
143 srcs: [""],
144 }
145
146 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800147 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800148 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000149 host_supported: true,
150 target: {
151 android_arm64: {
152 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
153 },
154 android_arm: {
155 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
156 },
157 linux_glibc_x86_64: {
158 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
159 },
160 linux_glibc_x86: {
161 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
162 },
Colin Cross5dc62c92023-02-15 12:20:19 -0800163 linux_musl_x86_64: {
164 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
165 },
166 linux_musl_x86: {
167 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
168 },
Colin Cross3e5e7782022-06-17 22:17:05 +0000169 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800170 }
171
Inseob Kimc0907f12019-02-08 21:00:45 +0900172 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900173 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100174 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700175 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900176 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800177 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900178 system_shared_libs: [],
179 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800180 stubs: {
181 versions: ["27", "28", "29"],
182 },
Colin Cross203b4212021-04-26 17:19:41 -0700183 llndk: {
184 symbol_file: "libc.map.txt",
185 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900186 }
187 cc_library {
188 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100189 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700190 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900191 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800192 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900193 system_shared_libs: [],
194 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800195 stubs: {
196 versions: ["27", "28", "29"],
197 },
198 apex_available: [
199 "//apex_available:platform",
200 "myapex"
201 ],
Colin Cross203b4212021-04-26 17:19:41 -0700202 llndk: {
203 symbol_file: "libm.map.txt",
204 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900205 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400206
207 // Coverage libraries
208 cc_library {
209 name: "libprofile-extras",
210 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500211 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900212 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400213 recovery_available: true,
214 native_coverage: false,
215 system_shared_libs: [],
216 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400217 }
218 cc_library {
219 name: "libprofile-clang-extras",
220 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500221 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900222 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400223 recovery_available: true,
224 native_coverage: false,
225 system_shared_libs: [],
226 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400227 }
228 cc_library {
229 name: "libprofile-extras_ndk",
230 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900231 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400232 native_coverage: false,
233 system_shared_libs: [],
234 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400235 sdk_version: "current",
236 }
237 cc_library {
238 name: "libprofile-clang-extras_ndk",
239 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900240 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400241 native_coverage: false,
242 system_shared_libs: [],
243 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400244 sdk_version: "current",
245 }
246
Inseob Kimc0907f12019-02-08 21:00:45 +0900247 cc_library {
248 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100249 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700250 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900251 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800252 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900253 system_shared_libs: [],
254 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800255 stubs: {
256 versions: ["27", "28", "29"],
257 },
258 apex_available: [
259 "//apex_available:platform",
260 "myapex"
261 ],
Colin Cross203b4212021-04-26 17:19:41 -0700262 llndk: {
263 symbol_file: "libdl.map.txt",
264 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900265 }
266 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900267 name: "libft2",
268 no_libcrt: true,
269 nocrt: true,
270 system_shared_libs: [],
271 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700272 llndk: {
273 symbol_file: "libft2.map.txt",
274 private: true,
275 }
Jooyung Han097087b2019-10-22 19:32:18 +0900276 }
277 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900278 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700279 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900280 nocrt: true,
281 system_shared_libs: [],
282 stl: "none",
283 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500284 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900285 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900286 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900287 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900288 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900289 apex_available: [
290 "//apex_available:platform",
291 "//apex_available:anyapex",
292 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900293 }
294 cc_library {
295 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700296 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900297 nocrt: true,
298 system_shared_libs: [],
299 stl: "none",
300 vendor_available: true,
Ivan Lozano0a468a42024-05-13 21:03:34 -0400301 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900302 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900303 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900304 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900305 min_sdk_version: "29",
Kiyoung Kim0d1c1e62024-03-26 16:33:58 +0900306 double_loadable: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800307 apex_available: [
308 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500309 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800310 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900311 }
312 cc_library {
Ryan Prichard2a69eb62024-07-30 01:58:54 +0000313 name: "ndk_libc++_shared",
314 export_include_dirs: ["ndk_libc++_shared_include_dirs"],
315 no_libcrt: true,
316 nocrt: true,
317 system_shared_libs: [],
318 stl: "none",
319 vendor_available: true,
320 vendor_ramdisk_available: true,
321 product_available: true,
322 recovery_available: true,
323 host_supported: false,
324 sdk_version: "minimum",
325 double_loadable: true,
326 apex_available: [
327 "//apex_available:platform",
328 "//apex_available:anyapex",
329 ],
330 }
331 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700332 name: "libc++demangle",
333 no_libcrt: true,
334 nocrt: true,
335 system_shared_libs: [],
336 stl: "none",
337 host_supported: false,
338 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500339 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900340 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700341 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900342 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900343 apex_available: [
344 "//apex_available:platform",
345 "//apex_available:anyapex",
346 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700347 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900348
Jiyong Park541142c2020-03-07 16:35:46 +0900349 cc_defaults {
350 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100351 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900352 recovery_available: true,
353 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500354 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900355 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900356 native_bridge_supported: true,
357 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700358 min_sdk_version: "16",
359 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700360 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900361 apex_available: [
362 "//apex_available:platform",
363 "//apex_available:anyapex",
364 ],
365 }
366
Inseob Kimc0907f12019-02-08 21:00:45 +0900367 cc_object {
368 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900369 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900370 srcs: ["crtbegin_so.c"],
371 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900372 }
373
374 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700375 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900376 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900377 srcs: ["crtbegin.c"],
378 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700379 }
380
381 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900382 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900383 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900384 srcs: ["crtbegin.c"],
385 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900386 }
387
388 cc_object {
389 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900390 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900391 srcs: ["crtend_so.c"],
392 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900393 }
394
395 cc_object {
396 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900397 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900398 srcs: ["crtend.c"],
399 objs: ["crtbrand"],
400 }
401
402 cc_object {
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800403 name: "crt_pad_segment",
404 defaults: ["crt_defaults"],
405 }
406
407 cc_object {
Jiyong Park7549d462021-08-25 16:16:03 +0900408 name: "crtbrand",
409 defaults: ["crt_defaults"],
410 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900411 }
412
413 cc_library {
414 name: "libprotobuf-cpp-lite",
415 }
Colin Crossf28329d2020-02-15 11:00:10 -0800416
Dan Albertde5aade2020-06-30 12:32:51 -0700417 ndk_library {
418 name: "libc",
419 first_version: "minimum",
420 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800421 }
422
Dan Albertde5aade2020-06-30 12:32:51 -0700423 ndk_library {
424 name: "libm",
425 first_version: "minimum",
426 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800427 }
428
Dan Albertde5aade2020-06-30 12:32:51 -0700429 ndk_library {
430 name: "libdl",
431 first_version: "minimum",
432 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800433 }
434
Jiyong Park46a512f2020-12-04 18:02:13 +0900435 cc_library_static {
436 name: "libgoogle-benchmark",
437 sdk_version: "current",
438 stl: "none",
439 system_shared_libs: [],
440 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700441
442 cc_library_static {
443 name: "note_memtag_heap_async",
444 }
445
446 cc_library_static {
447 name: "note_memtag_heap_sync",
448 }
Colin Cross528d67e2021-07-23 22:23:07 +0000449
Colin Cross528d67e2021-07-23 22:23:07 +0000450 cc_library {
451 name: "libc_musl",
452 host_supported: true,
453 no_libcrt: true,
454 nocrt: true,
455 system_shared_libs: [],
456 stl: "none",
457 }
Colin Crossf28329d2020-02-15 11:00:10 -0800458 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000459}
Colin Crossf28329d2020-02-15 11:00:10 -0800460
Paul Duffin02a3d652021-02-24 18:51:54 +0000461func withWindowsModules() string {
462 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500463 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000464 name: "libwinpthread",
465 host_supported: true,
466 enabled: false,
467 target: {
468 windows: {
469 enabled: true,
470 },
471 },
Liz Kammer718eb272022-01-07 10:53:37 -0500472 stl: "none",
473 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000474 }
475 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000476}
477
Paul Duffin02a3d652021-02-24 18:51:54 +0000478func withLinuxBionic() string {
479 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100480 cc_binary {
481 name: "linker",
482 defaults: ["linux_bionic_supported"],
483 recovery_available: true,
484 stl: "none",
485 nocrt: true,
486 static_executable: true,
487 native_coverage: false,
488 system_shared_libs: [],
489 }
490
491 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700492 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100493 host_supported: true,
494 device_supported: false,
495 target: {
496 host: {
497 enabled: false,
498 },
499 linux_bionic: {
500 enabled: true,
501 },
502 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700503 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100504 }
505
506 cc_defaults {
507 name: "linux_bionic_supported",
508 host_supported: true,
509 target: {
510 host: {
511 enabled: false,
512 },
513 linux_bionic: {
514 enabled: true,
515 },
516 },
517 }
518 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000519}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100520
Paul Duffin02a3d652021-02-24 18:51:54 +0000521func withoutLinuxBionic() string {
522 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100523 cc_defaults {
524 name: "linux_bionic_supported",
525 }
526 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900527}
Colin Cross9a942872019-05-14 15:44:26 -0700528
Colin Crossf28329d2020-02-15 11:00:10 -0800529func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800530}
531
Paul Duffin02a3d652021-02-24 18:51:54 +0000532// The directory in which cc linux bionic default modules will be defined.
533//
534// Placing them here ensures that their location does not conflict with default test modules
535// defined by other packages.
536const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
537
538// The directory in which the default cc common test modules will be defined.
539//
540// Placing them here ensures that their location does not conflict with default test modules
541// defined by other packages.
542const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
543
544// Test fixture preparer that will register most cc build components.
545//
546// Singletons and mutators should only be added here if they are needed for a majority of cc
547// module types, otherwise they should be added under a separate preparer to allow them to be
548// selected only when needed to reduce test execution time.
549//
550// Module types do not have much of an overhead unless they are used so this should include as many
551// module types as possible. The exceptions are those module types that require mutators and/or
552// singletons in order to function in which case they should be kept together in a separate
553// preparer.
554var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
555 android.PrepareForTestWithAndroidBuildComponents,
556 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
557 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000558 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000559 ctx.RegisterModuleType("cc_test", TestFactory)
560 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000561 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
562
Kiyoung Kim973cb6f2024-04-29 14:14:53 +0900563 RegisterLlndkLibraryTxtType(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000564 }),
565)
566
567// Preparer that will define default cc modules, e.g. standard prebuilt modules.
568var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
569 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000570
571 // Additional files needed in tests that disallow non-existent source.
572 android.MockFS{
Ryan Prichard2a69eb62024-07-30 01:58:54 +0000573 "defaults/cc/common/libc.map.txt": nil,
574 "defaults/cc/common/libdl.map.txt": nil,
575 "defaults/cc/common/libft2.map.txt": nil,
576 "defaults/cc/common/libm.map.txt": nil,
577 "defaults/cc/common/ndk_libc++_shared_include_dirs": nil,
578 "defaults/cc/common/crtbegin_so.c": nil,
579 "defaults/cc/common/crtbegin.c": nil,
580 "defaults/cc/common/crtend_so.c": nil,
581 "defaults/cc/common/crtend.c": nil,
582 "defaults/cc/common/crtbrand.c": nil,
583 "external/compiler-rt/lib/cfi/cfi_blocklist.txt": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000584
585 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
586 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
587 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
588 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000589 }.AddToFixture(),
590
Paul Duffin02a3d652021-02-24 18:51:54 +0000591 // Place the default cc test modules that are common to all platforms in a location that will not
592 // conflict with default test modules defined by other packages.
593 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
594 // Disable linux bionic by default.
595 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
596)
597
598// Prepare a fixture to use all cc module types, mutators and singletons fully.
599//
600// This should only be used by tests that want to run with as much of the build enabled as possible.
601var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
602 android.PrepareForIntegrationTestWithAndroid,
603 genrule.PrepareForIntegrationTestWithGenrule,
604 PrepareForTestWithCcDefaultModules,
605)
606
607// The preparer to include if running a cc related test for windows.
608var PrepareForTestOnWindows = android.GroupFixturePreparers(
609 // Place the default cc test modules for windows platforms in a location that will not conflict
610 // with default test modules defined by other packages.
611 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
612)
613
614// The preparer to include if running a cc related test for linux bionic.
615var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000616 // Enable linux bionic
617 //
618 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
619 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
620 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000621)
622
Colin Cross5dc62c92023-02-15 12:20:19 -0800623// PrepareForTestWithHostMusl sets the host configuration to musl libc instead of glibc. It also disables the test
624// on mac, which doesn't support musl libc, and adds musl modules.
625var PrepareForTestWithHostMusl = android.GroupFixturePreparers(
626 android.FixtureModifyConfig(android.ModifyTestConfigForMusl),
627 android.PrepareForSkipTestOnMac,
628 android.FixtureAddTextFile("external/musl/Android.bp", `
629 cc_defaults {
630 name: "libc_musl_crt_defaults",
631 host_supported: true,
632 device_supported: false,
633 }
634
635 cc_object {
636 name: "libc_musl_crtbegin_so",
637 defaults: ["libc_musl_crt_defaults"],
638 }
639
640 cc_object {
641 name: "libc_musl_crtend_so",
642 defaults: ["libc_musl_crt_defaults"],
643 }
644
645 cc_object {
646 name: "libc_musl_crtbegin_dynamic",
647 defaults: ["libc_musl_crt_defaults"],
648 }
649
650 cc_object {
651 name: "libc_musl_crtbegin_static",
652 defaults: ["libc_musl_crt_defaults"],
653 }
654
655 cc_object {
656 name: "libc_musl_crtend",
657 defaults: ["libc_musl_crt_defaults"],
658 }
659 `),
660)
661
Vinh Trancde10162023-03-09 22:07:19 -0500662// PrepareForTestWithFdoProfile registers module types to test with fdo_profile
663var PrepareForTestWithFdoProfile = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
664 ctx.RegisterModuleType("soong_namespace", android.NamespaceFactory)
Vinh Trance40b922023-06-05 12:57:55 -0400665 ctx.RegisterModuleType("fdo_profile", FdoProfileFactory)
Vinh Trancde10162023-03-09 22:07:19 -0500666})
667
Paul Duffin02a3d652021-02-24 18:51:54 +0000668// TestConfig is the legacy way of creating a test Config for testing cc modules.
669//
670// See testCc for an explanation as to how to stop using this deprecated method.
671//
672// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800673func TestConfig(buildDir string, os android.OsType, env map[string]string,
674 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700675
Colin Cross98be1bb2019-12-13 20:41:13 -0800676 // add some modules that are required by the compiler and/or linker
677 bp = bp + GatherRequiredDepsForTest(os)
678
Colin Cross2fce23a2020-06-07 17:02:48 -0700679 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800680
Colin Crossf28329d2020-02-15 11:00:10 -0800681 GatherRequiredFilesForTest(mockFS)
682
Colin Cross98be1bb2019-12-13 20:41:13 -0800683 for k, v := range fs {
684 mockFS[k] = v
685 }
686
Colin Crosscb0ac952021-07-20 13:17:15 -0700687 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800688}
689
Paul Duffin02a3d652021-02-24 18:51:54 +0000690// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
691//
692// See testCc for an explanation as to how to stop using this deprecated method.
693//
694// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700695func CreateTestContext(config android.Config) *android.TestContext {
696 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000697 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000698 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800699 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400700 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800701 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
702 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000703
Kiyoung Kim973cb6f2024-04-29 14:14:53 +0900704 RegisterLlndkLibraryTxtType(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000705
Colin Crosse1bb5d02019-09-24 14:55:04 -0700706 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100707 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100708 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700709
Colin Cross9a942872019-05-14 15:44:26 -0700710 return ctx
711}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400712
713func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
714 t.Helper()
715 mod := ctx.ModuleForTests(moduleName, variant)
716 outputFiles := mod.OutputFiles(t, "")
717 if len(outputFiles) != 1 {
718 t.Errorf("%q must have single output\n", moduleName)
719 return
720 }
721 snapshotPath := filepath.Join(subDir, snapshotFilename)
722
723 if include {
724 out := singleton.Output(snapshotPath)
725 if fake {
726 if out.Rule == nil {
727 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
728 }
729 } else {
730 if out.Input.String() != outputFiles[0].String() {
731 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
732 }
733 }
734 } else {
735 out := singleton.MaybeOutput(snapshotPath)
736 if out.Rule != nil {
737 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
738 }
739 }
740}
741
742func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
743 t.Helper()
744 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
745}
746
747func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
748 t.Helper()
749 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
750}
751
752func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
753 t.Helper()
754 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
755}
756
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400757func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
758 for _, moduleName := range moduleNames {
759 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
760 output := module.outputFile.Path().RelativeToTop()
761 paths = append(paths, output)
762 }
763 return paths
764}