blob: ca6a0fade2283dd2a9638fafdc9d2b8780a5e05b [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 (
18 "android/soong/android"
Colin Crosse9fe2942020-11-10 18:12:15 -080019 "android/soong/genrule"
Inseob Kimc0907f12019-02-08 21:00:45 +090020)
21
Paul Duffin77980a82019-12-19 16:01:36 +000022func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000023 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000024 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000025 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000026 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000027 RegisterLibraryHeadersBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000028
29 ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
Jiyong Park46a512f2020-12-04 18:02:13 +090030 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000031 ctx.RegisterModuleType("cc_object", ObjectFactory)
Martin Stjernholm7feceb22020-07-11 04:33:29 +010032 ctx.RegisterModuleType("cc_genrule", genRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080033 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
34 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070035 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000036}
37
Paul Duffina04c1072020-03-02 10:16:35 +000038func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000039 ret := commonDefaultModules()
40
41 supportLinuxBionic := false
42 for _, os := range oses {
43 if os == android.Fuchsia {
44 ret += withFuchsiaModules()
45 }
46 if os == android.Windows {
47 ret += withWindowsModules()
48 }
49 if os == android.LinuxBionic {
50 supportLinuxBionic = true
51 ret += withLinuxBionic()
52 }
53 }
54
55 if !supportLinuxBionic {
56 ret += withoutLinuxBionic()
57 }
58
59 return ret
60}
61
62func commonDefaultModules() string {
63 return `
Inseob Kimc0907f12019-02-08 21:00:45 +090064 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +090065 name: "libcompiler_rt-extras",
66 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050067 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090068 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090069 recovery_available: true,
70 src: "",
71 }
72
73 toolchain_library {
74 name: "libclang_rt.builtins-arm-android",
75 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050076 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090077 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090078 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080079 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090080 src: "",
81 }
82
83 toolchain_library {
84 name: "libclang_rt.builtins-aarch64-android",
85 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050086 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090087 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090088 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080089 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090090 src: "",
91 }
92
Jooyung Han75568392020-03-20 04:29:24 +090093 cc_prebuilt_library_shared {
94 name: "libclang_rt.hwasan-aarch64-android",
95 nocrt: true,
96 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090097 product_available: true,
Jooyung Han75568392020-03-20 04:29:24 +090098 recovery_available: true,
99 system_shared_libs: [],
100 stl: "none",
101 srcs: [""],
102 check_elf_files: false,
103 sanitize: {
104 never: true,
105 },
106 }
107
Inseob Kimc0907f12019-02-08 21:00:45 +0900108 toolchain_library {
109 name: "libclang_rt.builtins-i686-android",
110 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500111 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900112 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900113 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800114 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900115 src: "",
116 }
117
118 toolchain_library {
119 name: "libclang_rt.builtins-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100120 defaults: ["linux_bionic_supported"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900121 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500122 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900123 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900124 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800125 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900126 src: "",
127 }
128
129 toolchain_library {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800130 name: "libunwind",
131 defaults: ["linux_bionic_supported"],
132 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500133 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800134 product_available: true,
135 recovery_available: true,
136 native_bridge_supported: true,
137 src: "",
138 }
139
140 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700141 name: "libclang_rt.fuzzer-arm-android",
142 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900143 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700144 recovery_available: true,
145 src: "",
146 }
147
148 toolchain_library {
149 name: "libclang_rt.fuzzer-aarch64-android",
150 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900151 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700152 recovery_available: true,
153 src: "",
154 }
155
156 toolchain_library {
157 name: "libclang_rt.fuzzer-i686-android",
158 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900159 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700160 recovery_available: true,
161 src: "",
162 }
163
164 toolchain_library {
165 name: "libclang_rt.fuzzer-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100166 defaults: ["linux_bionic_supported"],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700167 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900168 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700169 recovery_available: true,
170 src: "",
171 }
172
173 toolchain_library {
174 name: "libclang_rt.fuzzer-x86_64",
175 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900176 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700177 recovery_available: true,
178 src: "",
179 }
180
Paul Duffind6867912019-12-19 14:38:36 +0000181 // Needed for sanitizer
182 cc_prebuilt_library_shared {
183 name: "libclang_rt.ubsan_standalone-aarch64-android",
184 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900185 product_available: true,
Paul Duffind6867912019-12-19 14:38:36 +0000186 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800187 system_shared_libs: [],
Paul Duffind6867912019-12-19 14:38:36 +0000188 srcs: [""],
189 }
190
Inseob Kimc0907f12019-02-08 21:00:45 +0900191 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900192 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100193 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700194 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900195 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800196 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900197 system_shared_libs: [],
198 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800199 stubs: {
200 versions: ["27", "28", "29"],
201 },
Colin Cross203b4212021-04-26 17:19:41 -0700202 llndk: {
203 symbol_file: "libc.map.txt",
204 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900205 }
206 cc_library {
207 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100208 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700209 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900210 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800211 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900212 system_shared_libs: [],
213 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800214 stubs: {
215 versions: ["27", "28", "29"],
216 },
217 apex_available: [
218 "//apex_available:platform",
219 "myapex"
220 ],
Colin Cross203b4212021-04-26 17:19:41 -0700221 llndk: {
222 symbol_file: "libm.map.txt",
223 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900224 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400225
226 // Coverage libraries
227 cc_library {
228 name: "libprofile-extras",
229 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500230 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900231 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400232 recovery_available: true,
233 native_coverage: false,
234 system_shared_libs: [],
235 stl: "none",
236 notice: "custom_notice",
237 }
238 cc_library {
239 name: "libprofile-clang-extras",
240 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500241 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900242 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400243 recovery_available: true,
244 native_coverage: false,
245 system_shared_libs: [],
246 stl: "none",
247 notice: "custom_notice",
248 }
249 cc_library {
250 name: "libprofile-extras_ndk",
251 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900252 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400253 native_coverage: false,
254 system_shared_libs: [],
255 stl: "none",
256 notice: "custom_notice",
257 sdk_version: "current",
258 }
259 cc_library {
260 name: "libprofile-clang-extras_ndk",
261 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900262 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400263 native_coverage: false,
264 system_shared_libs: [],
265 stl: "none",
266 notice: "custom_notice",
267 sdk_version: "current",
268 }
269
Inseob Kimc0907f12019-02-08 21:00:45 +0900270 cc_library {
271 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100272 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700273 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900274 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800275 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900276 system_shared_libs: [],
277 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800278 stubs: {
279 versions: ["27", "28", "29"],
280 },
281 apex_available: [
282 "//apex_available:platform",
283 "myapex"
284 ],
Colin Cross203b4212021-04-26 17:19:41 -0700285 llndk: {
286 symbol_file: "libdl.map.txt",
287 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900288 }
289 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900290 name: "libft2",
291 no_libcrt: true,
292 nocrt: true,
293 system_shared_libs: [],
294 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700295 llndk: {
296 symbol_file: "libft2.map.txt",
297 private: true,
298 }
Jooyung Han097087b2019-10-22 19:32:18 +0900299 }
300 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900301 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700302 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900303 nocrt: true,
304 system_shared_libs: [],
305 stl: "none",
306 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500307 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900308 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900309 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900310 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900311 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900312 apex_available: [
313 "//apex_available:platform",
314 "//apex_available:anyapex",
315 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900316 }
317 cc_library {
318 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700319 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900320 nocrt: true,
321 system_shared_libs: [],
322 stl: "none",
323 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900324 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900325 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900326 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900327 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900328 vndk: {
329 enabled: true,
330 support_system_process: true,
331 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800332 apex_available: [
333 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500334 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800335 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900336 }
337 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700338 name: "libc++demangle",
339 no_libcrt: true,
340 nocrt: true,
341 system_shared_libs: [],
342 stl: "none",
343 host_supported: false,
344 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500345 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900346 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700347 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900348 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900349 apex_available: [
350 "//apex_available:platform",
351 "//apex_available:anyapex",
352 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700353 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900354
Jiyong Park541142c2020-03-07 16:35:46 +0900355 cc_defaults {
356 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100357 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900358 recovery_available: true,
359 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500360 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900361 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900362 native_bridge_supported: true,
363 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700364 min_sdk_version: "16",
365 crt: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900366 apex_available: [
367 "//apex_available:platform",
368 "//apex_available:anyapex",
369 ],
370 }
371
Inseob Kimc0907f12019-02-08 21:00:45 +0900372 cc_object {
373 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900374 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900375 }
376
377 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700378 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900379 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700380 }
381
382 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900383 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900384 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900385 }
386
387 cc_object {
388 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900389 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900390 }
391
392 cc_object {
393 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900394 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900395 }
396
397 cc_library {
398 name: "libprotobuf-cpp-lite",
399 }
Colin Crossf28329d2020-02-15 11:00:10 -0800400
401 cc_library {
402 name: "ndk_libunwind",
403 sdk_version: "current",
404 stl: "none",
405 system_shared_libs: [],
406 }
407
Dan Albertde5aade2020-06-30 12:32:51 -0700408 ndk_library {
409 name: "libc",
410 first_version: "minimum",
411 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800412 }
413
Dan Albertde5aade2020-06-30 12:32:51 -0700414 ndk_library {
415 name: "libm",
416 first_version: "minimum",
417 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800418 }
419
Dan Albertde5aade2020-06-30 12:32:51 -0700420 ndk_library {
421 name: "libdl",
422 first_version: "minimum",
423 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800424 }
425
Colin Crossf28329d2020-02-15 11:00:10 -0800426 ndk_prebuilt_shared_stl {
427 name: "ndk_libc++_shared",
428 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900429
430 cc_library_static {
431 name: "libgoogle-benchmark",
432 sdk_version: "current",
433 stl: "none",
434 system_shared_libs: [],
435 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700436
437 cc_library_static {
438 name: "note_memtag_heap_async",
439 }
440
441 cc_library_static {
442 name: "note_memtag_heap_sync",
443 }
Colin Crossf28329d2020-02-15 11:00:10 -0800444 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000445}
Colin Crossf28329d2020-02-15 11:00:10 -0800446
Paul Duffin02a3d652021-02-24 18:51:54 +0000447func withWindowsModules() string {
448 return `
Paul Duffina04c1072020-03-02 10:16:35 +0000449 toolchain_library {
450 name: "libwinpthread",
451 host_supported: true,
452 enabled: false,
453 target: {
454 windows: {
455 enabled: true,
456 },
457 },
458 src: "",
459 }
460 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000461}
462
463func withFuchsiaModules() string {
464 return `
465 cc_library {
466 name: "libbioniccompat",
467 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000468 }
Paul Duffin02a3d652021-02-24 18:51:54 +0000469 cc_library {
470 name: "libcompiler_rt",
471 stl: "none",
472 }
473 `
474}
475
476func withLinuxBionic() string {
477 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100478 cc_binary {
479 name: "linker",
480 defaults: ["linux_bionic_supported"],
481 recovery_available: true,
482 stl: "none",
483 nocrt: true,
484 static_executable: true,
485 native_coverage: false,
486 system_shared_libs: [],
487 }
488
489 cc_genrule {
490 name: "host_bionic_linker_flags",
491 host_supported: true,
492 device_supported: false,
493 target: {
494 host: {
495 enabled: false,
496 },
497 linux_bionic: {
498 enabled: true,
499 },
500 },
501 out: ["linker.flags"],
502 }
503
504 cc_defaults {
505 name: "linux_bionic_supported",
506 host_supported: true,
507 target: {
508 host: {
509 enabled: false,
510 },
511 linux_bionic: {
512 enabled: true,
513 },
514 },
515 }
516 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000517}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100518
Paul Duffin02a3d652021-02-24 18:51:54 +0000519func withoutLinuxBionic() string {
520 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100521 cc_defaults {
522 name: "linux_bionic_supported",
523 }
524 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900525}
Colin Cross9a942872019-05-14 15:44:26 -0700526
Colin Crossf28329d2020-02-15 11:00:10 -0800527func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800528}
529
Paul Duffin02a3d652021-02-24 18:51:54 +0000530// The directory in which cc linux bionic default modules will be defined.
531//
532// Placing them here ensures that their location does not conflict with default test modules
533// defined by other packages.
534const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
535
536// The directory in which the default cc common test modules will be defined.
537//
538// Placing them here ensures that their location does not conflict with default test modules
539// defined by other packages.
540const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
541
542// Test fixture preparer that will register most cc build components.
543//
544// Singletons and mutators should only be added here if they are needed for a majority of cc
545// module types, otherwise they should be added under a separate preparer to allow them to be
546// selected only when needed to reduce test execution time.
547//
548// Module types do not have much of an overhead unless they are used so this should include as many
549// module types as possible. The exceptions are those module types that require mutators and/or
550// singletons in order to function in which case they should be kept together in a separate
551// preparer.
552var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
553 android.PrepareForTestWithAndroidBuildComponents,
554 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
555 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
556 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
557 ctx.RegisterModuleType("cc_test", TestFactory)
558 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000559 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
560 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
561
562 RegisterVndkLibraryTxtTypes(ctx)
563 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000564
565 // Additional files needed in tests that disallow non-existent source files.
566 // This includes files that are needed by all, or at least most, instances of a cc module type.
567 android.MockFS{
568 // Needed for ndk_prebuilt_(shared|static)_stl.
569 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
570 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000571)
572
573// Preparer that will define default cc modules, e.g. standard prebuilt modules.
574var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
575 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000576
577 // Additional files needed in tests that disallow non-existent source.
578 android.MockFS{
579 "defaults/cc/common/libc.map.txt": nil,
580 "defaults/cc/common/libdl.map.txt": nil,
581 "defaults/cc/common/libm.map.txt": nil,
582 }.AddToFixture(),
583
Paul Duffin02a3d652021-02-24 18:51:54 +0000584 // Place the default cc test modules that are common to all platforms in a location that will not
585 // conflict with default test modules defined by other packages.
586 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
587 // Disable linux bionic by default.
588 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
589)
590
591// Prepare a fixture to use all cc module types, mutators and singletons fully.
592//
593// This should only be used by tests that want to run with as much of the build enabled as possible.
594var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
595 android.PrepareForIntegrationTestWithAndroid,
596 genrule.PrepareForIntegrationTestWithGenrule,
597 PrepareForTestWithCcDefaultModules,
598)
599
600// The preparer to include if running a cc related test for windows.
601var PrepareForTestOnWindows = android.GroupFixturePreparers(
602 // Place the default cc test modules for windows platforms in a location that will not conflict
603 // with default test modules defined by other packages.
604 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
605)
606
607// The preparer to include if running a cc related test for linux bionic.
608var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000609 // Enable linux bionic
610 //
611 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
612 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
613 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000614)
615
Paul Duffinecdac8a2021-02-24 19:18:42 +0000616// The preparer to include if running a cc related test for fuchsia.
617var PrepareForTestOnFuchsia = android.GroupFixturePreparers(
618 // Place the default cc test modules for fuschia in a location that will not conflict with default
619 // test modules defined by other packages.
620 android.FixtureAddTextFile("defaults/cc/fuschia/Android.bp", withFuchsiaModules()),
621 android.PrepareForTestSetDeviceToFuchsia,
622)
623
Paul Duffin02a3d652021-02-24 18:51:54 +0000624// This adds some additional modules and singletons which might negatively impact the performance
625// of tests so they are not included in the PrepareForIntegrationTestWithCc.
626var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
627 PrepareForIntegrationTestWithCc,
628 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
629 vendorSnapshotImageSingleton.init(ctx)
630 recoverySnapshotImageSingleton.init(ctx)
631 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
632 }),
633)
634
635// TestConfig is the legacy way of creating a test Config for testing cc modules.
636//
637// See testCc for an explanation as to how to stop using this deprecated method.
638//
639// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800640func TestConfig(buildDir string, os android.OsType, env map[string]string,
641 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700642
Colin Cross98be1bb2019-12-13 20:41:13 -0800643 // add some modules that are required by the compiler and/or linker
644 bp = bp + GatherRequiredDepsForTest(os)
645
Colin Cross2fce23a2020-06-07 17:02:48 -0700646 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800647
Colin Crossf28329d2020-02-15 11:00:10 -0800648 GatherRequiredFilesForTest(mockFS)
649
Colin Cross98be1bb2019-12-13 20:41:13 -0800650 for k, v := range fs {
651 mockFS[k] = v
652 }
653
654 var config android.Config
655 if os == android.Fuchsia {
Paul Duffinecdac8a2021-02-24 19:18:42 +0000656 panic("Fuchsia not supported use test fixture instead")
Colin Cross98be1bb2019-12-13 20:41:13 -0800657 } else {
658 config = android.TestArchConfig(buildDir, env, bp, mockFS)
659 }
660
661 return config
662}
663
Paul Duffin02a3d652021-02-24 18:51:54 +0000664// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
665//
666// See testCc for an explanation as to how to stop using this deprecated method.
667//
668// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700669func CreateTestContext(config android.Config) *android.TestContext {
670 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000671 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800672 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800673 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400674 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800675 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800676 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
677 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000678
Colin Crosse0edaf92021-01-11 17:31:17 -0800679 vendorSnapshotImageSingleton.init(ctx)
680 recoverySnapshotImageSingleton.init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000681 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800682 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000683
Colin Crosse1bb5d02019-09-24 14:55:04 -0700684 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100685 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100686 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700687
Colin Cross9a942872019-05-14 15:44:26 -0700688 return ctx
689}