blob: 44a865d2ae7d0930f38e5811ba1319ecde6ed0a0 [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"
Kiyoung Kim48f37782021-07-07 12:42:39 +090024 "android/soong/snapshot"
Inseob Kimc0907f12019-02-08 21:00:45 +090025)
26
Paul Duffin77980a82019-12-19 16:01:36 +000027func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000028 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000029 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000030 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000031 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000032 RegisterLibraryHeadersBuildComponents(ctx)
Inseob Kim5eb7ee92022-04-27 10:30:34 +090033 RegisterLibraryStubBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000034
Kiyoung Kim487689e2022-07-26 09:48:22 +090035 multitree.RegisterApiImportsModule(ctx)
36
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)
Colin Crossf28329d2020-02-15 11:00:10 -080042 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070043 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
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",
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,
Jooyung Han75568392020-03-20 04:29:24 +090077 system_shared_libs: [],
78 stl: "none",
Jooyung Han75568392020-03-20 04:29:24 +090079 check_elf_files: false,
80 sanitize: {
81 never: true,
82 },
83 }
84
Liz Kammer718eb272022-01-07 10:53:37 -050085 cc_prebuilt_library_static {
86 name: "libcompiler_rt-extras",
87 defaults: ["toolchain_libs_defaults"],
88 vendor_ramdisk_available: true,
Colin Cross3e5e7782022-06-17 22:17:05 +000089 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -050090 }
91
92 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -080093 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -080094 defaults: ["toolchain_libs_defaults"],
95 host_supported: true,
Colin Cross4c4c1be2022-02-10 11:41:18 -080096 vendor_available: true,
97 vendor_ramdisk_available: true,
98 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +000099 srcs: [""],
Colin Cross06c80eb2022-02-10 10:34:19 -0800100 }
101
Liz Kammer718eb272022-01-07 10:53:37 -0500102 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800103 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500104 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000105 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500106 }
107
108 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800109 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500110 defaults: [
111 "linux_bionic_supported",
112 "toolchain_libs_defaults",
113 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500114 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800115 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000116 srcs: [""],
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800117 }
118
Liz Kammer718eb272022-01-07 10:53:37 -0500119 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800120 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500121 defaults: [
122 "linux_bionic_supported",
123 "toolchain_libs_defaults",
124 ],
Colin Cross3e5e7782022-06-17 22:17:05 +0000125 srcs: [""],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700126 }
127
Paul Duffind6867912019-12-19 14:38:36 +0000128 // Needed for sanitizer
129 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800130 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500131 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000132 srcs: [""],
Paul Duffind6867912019-12-19 14:38:36 +0000133 }
134
Colin Cross06c80eb2022-02-10 10:34:19 -0800135 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800136 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800137 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000138 host_supported: true,
139 target: {
140 android_arm64: {
141 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
142 },
143 android_arm: {
144 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
145 },
146 linux_glibc_x86_64: {
147 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
148 },
149 linux_glibc_x86: {
150 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
151 },
152 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800153 }
154
Inseob Kimc0907f12019-02-08 21:00:45 +0900155 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900156 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100157 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700158 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900159 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800160 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900161 system_shared_libs: [],
162 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800163 stubs: {
164 versions: ["27", "28", "29"],
165 },
Colin Cross203b4212021-04-26 17:19:41 -0700166 llndk: {
167 symbol_file: "libc.map.txt",
168 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900169 }
170 cc_library {
171 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100172 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700173 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900174 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800175 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900176 system_shared_libs: [],
177 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800178 stubs: {
179 versions: ["27", "28", "29"],
180 },
181 apex_available: [
182 "//apex_available:platform",
183 "myapex"
184 ],
Colin Cross203b4212021-04-26 17:19:41 -0700185 llndk: {
186 symbol_file: "libm.map.txt",
187 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900188 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400189
190 // Coverage libraries
191 cc_library {
192 name: "libprofile-extras",
193 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500194 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900195 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400196 recovery_available: true,
197 native_coverage: false,
198 system_shared_libs: [],
199 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400200 }
201 cc_library {
202 name: "libprofile-clang-extras",
203 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500204 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900205 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400206 recovery_available: true,
207 native_coverage: false,
208 system_shared_libs: [],
209 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400210 }
211 cc_library {
212 name: "libprofile-extras_ndk",
213 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900214 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400215 native_coverage: false,
216 system_shared_libs: [],
217 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400218 sdk_version: "current",
219 }
220 cc_library {
221 name: "libprofile-clang-extras_ndk",
222 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900223 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400224 native_coverage: false,
225 system_shared_libs: [],
226 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400227 sdk_version: "current",
228 }
229
Inseob Kimc0907f12019-02-08 21:00:45 +0900230 cc_library {
231 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100232 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700233 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900234 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800235 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900236 system_shared_libs: [],
237 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800238 stubs: {
239 versions: ["27", "28", "29"],
240 },
241 apex_available: [
242 "//apex_available:platform",
243 "myapex"
244 ],
Colin Cross203b4212021-04-26 17:19:41 -0700245 llndk: {
246 symbol_file: "libdl.map.txt",
247 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900248 }
249 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900250 name: "libft2",
251 no_libcrt: true,
252 nocrt: true,
253 system_shared_libs: [],
254 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700255 llndk: {
256 symbol_file: "libft2.map.txt",
257 private: true,
258 }
Jooyung Han097087b2019-10-22 19:32:18 +0900259 }
260 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900261 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700262 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900263 nocrt: true,
264 system_shared_libs: [],
265 stl: "none",
266 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500267 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900268 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900269 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900270 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900271 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900272 apex_available: [
273 "//apex_available:platform",
274 "//apex_available:anyapex",
275 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900276 }
277 cc_library {
278 name: "libc++",
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,
Justin Yun63e9ec72020-10-29 16:49:43 +0900284 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900285 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900286 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900287 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900288 vndk: {
289 enabled: true,
290 support_system_process: true,
291 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800292 apex_available: [
293 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500294 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800295 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900296 }
297 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700298 name: "libc++demangle",
299 no_libcrt: true,
300 nocrt: true,
301 system_shared_libs: [],
302 stl: "none",
303 host_supported: false,
304 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500305 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900306 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700307 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900308 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900309 apex_available: [
310 "//apex_available:platform",
311 "//apex_available:anyapex",
312 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700313 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900314
Jiyong Park541142c2020-03-07 16:35:46 +0900315 cc_defaults {
316 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100317 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900318 recovery_available: true,
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,
Jiyong Park541142c2020-03-07 16:35:46 +0900322 native_bridge_supported: true,
323 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700324 min_sdk_version: "16",
325 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700326 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900327 apex_available: [
328 "//apex_available:platform",
329 "//apex_available:anyapex",
330 ],
331 }
332
Inseob Kimc0907f12019-02-08 21:00:45 +0900333 cc_object {
334 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900335 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900336 srcs: ["crtbegin_so.c"],
337 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900338 }
339
340 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700341 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900342 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900343 srcs: ["crtbegin.c"],
344 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700345 }
346
347 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900348 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900349 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900350 srcs: ["crtbegin.c"],
351 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900352 }
353
354 cc_object {
355 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900356 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900357 srcs: ["crtend_so.c"],
358 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900359 }
360
361 cc_object {
362 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900363 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900364 srcs: ["crtend.c"],
365 objs: ["crtbrand"],
366 }
367
368 cc_object {
369 name: "crtbrand",
370 defaults: ["crt_defaults"],
371 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900372 }
373
374 cc_library {
375 name: "libprotobuf-cpp-lite",
376 }
Colin Crossf28329d2020-02-15 11:00:10 -0800377
378 cc_library {
379 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700380 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800381 stl: "none",
382 system_shared_libs: [],
383 }
384
Dan Albertde5aade2020-06-30 12:32:51 -0700385 ndk_library {
386 name: "libc",
387 first_version: "minimum",
388 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800389 }
390
Dan Albertde5aade2020-06-30 12:32:51 -0700391 ndk_library {
392 name: "libm",
393 first_version: "minimum",
394 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800395 }
396
Dan Albertde5aade2020-06-30 12:32:51 -0700397 ndk_library {
398 name: "libdl",
399 first_version: "minimum",
400 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800401 }
402
Colin Crossf28329d2020-02-15 11:00:10 -0800403 ndk_prebuilt_shared_stl {
404 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700405 export_include_dirs: ["ndk_libc++_shared"],
406 }
407
408 ndk_prebuilt_static_stl {
409 name: "ndk_libandroid_support",
410 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800411 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900412
413 cc_library_static {
414 name: "libgoogle-benchmark",
415 sdk_version: "current",
416 stl: "none",
417 system_shared_libs: [],
418 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700419
420 cc_library_static {
421 name: "note_memtag_heap_async",
422 }
423
424 cc_library_static {
425 name: "note_memtag_heap_sync",
426 }
Colin Cross528d67e2021-07-23 22:23:07 +0000427
Colin Cross528d67e2021-07-23 22:23:07 +0000428 cc_library {
429 name: "libc_musl",
430 host_supported: true,
431 no_libcrt: true,
432 nocrt: true,
433 system_shared_libs: [],
434 stl: "none",
435 }
Colin Crossf28329d2020-02-15 11:00:10 -0800436 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000437}
Colin Crossf28329d2020-02-15 11:00:10 -0800438
Paul Duffin02a3d652021-02-24 18:51:54 +0000439func withWindowsModules() string {
440 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500441 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000442 name: "libwinpthread",
443 host_supported: true,
444 enabled: false,
445 target: {
446 windows: {
447 enabled: true,
448 },
449 },
Liz Kammer718eb272022-01-07 10:53:37 -0500450 stl: "none",
451 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000452 }
453 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000454}
455
Paul Duffin02a3d652021-02-24 18:51:54 +0000456func withLinuxBionic() string {
457 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100458 cc_binary {
459 name: "linker",
460 defaults: ["linux_bionic_supported"],
461 recovery_available: true,
462 stl: "none",
463 nocrt: true,
464 static_executable: true,
465 native_coverage: false,
466 system_shared_libs: [],
467 }
468
469 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700470 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100471 host_supported: true,
472 device_supported: false,
473 target: {
474 host: {
475 enabled: false,
476 },
477 linux_bionic: {
478 enabled: true,
479 },
480 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700481 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100482 }
483
484 cc_defaults {
485 name: "linux_bionic_supported",
486 host_supported: true,
487 target: {
488 host: {
489 enabled: false,
490 },
491 linux_bionic: {
492 enabled: true,
493 },
494 },
495 }
496 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000497}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100498
Paul Duffin02a3d652021-02-24 18:51:54 +0000499func withoutLinuxBionic() string {
500 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100501 cc_defaults {
502 name: "linux_bionic_supported",
503 }
504 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900505}
Colin Cross9a942872019-05-14 15:44:26 -0700506
Colin Crossf28329d2020-02-15 11:00:10 -0800507func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800508}
509
Paul Duffin02a3d652021-02-24 18:51:54 +0000510// The directory in which cc linux bionic default modules will be defined.
511//
512// Placing them here ensures that their location does not conflict with default test modules
513// defined by other packages.
514const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
515
516// The directory in which the default cc common test modules will be defined.
517//
518// Placing them here ensures that their location does not conflict with default test modules
519// defined by other packages.
520const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
521
522// Test fixture preparer that will register most cc build components.
523//
524// Singletons and mutators should only be added here if they are needed for a majority of cc
525// module types, otherwise they should be added under a separate preparer to allow them to be
526// selected only when needed to reduce test execution time.
527//
528// Module types do not have much of an overhead unless they are used so this should include as many
529// module types as possible. The exceptions are those module types that require mutators and/or
530// singletons in order to function in which case they should be kept together in a separate
531// preparer.
532var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
533 android.PrepareForTestWithAndroidBuildComponents,
534 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
535 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000536 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000537 ctx.RegisterModuleType("cc_test", TestFactory)
538 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000539 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
540
541 RegisterVndkLibraryTxtTypes(ctx)
542 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000543
544 // Additional files needed in tests that disallow non-existent source files.
545 // This includes files that are needed by all, or at least most, instances of a cc module type.
546 android.MockFS{
547 // Needed for ndk_prebuilt_(shared|static)_stl.
548 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
549 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000550)
551
552// Preparer that will define default cc modules, e.g. standard prebuilt modules.
553var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
554 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000555
556 // Additional files needed in tests that disallow non-existent source.
557 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700558 "defaults/cc/common/libc.map.txt": nil,
559 "defaults/cc/common/libdl.map.txt": nil,
560 "defaults/cc/common/libm.map.txt": nil,
561 "defaults/cc/common/ndk_libandroid_support": nil,
562 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900563 "defaults/cc/common/crtbegin_so.c": nil,
564 "defaults/cc/common/crtbegin.c": nil,
565 "defaults/cc/common/crtend_so.c": nil,
566 "defaults/cc/common/crtend.c": nil,
567 "defaults/cc/common/crtbrand.c": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000568
569 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
570 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
571 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
572 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000573 }.AddToFixture(),
574
Paul Duffin02a3d652021-02-24 18:51:54 +0000575 // Place the default cc test modules that are common to all platforms in a location that will not
576 // conflict with default test modules defined by other packages.
577 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
578 // Disable linux bionic by default.
579 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
580)
581
582// Prepare a fixture to use all cc module types, mutators and singletons fully.
583//
584// This should only be used by tests that want to run with as much of the build enabled as possible.
585var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
586 android.PrepareForIntegrationTestWithAndroid,
587 genrule.PrepareForIntegrationTestWithGenrule,
588 PrepareForTestWithCcDefaultModules,
589)
590
591// The preparer to include if running a cc related test for windows.
592var PrepareForTestOnWindows = android.GroupFixturePreparers(
593 // Place the default cc test modules for windows platforms in a location that will not conflict
594 // with default test modules defined by other packages.
595 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
596)
597
598// The preparer to include if running a cc related test for linux bionic.
599var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000600 // Enable linux bionic
601 //
602 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
603 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
604 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000605)
606
607// This adds some additional modules and singletons which might negatively impact the performance
608// of tests so they are not included in the PrepareForIntegrationTestWithCc.
609var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
610 PrepareForIntegrationTestWithCc,
611 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900612 snapshot.VendorSnapshotImageSingleton.Init(ctx)
613 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
614 RegisterVendorSnapshotModules(ctx)
615 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000616 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
617 }),
618)
619
620// TestConfig is the legacy way of creating a test Config for testing cc modules.
621//
622// See testCc for an explanation as to how to stop using this deprecated method.
623//
624// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800625func TestConfig(buildDir string, os android.OsType, env map[string]string,
626 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700627
Colin Cross98be1bb2019-12-13 20:41:13 -0800628 // add some modules that are required by the compiler and/or linker
629 bp = bp + GatherRequiredDepsForTest(os)
630
Colin Cross2fce23a2020-06-07 17:02:48 -0700631 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800632
Colin Crossf28329d2020-02-15 11:00:10 -0800633 GatherRequiredFilesForTest(mockFS)
634
Colin Cross98be1bb2019-12-13 20:41:13 -0800635 for k, v := range fs {
636 mockFS[k] = v
637 }
638
Colin Crosscb0ac952021-07-20 13:17:15 -0700639 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800640}
641
Paul Duffin02a3d652021-02-24 18:51:54 +0000642// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
643//
644// See testCc for an explanation as to how to stop using this deprecated method.
645//
646// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700647func CreateTestContext(config android.Config) *android.TestContext {
648 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000649 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000650 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800651 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400652 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800653 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
654 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000655
Kiyoung Kim48f37782021-07-07 12:42:39 +0900656 snapshot.VendorSnapshotImageSingleton.Init(ctx)
657 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
658 RegisterVendorSnapshotModules(ctx)
659 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000660 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800661 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000662
Colin Crosse1bb5d02019-09-24 14:55:04 -0700663 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100664 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100665 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700666
Colin Cross9a942872019-05-14 15:44:26 -0700667 return ctx
668}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400669
670func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
671 t.Helper()
672 mod := ctx.ModuleForTests(moduleName, variant)
673 outputFiles := mod.OutputFiles(t, "")
674 if len(outputFiles) != 1 {
675 t.Errorf("%q must have single output\n", moduleName)
676 return
677 }
678 snapshotPath := filepath.Join(subDir, snapshotFilename)
679
680 if include {
681 out := singleton.Output(snapshotPath)
682 if fake {
683 if out.Rule == nil {
684 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
685 }
686 } else {
687 if out.Input.String() != outputFiles[0].String() {
688 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
689 }
690 }
691 } else {
692 out := singleton.MaybeOutput(snapshotPath)
693 if out.Rule != nil {
694 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
695 }
696 }
697}
698
699func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
700 t.Helper()
701 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
702}
703
704func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
705 t.Helper()
706 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
707}
708
709func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
710 t.Helper()
711 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
712}
713
714func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
715 t.Helper()
716 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
717 if m.ExcludeFromVendorSnapshot() != expected {
718 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
719 }
720}
721
722func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
723 for _, moduleName := range moduleNames {
724 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
725 output := module.outputFile.Path().RelativeToTop()
726 paths = append(paths, output)
727 }
728 return paths
729}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500730
731func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
732 t.Helper()
733 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
734 if m.ExcludeFromRecoverySnapshot() != expected {
735 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
736 }
737}