blob: 07bee01be88614e8c516ad9ef5ddb2c13bfe97a5 [file] [log] [blame]
Inseob Kimc0907f12019-02-08 21:00:45 +09001// Copyright (C) 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
Inseob Kima1888ce2022-10-04 14:42:02 +090018 "encoding/json"
Ivan Lozanod67a6b02021-05-20 13:01:32 -040019 "path/filepath"
20 "testing"
21
Inseob Kimc0907f12019-02-08 21:00:45 +090022 "android/soong/android"
Colin Crosse9fe2942020-11-10 18:12:15 -080023 "android/soong/genrule"
Kiyoung Kim487689e2022-07-26 09:48:22 +090024 "android/soong/multitree"
Kiyoung Kim48f37782021-07-07 12:42:39 +090025 "android/soong/snapshot"
Inseob Kimc0907f12019-02-08 21:00:45 +090026)
27
Paul Duffin77980a82019-12-19 16:01:36 +000028func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000029 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000030 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000031 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000032 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000033 RegisterLibraryHeadersBuildComponents(ctx)
Inseob Kim5eb7ee92022-04-27 10:30:34 +090034 RegisterLibraryStubBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000035
Kiyoung Kim487689e2022-07-26 09:48:22 +090036 multitree.RegisterApiImportsModule(ctx)
37
Jiyong Park46a512f2020-12-04 18:02:13 +090038 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
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)
Colin Crossf28329d2020-02-15 11:00:10 -080041 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070042 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070043 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Spandan Das73bcafc2022-08-18 23:26:00 +000044 ctx.RegisterModuleType("ndk_headers", ndkHeadersFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000045}
46
Paul Duffina04c1072020-03-02 10:16:35 +000047func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000048 ret := commonDefaultModules()
49
50 supportLinuxBionic := false
51 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000052 if os == android.Windows {
53 ret += withWindowsModules()
54 }
55 if os == android.LinuxBionic {
56 supportLinuxBionic = true
57 ret += withLinuxBionic()
58 }
59 }
60
61 if !supportLinuxBionic {
62 ret += withoutLinuxBionic()
63 }
64
65 return ret
66}
67
68func commonDefaultModules() string {
69 return `
Liz Kammer718eb272022-01-07 10:53:37 -050070 cc_defaults {
71 name: "toolchain_libs_defaults",
Colin Cross5dc62c92023-02-15 12:20:19 -080072 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090073 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090074 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090075 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050076 no_libcrt: true,
77 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090078 nocrt: 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",
Inseob Kimc0907f12019-02-08 21:00:45 +0900306 vndk: {
307 enabled: true,
308 support_system_process: true,
309 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800310 apex_available: [
311 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500312 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800313 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900314 }
315 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700316 name: "libc++demangle",
317 no_libcrt: true,
318 nocrt: true,
319 system_shared_libs: [],
320 stl: "none",
321 host_supported: false,
322 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500323 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900324 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700325 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900326 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900327 apex_available: [
328 "//apex_available:platform",
329 "//apex_available:anyapex",
330 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700331 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900332
Jiyong Park541142c2020-03-07 16:35:46 +0900333 cc_defaults {
334 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100335 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900336 recovery_available: true,
337 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500338 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900339 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900340 native_bridge_supported: true,
341 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700342 min_sdk_version: "16",
343 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700344 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900345 apex_available: [
346 "//apex_available:platform",
347 "//apex_available:anyapex",
348 ],
349 }
350
Inseob Kimc0907f12019-02-08 21:00:45 +0900351 cc_object {
352 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900353 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900354 srcs: ["crtbegin_so.c"],
355 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900356 }
357
358 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700359 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900360 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900361 srcs: ["crtbegin.c"],
362 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700363 }
364
365 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900366 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900367 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900368 srcs: ["crtbegin.c"],
369 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900370 }
371
372 cc_object {
373 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900374 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900375 srcs: ["crtend_so.c"],
376 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900377 }
378
379 cc_object {
380 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900381 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900382 srcs: ["crtend.c"],
383 objs: ["crtbrand"],
384 }
385
386 cc_object {
387 name: "crtbrand",
388 defaults: ["crt_defaults"],
389 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900390 }
391
392 cc_library {
393 name: "libprotobuf-cpp-lite",
394 }
Colin Crossf28329d2020-02-15 11:00:10 -0800395
396 cc_library {
397 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700398 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800399 stl: "none",
400 system_shared_libs: [],
401 }
402
Dan Albertde5aade2020-06-30 12:32:51 -0700403 ndk_library {
404 name: "libc",
405 first_version: "minimum",
406 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800407 }
408
Dan Albertde5aade2020-06-30 12:32:51 -0700409 ndk_library {
410 name: "libm",
411 first_version: "minimum",
412 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800413 }
414
Dan Albertde5aade2020-06-30 12:32:51 -0700415 ndk_library {
416 name: "libdl",
417 first_version: "minimum",
418 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800419 }
420
Colin Crossf28329d2020-02-15 11:00:10 -0800421 ndk_prebuilt_shared_stl {
422 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700423 export_include_dirs: ["ndk_libc++_shared"],
424 }
425
Jiyong Park46a512f2020-12-04 18:02:13 +0900426 cc_library_static {
427 name: "libgoogle-benchmark",
428 sdk_version: "current",
429 stl: "none",
430 system_shared_libs: [],
431 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700432
433 cc_library_static {
434 name: "note_memtag_heap_async",
435 }
436
437 cc_library_static {
438 name: "note_memtag_heap_sync",
439 }
Colin Cross528d67e2021-07-23 22:23:07 +0000440
Colin Cross528d67e2021-07-23 22:23:07 +0000441 cc_library {
442 name: "libc_musl",
443 host_supported: true,
444 no_libcrt: true,
445 nocrt: true,
446 system_shared_libs: [],
447 stl: "none",
448 }
Colin Crossf28329d2020-02-15 11:00:10 -0800449 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000450}
Colin Crossf28329d2020-02-15 11:00:10 -0800451
Paul Duffin02a3d652021-02-24 18:51:54 +0000452func withWindowsModules() string {
453 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500454 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000455 name: "libwinpthread",
456 host_supported: true,
457 enabled: false,
458 target: {
459 windows: {
460 enabled: true,
461 },
462 },
Liz Kammer718eb272022-01-07 10:53:37 -0500463 stl: "none",
464 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000465 }
466 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000467}
468
Paul Duffin02a3d652021-02-24 18:51:54 +0000469func withLinuxBionic() string {
470 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100471 cc_binary {
472 name: "linker",
473 defaults: ["linux_bionic_supported"],
474 recovery_available: true,
475 stl: "none",
476 nocrt: true,
477 static_executable: true,
478 native_coverage: false,
479 system_shared_libs: [],
480 }
481
482 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700483 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100484 host_supported: true,
485 device_supported: false,
486 target: {
487 host: {
488 enabled: false,
489 },
490 linux_bionic: {
491 enabled: true,
492 },
493 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700494 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100495 }
496
497 cc_defaults {
498 name: "linux_bionic_supported",
499 host_supported: true,
500 target: {
501 host: {
502 enabled: false,
503 },
504 linux_bionic: {
505 enabled: true,
506 },
507 },
508 }
509 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000510}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100511
Paul Duffin02a3d652021-02-24 18:51:54 +0000512func withoutLinuxBionic() string {
513 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100514 cc_defaults {
515 name: "linux_bionic_supported",
516 }
517 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900518}
Colin Cross9a942872019-05-14 15:44:26 -0700519
Colin Crossf28329d2020-02-15 11:00:10 -0800520func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800521}
522
Paul Duffin02a3d652021-02-24 18:51:54 +0000523// The directory in which cc linux bionic default modules will be defined.
524//
525// Placing them here ensures that their location does not conflict with default test modules
526// defined by other packages.
527const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
528
529// The directory in which the default cc common test modules will be defined.
530//
531// Placing them here ensures that their location does not conflict with default test modules
532// defined by other packages.
533const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
534
535// Test fixture preparer that will register most cc build components.
536//
537// Singletons and mutators should only be added here if they are needed for a majority of cc
538// module types, otherwise they should be added under a separate preparer to allow them to be
539// selected only when needed to reduce test execution time.
540//
541// Module types do not have much of an overhead unless they are used so this should include as many
542// module types as possible. The exceptions are those module types that require mutators and/or
543// singletons in order to function in which case they should be kept together in a separate
544// preparer.
545var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
546 android.PrepareForTestWithAndroidBuildComponents,
547 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
548 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000549 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000550 ctx.RegisterModuleType("cc_test", TestFactory)
551 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000552 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
553
554 RegisterVndkLibraryTxtTypes(ctx)
555 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000556
557 // Additional files needed in tests that disallow non-existent source files.
558 // This includes files that are needed by all, or at least most, instances of a cc module type.
559 android.MockFS{
560 // Needed for ndk_prebuilt_(shared|static)_stl.
Spandan Das6e332d22023-09-13 17:58:52 +0000561 "defaults/cc/common/current/sources/cxx-stl/llvm-libc++/libs": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000562 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000563)
564
565// Preparer that will define default cc modules, e.g. standard prebuilt modules.
566var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
567 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000568
569 // Additional files needed in tests that disallow non-existent source.
570 android.MockFS{
Dan Albert94dd5652023-07-20 18:16:19 +0000571 "defaults/cc/common/libc.map.txt": nil,
572 "defaults/cc/common/libdl.map.txt": nil,
573 "defaults/cc/common/libm.map.txt": nil,
574 "defaults/cc/common/ndk_libc++_shared": nil,
575 "defaults/cc/common/crtbegin_so.c": nil,
576 "defaults/cc/common/crtbegin.c": nil,
577 "defaults/cc/common/crtend_so.c": nil,
578 "defaults/cc/common/crtend.c": nil,
579 "defaults/cc/common/crtbrand.c": 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
619// This adds some additional modules and singletons which might negatively impact the performance
620// of tests so they are not included in the PrepareForIntegrationTestWithCc.
621var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
622 PrepareForIntegrationTestWithCc,
623 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900624 snapshot.VendorSnapshotImageSingleton.Init(ctx)
625 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
626 RegisterVendorSnapshotModules(ctx)
627 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000628 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
629 }),
630)
631
Colin Cross5dc62c92023-02-15 12:20:19 -0800632// PrepareForTestWithHostMusl sets the host configuration to musl libc instead of glibc. It also disables the test
633// on mac, which doesn't support musl libc, and adds musl modules.
634var PrepareForTestWithHostMusl = android.GroupFixturePreparers(
635 android.FixtureModifyConfig(android.ModifyTestConfigForMusl),
636 android.PrepareForSkipTestOnMac,
637 android.FixtureAddTextFile("external/musl/Android.bp", `
638 cc_defaults {
639 name: "libc_musl_crt_defaults",
640 host_supported: true,
641 device_supported: false,
642 }
643
644 cc_object {
645 name: "libc_musl_crtbegin_so",
646 defaults: ["libc_musl_crt_defaults"],
647 }
648
649 cc_object {
650 name: "libc_musl_crtend_so",
651 defaults: ["libc_musl_crt_defaults"],
652 }
653
654 cc_object {
655 name: "libc_musl_crtbegin_dynamic",
656 defaults: ["libc_musl_crt_defaults"],
657 }
658
659 cc_object {
660 name: "libc_musl_crtbegin_static",
661 defaults: ["libc_musl_crt_defaults"],
662 }
663
664 cc_object {
665 name: "libc_musl_crtend",
666 defaults: ["libc_musl_crt_defaults"],
667 }
668 `),
669)
670
Vinh Trancde10162023-03-09 22:07:19 -0500671// PrepareForTestWithFdoProfile registers module types to test with fdo_profile
672var PrepareForTestWithFdoProfile = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
673 ctx.RegisterModuleType("soong_namespace", android.NamespaceFactory)
Vinh Trance40b922023-06-05 12:57:55 -0400674 ctx.RegisterModuleType("fdo_profile", FdoProfileFactory)
Vinh Trancde10162023-03-09 22:07:19 -0500675})
676
Paul Duffin02a3d652021-02-24 18:51:54 +0000677// TestConfig is the legacy way of creating a test Config for testing cc modules.
678//
679// See testCc for an explanation as to how to stop using this deprecated method.
680//
681// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800682func TestConfig(buildDir string, os android.OsType, env map[string]string,
683 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700684
Colin Cross98be1bb2019-12-13 20:41:13 -0800685 // add some modules that are required by the compiler and/or linker
686 bp = bp + GatherRequiredDepsForTest(os)
687
Colin Cross2fce23a2020-06-07 17:02:48 -0700688 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800689
Colin Crossf28329d2020-02-15 11:00:10 -0800690 GatherRequiredFilesForTest(mockFS)
691
Colin Cross98be1bb2019-12-13 20:41:13 -0800692 for k, v := range fs {
693 mockFS[k] = v
694 }
695
Colin Crosscb0ac952021-07-20 13:17:15 -0700696 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800697}
698
Paul Duffin02a3d652021-02-24 18:51:54 +0000699// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
700//
701// See testCc for an explanation as to how to stop using this deprecated method.
702//
703// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700704func CreateTestContext(config android.Config) *android.TestContext {
705 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000706 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000707 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800708 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400709 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800710 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
711 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000712
Kiyoung Kim48f37782021-07-07 12:42:39 +0900713 snapshot.VendorSnapshotImageSingleton.Init(ctx)
714 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
715 RegisterVendorSnapshotModules(ctx)
716 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000717 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800718 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000719
Colin Crosse1bb5d02019-09-24 14:55:04 -0700720 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100721 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100722 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700723
Colin Cross9a942872019-05-14 15:44:26 -0700724 return ctx
725}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400726
727func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
728 t.Helper()
729 mod := ctx.ModuleForTests(moduleName, variant)
730 outputFiles := mod.OutputFiles(t, "")
731 if len(outputFiles) != 1 {
732 t.Errorf("%q must have single output\n", moduleName)
733 return
734 }
735 snapshotPath := filepath.Join(subDir, snapshotFilename)
736
737 if include {
738 out := singleton.Output(snapshotPath)
739 if fake {
740 if out.Rule == nil {
741 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
742 }
743 } else {
744 if out.Input.String() != outputFiles[0].String() {
745 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
746 }
747 }
748 } else {
749 out := singleton.MaybeOutput(snapshotPath)
750 if out.Rule != nil {
751 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
752 }
753 }
754}
755
756func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
757 t.Helper()
758 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
759}
760
761func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
762 t.Helper()
763 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
764}
765
766func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
767 t.Helper()
768 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
769}
770
771func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
772 t.Helper()
773 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
774 if m.ExcludeFromVendorSnapshot() != expected {
775 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
776 }
777}
778
779func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
780 for _, moduleName := range moduleNames {
781 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
782 output := module.outputFile.Path().RelativeToTop()
783 paths = append(paths, output)
784 }
785 return paths
786}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500787
788func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
789 t.Helper()
790 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
791 if m.ExcludeFromRecoverySnapshot() != expected {
792 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
793 }
794}
Inseob Kima1888ce2022-10-04 14:42:02 +0900795
796func checkOverrides(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, jsonPath string, expected []string) {
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7a11dc82022-10-06 15:20:37 +0000797 t.Helper()
Inseob Kima1888ce2022-10-04 14:42:02 +0900798 out := singleton.MaybeOutput(jsonPath)
799 content := android.ContentFromFileRuleForTests(t, out)
800
801 var flags snapshotJsonFlags
802 if err := json.Unmarshal([]byte(content), &flags); err != nil {
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7a11dc82022-10-06 15:20:37 +0000803 t.Errorf("Error while unmarshalling json %q: %s", jsonPath, err.Error())
Inseob Kima1888ce2022-10-04 14:42:02 +0900804 return
805 }
806
807 for _, moduleName := range expected {
808 if !android.InList(moduleName, flags.Overrides) {
809 t.Errorf("expected %q to be in %q: %q", moduleName, flags.Overrides, content)
810 return
811 }
812 }
813}