blob: 40edd28f23e33a3237d60b3e47b335f80fc9295e [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",
200 notice: "custom_notice",
201 }
202 cc_library {
203 name: "libprofile-clang-extras",
204 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500205 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900206 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400207 recovery_available: true,
208 native_coverage: false,
209 system_shared_libs: [],
210 stl: "none",
211 notice: "custom_notice",
212 }
213 cc_library {
214 name: "libprofile-extras_ndk",
215 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900216 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400217 native_coverage: false,
218 system_shared_libs: [],
219 stl: "none",
220 notice: "custom_notice",
221 sdk_version: "current",
222 }
223 cc_library {
224 name: "libprofile-clang-extras_ndk",
225 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900226 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400227 native_coverage: false,
228 system_shared_libs: [],
229 stl: "none",
230 notice: "custom_notice",
231 sdk_version: "current",
232 }
233
Inseob Kimc0907f12019-02-08 21:00:45 +0900234 cc_library {
235 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100236 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700237 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900238 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800239 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900240 system_shared_libs: [],
241 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800242 stubs: {
243 versions: ["27", "28", "29"],
244 },
245 apex_available: [
246 "//apex_available:platform",
247 "myapex"
248 ],
Colin Cross203b4212021-04-26 17:19:41 -0700249 llndk: {
250 symbol_file: "libdl.map.txt",
251 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900252 }
253 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900254 name: "libft2",
255 no_libcrt: true,
256 nocrt: true,
257 system_shared_libs: [],
258 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700259 llndk: {
260 symbol_file: "libft2.map.txt",
261 private: true,
262 }
Jooyung Han097087b2019-10-22 19:32:18 +0900263 }
264 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900265 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700266 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900267 nocrt: true,
268 system_shared_libs: [],
269 stl: "none",
270 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500271 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900272 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900273 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900274 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900275 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900276 apex_available: [
277 "//apex_available:platform",
278 "//apex_available:anyapex",
279 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900280 }
281 cc_library {
282 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700283 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900284 nocrt: true,
285 system_shared_libs: [],
286 stl: "none",
287 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900288 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900289 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900290 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900291 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900292 vndk: {
293 enabled: true,
294 support_system_process: true,
295 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800296 apex_available: [
297 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500298 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800299 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 }
301 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700302 name: "libc++demangle",
303 no_libcrt: true,
304 nocrt: true,
305 system_shared_libs: [],
306 stl: "none",
307 host_supported: false,
308 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500309 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900310 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700311 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900312 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900313 apex_available: [
314 "//apex_available:platform",
315 "//apex_available:anyapex",
316 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700317 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900318
Jiyong Park541142c2020-03-07 16:35:46 +0900319 cc_defaults {
320 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100321 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900322 recovery_available: true,
323 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500324 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900325 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900326 native_bridge_supported: true,
327 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700328 min_sdk_version: "16",
329 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700330 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900331 apex_available: [
332 "//apex_available:platform",
333 "//apex_available:anyapex",
334 ],
335 }
336
Inseob Kimc0907f12019-02-08 21:00:45 +0900337 cc_object {
338 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900339 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900340 srcs: ["crtbegin_so.c"],
341 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900342 }
343
344 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700345 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900346 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900347 srcs: ["crtbegin.c"],
348 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700349 }
350
351 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900352 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900353 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900354 srcs: ["crtbegin.c"],
355 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900356 }
357
358 cc_object {
359 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900360 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900361 srcs: ["crtend_so.c"],
362 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900363 }
364
365 cc_object {
366 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900367 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900368 srcs: ["crtend.c"],
369 objs: ["crtbrand"],
370 }
371
372 cc_object {
373 name: "crtbrand",
374 defaults: ["crt_defaults"],
375 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900376 }
377
378 cc_library {
379 name: "libprotobuf-cpp-lite",
380 }
Colin Crossf28329d2020-02-15 11:00:10 -0800381
382 cc_library {
383 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700384 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800385 stl: "none",
386 system_shared_libs: [],
387 }
388
Dan Albertde5aade2020-06-30 12:32:51 -0700389 ndk_library {
390 name: "libc",
391 first_version: "minimum",
392 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800393 }
394
Dan Albertde5aade2020-06-30 12:32:51 -0700395 ndk_library {
396 name: "libm",
397 first_version: "minimum",
398 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800399 }
400
Dan Albertde5aade2020-06-30 12:32:51 -0700401 ndk_library {
402 name: "libdl",
403 first_version: "minimum",
404 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800405 }
406
Colin Crossf28329d2020-02-15 11:00:10 -0800407 ndk_prebuilt_shared_stl {
408 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700409 export_include_dirs: ["ndk_libc++_shared"],
410 }
411
412 ndk_prebuilt_static_stl {
413 name: "ndk_libandroid_support",
414 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800415 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900416
417 cc_library_static {
418 name: "libgoogle-benchmark",
419 sdk_version: "current",
420 stl: "none",
421 system_shared_libs: [],
422 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700423
424 cc_library_static {
425 name: "note_memtag_heap_async",
426 }
427
428 cc_library_static {
429 name: "note_memtag_heap_sync",
430 }
Colin Cross528d67e2021-07-23 22:23:07 +0000431
Colin Cross528d67e2021-07-23 22:23:07 +0000432 cc_library {
433 name: "libc_musl",
434 host_supported: true,
435 no_libcrt: true,
436 nocrt: true,
437 system_shared_libs: [],
438 stl: "none",
439 }
Colin Crossf28329d2020-02-15 11:00:10 -0800440 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000441}
Colin Crossf28329d2020-02-15 11:00:10 -0800442
Paul Duffin02a3d652021-02-24 18:51:54 +0000443func withWindowsModules() string {
444 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500445 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000446 name: "libwinpthread",
447 host_supported: true,
448 enabled: false,
449 target: {
450 windows: {
451 enabled: true,
452 },
453 },
Liz Kammer718eb272022-01-07 10:53:37 -0500454 stl: "none",
455 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000456 }
457 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000458}
459
Paul Duffin02a3d652021-02-24 18:51:54 +0000460func withLinuxBionic() string {
461 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100462 cc_binary {
463 name: "linker",
464 defaults: ["linux_bionic_supported"],
465 recovery_available: true,
466 stl: "none",
467 nocrt: true,
468 static_executable: true,
469 native_coverage: false,
470 system_shared_libs: [],
471 }
472
473 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700474 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100475 host_supported: true,
476 device_supported: false,
477 target: {
478 host: {
479 enabled: false,
480 },
481 linux_bionic: {
482 enabled: true,
483 },
484 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700485 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100486 }
487
488 cc_defaults {
489 name: "linux_bionic_supported",
490 host_supported: true,
491 target: {
492 host: {
493 enabled: false,
494 },
495 linux_bionic: {
496 enabled: true,
497 },
498 },
499 }
500 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000501}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100502
Paul Duffin02a3d652021-02-24 18:51:54 +0000503func withoutLinuxBionic() string {
504 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100505 cc_defaults {
506 name: "linux_bionic_supported",
507 }
508 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900509}
Colin Cross9a942872019-05-14 15:44:26 -0700510
Colin Crossf28329d2020-02-15 11:00:10 -0800511func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800512}
513
Paul Duffin02a3d652021-02-24 18:51:54 +0000514// The directory in which cc linux bionic default modules will be defined.
515//
516// Placing them here ensures that their location does not conflict with default test modules
517// defined by other packages.
518const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
519
520// The directory in which the default cc common test modules will be defined.
521//
522// Placing them here ensures that their location does not conflict with default test modules
523// defined by other packages.
524const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
525
526// Test fixture preparer that will register most cc build components.
527//
528// Singletons and mutators should only be added here if they are needed for a majority of cc
529// module types, otherwise they should be added under a separate preparer to allow them to be
530// selected only when needed to reduce test execution time.
531//
532// Module types do not have much of an overhead unless they are used so this should include as many
533// module types as possible. The exceptions are those module types that require mutators and/or
534// singletons in order to function in which case they should be kept together in a separate
535// preparer.
536var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
537 android.PrepareForTestWithAndroidBuildComponents,
538 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
539 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000540 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
541 ctx.RegisterModuleType("cc_afl_fuzz", AFLFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000542 ctx.RegisterModuleType("cc_test", TestFactory)
543 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000544 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
545
546 RegisterVndkLibraryTxtTypes(ctx)
547 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000548
549 // Additional files needed in tests that disallow non-existent source files.
550 // This includes files that are needed by all, or at least most, instances of a cc module type.
551 android.MockFS{
552 // Needed for ndk_prebuilt_(shared|static)_stl.
553 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
554 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000555)
556
557// Preparer that will define default cc modules, e.g. standard prebuilt modules.
558var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
559 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000560
561 // Additional files needed in tests that disallow non-existent source.
562 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700563 "defaults/cc/common/libc.map.txt": nil,
564 "defaults/cc/common/libdl.map.txt": nil,
565 "defaults/cc/common/libm.map.txt": nil,
566 "defaults/cc/common/ndk_libandroid_support": nil,
567 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900568 "defaults/cc/common/crtbegin_so.c": nil,
569 "defaults/cc/common/crtbegin.c": nil,
570 "defaults/cc/common/crtend_so.c": nil,
571 "defaults/cc/common/crtend.c": nil,
572 "defaults/cc/common/crtbrand.c": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000573
574 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
575 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
576 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
577 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000578 }.AddToFixture(),
579
Paul Duffin02a3d652021-02-24 18:51:54 +0000580 // Place the default cc test modules that are common to all platforms in a location that will not
581 // conflict with default test modules defined by other packages.
582 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
583 // Disable linux bionic by default.
584 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
585)
586
587// Prepare a fixture to use all cc module types, mutators and singletons fully.
588//
589// This should only be used by tests that want to run with as much of the build enabled as possible.
590var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
591 android.PrepareForIntegrationTestWithAndroid,
592 genrule.PrepareForIntegrationTestWithGenrule,
593 PrepareForTestWithCcDefaultModules,
594)
595
596// The preparer to include if running a cc related test for windows.
597var PrepareForTestOnWindows = android.GroupFixturePreparers(
598 // Place the default cc test modules for windows platforms in a location that will not conflict
599 // with default test modules defined by other packages.
600 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
601)
602
603// The preparer to include if running a cc related test for linux bionic.
604var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000605 // Enable linux bionic
606 //
607 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
608 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
609 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000610)
611
612// This adds some additional modules and singletons which might negatively impact the performance
613// of tests so they are not included in the PrepareForIntegrationTestWithCc.
614var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
615 PrepareForIntegrationTestWithCc,
616 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900617 snapshot.VendorSnapshotImageSingleton.Init(ctx)
618 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
619 RegisterVendorSnapshotModules(ctx)
620 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000621 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
622 }),
623)
624
625// TestConfig is the legacy way of creating a test Config for testing cc modules.
626//
627// See testCc for an explanation as to how to stop using this deprecated method.
628//
629// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800630func TestConfig(buildDir string, os android.OsType, env map[string]string,
631 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700632
Colin Cross98be1bb2019-12-13 20:41:13 -0800633 // add some modules that are required by the compiler and/or linker
634 bp = bp + GatherRequiredDepsForTest(os)
635
Colin Cross2fce23a2020-06-07 17:02:48 -0700636 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800637
Colin Crossf28329d2020-02-15 11:00:10 -0800638 GatherRequiredFilesForTest(mockFS)
639
Colin Cross98be1bb2019-12-13 20:41:13 -0800640 for k, v := range fs {
641 mockFS[k] = v
642 }
643
Colin Crosscb0ac952021-07-20 13:17:15 -0700644 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800645}
646
Paul Duffin02a3d652021-02-24 18:51:54 +0000647// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
648//
649// See testCc for an explanation as to how to stop using this deprecated method.
650//
651// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700652func CreateTestContext(config android.Config) *android.TestContext {
653 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000654 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000655 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
656 ctx.RegisterModuleType("cc_afl_fuzz", AFLFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800657 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400658 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800659 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
660 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000661
Kiyoung Kim48f37782021-07-07 12:42:39 +0900662 snapshot.VendorSnapshotImageSingleton.Init(ctx)
663 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
664 RegisterVendorSnapshotModules(ctx)
665 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000666 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800667 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000668
Colin Crosse1bb5d02019-09-24 14:55:04 -0700669 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100670 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100671 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700672
Colin Cross9a942872019-05-14 15:44:26 -0700673 return ctx
674}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400675
676func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
677 t.Helper()
678 mod := ctx.ModuleForTests(moduleName, variant)
679 outputFiles := mod.OutputFiles(t, "")
680 if len(outputFiles) != 1 {
681 t.Errorf("%q must have single output\n", moduleName)
682 return
683 }
684 snapshotPath := filepath.Join(subDir, snapshotFilename)
685
686 if include {
687 out := singleton.Output(snapshotPath)
688 if fake {
689 if out.Rule == nil {
690 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
691 }
692 } else {
693 if out.Input.String() != outputFiles[0].String() {
694 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
695 }
696 }
697 } else {
698 out := singleton.MaybeOutput(snapshotPath)
699 if out.Rule != nil {
700 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
701 }
702 }
703}
704
705func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
706 t.Helper()
707 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
708}
709
710func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
711 t.Helper()
712 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
713}
714
715func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
716 t.Helper()
717 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
718}
719
720func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
721 t.Helper()
722 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
723 if m.ExcludeFromVendorSnapshot() != expected {
724 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
725 }
726}
727
728func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
729 for _, moduleName := range moduleNames {
730 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
731 output := module.outputFile.Path().RelativeToTop()
732 paths = append(paths, output)
733 }
734 return paths
735}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500736
737func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
738 t.Helper()
739 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
740 if m.ExcludeFromRecoverySnapshot() != expected {
741 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
742 }
743}