blob: 4b4e866d45b824ae5e6ebdaf7a6ea1f4a324f0b9 [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)
Paul Duffin6c26dc72019-12-19 15:02:40 +000038 ctx.RegisterModuleType("cc_object", ObjectFactory)
Wei Libcd39942021-09-16 23:57:28 +000039 ctx.RegisterModuleType("cc_genrule", GenRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080040 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070041 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070042 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Spandan Das319711b2023-09-19 19:04:41 +000043 ctx.RegisterModuleType("ndk_headers", NdkHeadersFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000044}
45
Paul Duffina04c1072020-03-02 10:16:35 +000046func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000047 ret := commonDefaultModules()
48
49 supportLinuxBionic := false
50 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000051 if os == android.Windows {
52 ret += withWindowsModules()
53 }
54 if os == android.LinuxBionic {
55 supportLinuxBionic = true
56 ret += withLinuxBionic()
57 }
58 }
59
60 if !supportLinuxBionic {
61 ret += withoutLinuxBionic()
62 }
63
64 return ret
65}
66
67func commonDefaultModules() string {
68 return `
Liz Kammer718eb272022-01-07 10:53:37 -050069 cc_defaults {
70 name: "toolchain_libs_defaults",
Colin Cross5dc62c92023-02-15 12:20:19 -080071 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090072 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090073 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090074 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050075 no_libcrt: true,
76 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090077 nocrt: true,
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -080078 no_crt_pad_segment: true,
Jooyung Han75568392020-03-20 04:29:24 +090079 system_shared_libs: [],
80 stl: "none",
Jooyung Han75568392020-03-20 04:29:24 +090081 check_elf_files: false,
82 sanitize: {
83 never: true,
84 },
Spandan Das4de7b492023-05-05 21:13:01 +000085 apex_available: [
86 "//apex_available:anyapex",
87 "//apex_available:platform",
88 ],
Jooyung Han75568392020-03-20 04:29:24 +090089 }
90
Liz Kammer718eb272022-01-07 10:53:37 -050091 cc_prebuilt_library_static {
92 name: "libcompiler_rt-extras",
93 defaults: ["toolchain_libs_defaults"],
94 vendor_ramdisk_available: true,
Colin Cross3e5e7782022-06-17 22:17:05 +000095 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -050096 }
97
98 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -080099 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -0800100 defaults: ["toolchain_libs_defaults"],
101 host_supported: true,
Colin Cross4c4c1be2022-02-10 11:41:18 -0800102 vendor_available: true,
103 vendor_ramdisk_available: true,
104 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000105 srcs: [""],
Colin Cross06c80eb2022-02-10 10:34:19 -0800106 }
107
Liz Kammer718eb272022-01-07 10:53:37 -0500108 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800109 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500110 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000111 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500112 }
113
114 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800115 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500116 defaults: [
117 "linux_bionic_supported",
118 "toolchain_libs_defaults",
119 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500120 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800121 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000122 srcs: [""],
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800123 }
124
Liz Kammer718eb272022-01-07 10:53:37 -0500125 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800126 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500127 defaults: [
128 "linux_bionic_supported",
129 "toolchain_libs_defaults",
130 ],
Colin Cross3e5e7782022-06-17 22:17:05 +0000131 srcs: [""],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700132 }
133
Paul Duffind6867912019-12-19 14:38:36 +0000134 // Needed for sanitizer
135 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800136 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500137 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000138 srcs: [""],
Paul Duffind6867912019-12-19 14:38:36 +0000139 }
140
Colin Cross06c80eb2022-02-10 10:34:19 -0800141 cc_prebuilt_library_static {
Colin Cross5dc62c92023-02-15 12:20:19 -0800142 name: "libclang_rt.ubsan_standalone.static",
143 defaults: ["toolchain_libs_defaults"],
144 srcs: [""],
145 }
146
147 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800148 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800149 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000150 host_supported: true,
151 target: {
152 android_arm64: {
153 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
154 },
155 android_arm: {
156 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
157 },
158 linux_glibc_x86_64: {
159 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
160 },
161 linux_glibc_x86: {
162 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
163 },
Colin Cross5dc62c92023-02-15 12:20:19 -0800164 linux_musl_x86_64: {
165 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
166 },
167 linux_musl_x86: {
168 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
169 },
Colin Cross3e5e7782022-06-17 22:17:05 +0000170 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800171 }
172
Inseob Kimc0907f12019-02-08 21:00:45 +0900173 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900174 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100175 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700176 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900177 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800178 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900179 system_shared_libs: [],
180 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800181 stubs: {
182 versions: ["27", "28", "29"],
183 },
Colin Cross203b4212021-04-26 17:19:41 -0700184 llndk: {
185 symbol_file: "libc.map.txt",
186 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900187 }
188 cc_library {
189 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100190 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700191 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900192 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800193 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 system_shared_libs: [],
195 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800196 stubs: {
197 versions: ["27", "28", "29"],
198 },
199 apex_available: [
200 "//apex_available:platform",
201 "myapex"
202 ],
Colin Cross203b4212021-04-26 17:19:41 -0700203 llndk: {
204 symbol_file: "libm.map.txt",
205 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900206 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400207
208 // Coverage libraries
209 cc_library {
210 name: "libprofile-extras",
211 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500212 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900213 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400214 recovery_available: true,
215 native_coverage: false,
216 system_shared_libs: [],
217 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400218 }
219 cc_library {
220 name: "libprofile-clang-extras",
221 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500222 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900223 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400224 recovery_available: true,
225 native_coverage: false,
226 system_shared_libs: [],
227 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400228 }
229 cc_library {
230 name: "libprofile-extras_ndk",
231 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900232 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400233 native_coverage: false,
234 system_shared_libs: [],
235 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400236 sdk_version: "current",
237 }
238 cc_library {
239 name: "libprofile-clang-extras_ndk",
240 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900241 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400242 native_coverage: false,
243 system_shared_libs: [],
244 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400245 sdk_version: "current",
246 }
247
Inseob Kimc0907f12019-02-08 21:00:45 +0900248 cc_library {
249 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100250 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700251 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900252 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800253 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900254 system_shared_libs: [],
255 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800256 stubs: {
257 versions: ["27", "28", "29"],
258 },
259 apex_available: [
260 "//apex_available:platform",
261 "myapex"
262 ],
Colin Cross203b4212021-04-26 17:19:41 -0700263 llndk: {
264 symbol_file: "libdl.map.txt",
265 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900266 }
267 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900268 name: "libft2",
269 no_libcrt: true,
270 nocrt: true,
271 system_shared_libs: [],
272 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700273 llndk: {
274 symbol_file: "libft2.map.txt",
275 private: true,
276 }
Jooyung Han097087b2019-10-22 19:32:18 +0900277 }
278 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900279 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700280 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900281 nocrt: true,
282 system_shared_libs: [],
283 stl: "none",
284 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500285 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900286 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900287 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900288 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900289 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900290 apex_available: [
291 "//apex_available:platform",
292 "//apex_available:anyapex",
293 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900294 }
295 cc_library {
296 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700297 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 nocrt: true,
299 system_shared_libs: [],
300 stl: "none",
301 vendor_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 {
Dan Albert2da19cb2019-07-24 12:17:40 -0700313 name: "libc++demangle",
314 no_libcrt: true,
315 nocrt: true,
316 system_shared_libs: [],
317 stl: "none",
318 host_supported: false,
319 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500320 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900321 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700322 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900323 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900324 apex_available: [
325 "//apex_available:platform",
326 "//apex_available:anyapex",
327 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700328 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900329
Jiyong Park541142c2020-03-07 16:35:46 +0900330 cc_defaults {
331 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100332 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900333 recovery_available: true,
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,
Jiyong Park541142c2020-03-07 16:35:46 +0900337 native_bridge_supported: true,
338 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700339 min_sdk_version: "16",
340 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700341 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900342 apex_available: [
343 "//apex_available:platform",
344 "//apex_available:anyapex",
345 ],
346 }
347
Inseob Kimc0907f12019-02-08 21:00:45 +0900348 cc_object {
349 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900350 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900351 srcs: ["crtbegin_so.c"],
352 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900353 }
354
355 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700356 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900357 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900358 srcs: ["crtbegin.c"],
359 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700360 }
361
362 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900363 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900364 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900365 srcs: ["crtbegin.c"],
366 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900367 }
368
369 cc_object {
370 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900371 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900372 srcs: ["crtend_so.c"],
373 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900374 }
375
376 cc_object {
377 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900378 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900379 srcs: ["crtend.c"],
380 objs: ["crtbrand"],
381 }
382
383 cc_object {
Kalesh Singhf4ffe0a2024-01-29 13:01:51 -0800384 name: "crt_pad_segment",
385 defaults: ["crt_defaults"],
386 }
387
388 cc_object {
Jiyong Park7549d462021-08-25 16:16:03 +0900389 name: "crtbrand",
390 defaults: ["crt_defaults"],
391 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900392 }
393
394 cc_library {
395 name: "libprotobuf-cpp-lite",
396 }
Colin Crossf28329d2020-02-15 11:00:10 -0800397
398 cc_library {
399 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700400 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800401 stl: "none",
402 system_shared_libs: [],
403 }
404
Dan Albertde5aade2020-06-30 12:32:51 -0700405 ndk_library {
406 name: "libc",
407 first_version: "minimum",
408 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800409 }
410
Dan Albertde5aade2020-06-30 12:32:51 -0700411 ndk_library {
412 name: "libm",
413 first_version: "minimum",
414 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800415 }
416
Dan Albertde5aade2020-06-30 12:32:51 -0700417 ndk_library {
418 name: "libdl",
419 first_version: "minimum",
420 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800421 }
422
Colin Crossf28329d2020-02-15 11:00:10 -0800423 ndk_prebuilt_shared_stl {
424 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700425 export_include_dirs: ["ndk_libc++_shared"],
426 }
427
Jiyong Park46a512f2020-12-04 18:02:13 +0900428 cc_library_static {
429 name: "libgoogle-benchmark",
430 sdk_version: "current",
431 stl: "none",
432 system_shared_libs: [],
433 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700434
435 cc_library_static {
436 name: "note_memtag_heap_async",
437 }
438
439 cc_library_static {
440 name: "note_memtag_heap_sync",
441 }
Colin Cross528d67e2021-07-23 22:23:07 +0000442
Colin Cross528d67e2021-07-23 22:23:07 +0000443 cc_library {
444 name: "libc_musl",
445 host_supported: true,
446 no_libcrt: true,
447 nocrt: true,
448 system_shared_libs: [],
449 stl: "none",
450 }
Colin Crossf28329d2020-02-15 11:00:10 -0800451 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000452}
Colin Crossf28329d2020-02-15 11:00:10 -0800453
Paul Duffin02a3d652021-02-24 18:51:54 +0000454func withWindowsModules() string {
455 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500456 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000457 name: "libwinpthread",
458 host_supported: true,
459 enabled: false,
460 target: {
461 windows: {
462 enabled: true,
463 },
464 },
Liz Kammer718eb272022-01-07 10:53:37 -0500465 stl: "none",
466 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000467 }
468 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000469}
470
Paul Duffin02a3d652021-02-24 18:51:54 +0000471func withLinuxBionic() string {
472 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100473 cc_binary {
474 name: "linker",
475 defaults: ["linux_bionic_supported"],
476 recovery_available: true,
477 stl: "none",
478 nocrt: true,
479 static_executable: true,
480 native_coverage: false,
481 system_shared_libs: [],
482 }
483
484 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700485 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100486 host_supported: true,
487 device_supported: false,
488 target: {
489 host: {
490 enabled: false,
491 },
492 linux_bionic: {
493 enabled: true,
494 },
495 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700496 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100497 }
498
499 cc_defaults {
500 name: "linux_bionic_supported",
501 host_supported: true,
502 target: {
503 host: {
504 enabled: false,
505 },
506 linux_bionic: {
507 enabled: true,
508 },
509 },
510 }
511 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000512}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100513
Paul Duffin02a3d652021-02-24 18:51:54 +0000514func withoutLinuxBionic() string {
515 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100516 cc_defaults {
517 name: "linux_bionic_supported",
518 }
519 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900520}
Colin Cross9a942872019-05-14 15:44:26 -0700521
Colin Crossf28329d2020-02-15 11:00:10 -0800522func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800523}
524
Paul Duffin02a3d652021-02-24 18:51:54 +0000525// The directory in which cc linux bionic default modules will be defined.
526//
527// Placing them here ensures that their location does not conflict with default test modules
528// defined by other packages.
529const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
530
531// The directory in which the default cc common test modules will be defined.
532//
533// Placing them here ensures that their location does not conflict with default test modules
534// defined by other packages.
535const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
536
537// Test fixture preparer that will register most cc build components.
538//
539// Singletons and mutators should only be added here if they are needed for a majority of cc
540// module types, otherwise they should be added under a separate preparer to allow them to be
541// selected only when needed to reduce test execution time.
542//
543// Module types do not have much of an overhead unless they are used so this should include as many
544// module types as possible. The exceptions are those module types that require mutators and/or
545// singletons in order to function in which case they should be kept together in a separate
546// preparer.
547var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
548 android.PrepareForTestWithAndroidBuildComponents,
549 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
550 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000551 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000552 ctx.RegisterModuleType("cc_test", TestFactory)
553 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000554 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
555
556 RegisterVndkLibraryTxtTypes(ctx)
Kiyoung Kim973cb6f2024-04-29 14:14:53 +0900557 RegisterLlndkLibraryTxtType(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000558 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000559
560 // Additional files needed in tests that disallow non-existent source files.
561 // This includes files that are needed by all, or at least most, instances of a cc module type.
562 android.MockFS{
563 // Needed for ndk_prebuilt_(shared|static)_stl.
Spandan Das6e332d22023-09-13 17:58:52 +0000564 "defaults/cc/common/current/sources/cxx-stl/llvm-libc++/libs": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000565 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000566)
567
568// Preparer that will define default cc modules, e.g. standard prebuilt modules.
569var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
570 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000571
572 // Additional files needed in tests that disallow non-existent source.
573 android.MockFS{
Kiyoung Kim973cb6f2024-04-29 14:14:53 +0900574 "defaults/cc/common/libc.map.txt": nil,
575 "defaults/cc/common/libdl.map.txt": nil,
576 "defaults/cc/common/libft2.map.txt": nil,
577 "defaults/cc/common/libm.map.txt": nil,
578 "defaults/cc/common/ndk_libc++_shared": nil,
579 "defaults/cc/common/crtbegin_so.c": nil,
580 "defaults/cc/common/crtbegin.c": nil,
581 "defaults/cc/common/crtend_so.c": nil,
582 "defaults/cc/common/crtend.c": nil,
583 "defaults/cc/common/crtbrand.c": nil,
584 "external/compiler-rt/lib/cfi/cfi_blocklist.txt": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000585
586 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
587 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
588 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
589 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000590 }.AddToFixture(),
591
Paul Duffin02a3d652021-02-24 18:51:54 +0000592 // Place the default cc test modules that are common to all platforms in a location that will not
593 // conflict with default test modules defined by other packages.
594 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
595 // Disable linux bionic by default.
596 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
597)
598
599// Prepare a fixture to use all cc module types, mutators and singletons fully.
600//
601// This should only be used by tests that want to run with as much of the build enabled as possible.
602var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
603 android.PrepareForIntegrationTestWithAndroid,
604 genrule.PrepareForIntegrationTestWithGenrule,
605 PrepareForTestWithCcDefaultModules,
606)
607
608// The preparer to include if running a cc related test for windows.
609var PrepareForTestOnWindows = android.GroupFixturePreparers(
610 // Place the default cc test modules for windows platforms in a location that will not conflict
611 // with default test modules defined by other packages.
612 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
613)
614
615// The preparer to include if running a cc related test for linux bionic.
616var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000617 // Enable linux bionic
618 //
619 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
620 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
621 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000622)
623
Colin Cross5dc62c92023-02-15 12:20:19 -0800624// PrepareForTestWithHostMusl sets the host configuration to musl libc instead of glibc. It also disables the test
625// on mac, which doesn't support musl libc, and adds musl modules.
626var PrepareForTestWithHostMusl = android.GroupFixturePreparers(
627 android.FixtureModifyConfig(android.ModifyTestConfigForMusl),
628 android.PrepareForSkipTestOnMac,
629 android.FixtureAddTextFile("external/musl/Android.bp", `
630 cc_defaults {
631 name: "libc_musl_crt_defaults",
632 host_supported: true,
633 device_supported: false,
634 }
635
636 cc_object {
637 name: "libc_musl_crtbegin_so",
638 defaults: ["libc_musl_crt_defaults"],
639 }
640
641 cc_object {
642 name: "libc_musl_crtend_so",
643 defaults: ["libc_musl_crt_defaults"],
644 }
645
646 cc_object {
647 name: "libc_musl_crtbegin_dynamic",
648 defaults: ["libc_musl_crt_defaults"],
649 }
650
651 cc_object {
652 name: "libc_musl_crtbegin_static",
653 defaults: ["libc_musl_crt_defaults"],
654 }
655
656 cc_object {
657 name: "libc_musl_crtend",
658 defaults: ["libc_musl_crt_defaults"],
659 }
660 `),
661)
662
Vinh Trancde10162023-03-09 22:07:19 -0500663// PrepareForTestWithFdoProfile registers module types to test with fdo_profile
664var PrepareForTestWithFdoProfile = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
665 ctx.RegisterModuleType("soong_namespace", android.NamespaceFactory)
Vinh Trance40b922023-06-05 12:57:55 -0400666 ctx.RegisterModuleType("fdo_profile", FdoProfileFactory)
Vinh Trancde10162023-03-09 22:07:19 -0500667})
668
Paul Duffin02a3d652021-02-24 18:51:54 +0000669// TestConfig is the legacy way of creating a test Config for testing cc modules.
670//
671// See testCc for an explanation as to how to stop using this deprecated method.
672//
673// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800674func TestConfig(buildDir string, os android.OsType, env map[string]string,
675 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700676
Colin Cross98be1bb2019-12-13 20:41:13 -0800677 // add some modules that are required by the compiler and/or linker
678 bp = bp + GatherRequiredDepsForTest(os)
679
Colin Cross2fce23a2020-06-07 17:02:48 -0700680 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800681
Colin Crossf28329d2020-02-15 11:00:10 -0800682 GatherRequiredFilesForTest(mockFS)
683
Colin Cross98be1bb2019-12-13 20:41:13 -0800684 for k, v := range fs {
685 mockFS[k] = v
686 }
687
Colin Crosscb0ac952021-07-20 13:17:15 -0700688 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800689}
690
Paul Duffin02a3d652021-02-24 18:51:54 +0000691// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
692//
693// See testCc for an explanation as to how to stop using this deprecated method.
694//
695// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700696func CreateTestContext(config android.Config) *android.TestContext {
697 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000698 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000699 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800700 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400701 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800702 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
703 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000704
Colin Crosse4e44bc2020-12-28 13:50:21 -0800705 RegisterVndkLibraryTxtTypes(ctx)
Kiyoung Kim973cb6f2024-04-29 14:14:53 +0900706 RegisterLlndkLibraryTxtType(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000707
Colin Crosse1bb5d02019-09-24 14:55:04 -0700708 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100709 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100710 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700711
Colin Cross9a942872019-05-14 15:44:26 -0700712 return ctx
713}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400714
715func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
716 t.Helper()
717 mod := ctx.ModuleForTests(moduleName, variant)
718 outputFiles := mod.OutputFiles(t, "")
719 if len(outputFiles) != 1 {
720 t.Errorf("%q must have single output\n", moduleName)
721 return
722 }
723 snapshotPath := filepath.Join(subDir, snapshotFilename)
724
725 if include {
726 out := singleton.Output(snapshotPath)
727 if fake {
728 if out.Rule == nil {
729 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
730 }
731 } else {
732 if out.Input.String() != outputFiles[0].String() {
733 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
734 }
735 }
736 } else {
737 out := singleton.MaybeOutput(snapshotPath)
738 if out.Rule != nil {
739 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
740 }
741 }
742}
743
744func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
745 t.Helper()
746 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
747}
748
749func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
750 t.Helper()
751 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
752}
753
754func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
755 t.Helper()
756 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
757}
758
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400759func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
760 for _, moduleName := range moduleNames {
761 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
762 output := module.outputFile.Path().RelativeToTop()
763 paths = append(paths, output)
764 }
765 return paths
766}