blob: bee170f1d08487270c98e2a25e61b973778bc954 [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"
Inseob Kimc0907f12019-02-08 21:00:45 +090023)
24
Paul Duffin77980a82019-12-19 16:01:36 +000025func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000026 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000027 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000028 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000029 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000030 RegisterLibraryHeadersBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000031
32 ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
Jiyong Park46a512f2020-12-04 18:02:13 +090033 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000034 ctx.RegisterModuleType("cc_object", ObjectFactory)
Martin Stjernholm7feceb22020-07-11 04:33:29 +010035 ctx.RegisterModuleType("cc_genrule", genRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080036 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
37 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070038 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000039}
40
Paul Duffina04c1072020-03-02 10:16:35 +000041func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000042 ret := commonDefaultModules()
43
44 supportLinuxBionic := false
45 for _, os := range oses {
46 if os == android.Fuchsia {
47 ret += withFuchsiaModules()
48 }
49 if os == android.Windows {
50 ret += withWindowsModules()
51 }
52 if os == android.LinuxBionic {
53 supportLinuxBionic = true
54 ret += withLinuxBionic()
55 }
56 }
57
58 if !supportLinuxBionic {
59 ret += withoutLinuxBionic()
60 }
61
62 return ret
63}
64
65func commonDefaultModules() string {
66 return `
Inseob Kimc0907f12019-02-08 21:00:45 +090067 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +090068 name: "libcompiler_rt-extras",
69 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050070 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090071 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090072 recovery_available: true,
73 src: "",
74 }
75
76 toolchain_library {
77 name: "libclang_rt.builtins-arm-android",
78 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050079 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090080 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090081 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080082 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090083 src: "",
84 }
85
86 toolchain_library {
87 name: "libclang_rt.builtins-aarch64-android",
88 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050089 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090090 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090091 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080092 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090093 src: "",
94 }
95
Jooyung Han75568392020-03-20 04:29:24 +090096 cc_prebuilt_library_shared {
97 name: "libclang_rt.hwasan-aarch64-android",
98 nocrt: true,
99 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900100 product_available: true,
Jooyung Han75568392020-03-20 04:29:24 +0900101 recovery_available: true,
102 system_shared_libs: [],
103 stl: "none",
104 srcs: [""],
105 check_elf_files: false,
106 sanitize: {
107 never: true,
108 },
109 }
110
Inseob Kimc0907f12019-02-08 21:00:45 +0900111 toolchain_library {
112 name: "libclang_rt.builtins-i686-android",
113 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500114 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900115 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900116 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800117 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900118 src: "",
119 }
120
121 toolchain_library {
122 name: "libclang_rt.builtins-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100123 defaults: ["linux_bionic_supported"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900124 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500125 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900126 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900127 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800128 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900129 src: "",
130 }
131
132 toolchain_library {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800133 name: "libunwind",
134 defaults: ["linux_bionic_supported"],
135 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500136 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800137 product_available: true,
138 recovery_available: true,
139 native_bridge_supported: true,
140 src: "",
141 }
142
143 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700144 name: "libclang_rt.fuzzer-arm-android",
145 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900146 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700147 recovery_available: true,
148 src: "",
149 }
150
151 toolchain_library {
152 name: "libclang_rt.fuzzer-aarch64-android",
153 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900154 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700155 recovery_available: true,
156 src: "",
157 }
158
159 toolchain_library {
160 name: "libclang_rt.fuzzer-i686-android",
161 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900162 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700163 recovery_available: true,
164 src: "",
165 }
166
167 toolchain_library {
168 name: "libclang_rt.fuzzer-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100169 defaults: ["linux_bionic_supported"],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700170 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900171 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700172 recovery_available: true,
173 src: "",
174 }
175
176 toolchain_library {
177 name: "libclang_rt.fuzzer-x86_64",
178 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900179 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700180 recovery_available: true,
181 src: "",
182 }
183
Paul Duffind6867912019-12-19 14:38:36 +0000184 // Needed for sanitizer
185 cc_prebuilt_library_shared {
186 name: "libclang_rt.ubsan_standalone-aarch64-android",
187 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900188 product_available: true,
Paul Duffind6867912019-12-19 14:38:36 +0000189 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800190 system_shared_libs: [],
Paul Duffind6867912019-12-19 14:38:36 +0000191 srcs: [""],
192 }
193
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900195 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100196 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700197 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900198 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800199 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900200 system_shared_libs: [],
201 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800202 stubs: {
203 versions: ["27", "28", "29"],
204 },
Colin Cross203b4212021-04-26 17:19:41 -0700205 llndk: {
206 symbol_file: "libc.map.txt",
207 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900208 }
209 cc_library {
210 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100211 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700212 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900213 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800214 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900215 system_shared_libs: [],
216 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800217 stubs: {
218 versions: ["27", "28", "29"],
219 },
220 apex_available: [
221 "//apex_available:platform",
222 "myapex"
223 ],
Colin Cross203b4212021-04-26 17:19:41 -0700224 llndk: {
225 symbol_file: "libm.map.txt",
226 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900227 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400228
229 // Coverage libraries
230 cc_library {
231 name: "libprofile-extras",
232 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500233 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900234 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400235 recovery_available: true,
236 native_coverage: false,
237 system_shared_libs: [],
238 stl: "none",
239 notice: "custom_notice",
240 }
241 cc_library {
242 name: "libprofile-clang-extras",
243 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500244 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900245 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400246 recovery_available: true,
247 native_coverage: false,
248 system_shared_libs: [],
249 stl: "none",
250 notice: "custom_notice",
251 }
252 cc_library {
253 name: "libprofile-extras_ndk",
254 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900255 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400256 native_coverage: false,
257 system_shared_libs: [],
258 stl: "none",
259 notice: "custom_notice",
260 sdk_version: "current",
261 }
262 cc_library {
263 name: "libprofile-clang-extras_ndk",
264 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900265 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400266 native_coverage: false,
267 system_shared_libs: [],
268 stl: "none",
269 notice: "custom_notice",
270 sdk_version: "current",
271 }
272
Inseob Kimc0907f12019-02-08 21:00:45 +0900273 cc_library {
274 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100275 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700276 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900277 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800278 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900279 system_shared_libs: [],
280 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800281 stubs: {
282 versions: ["27", "28", "29"],
283 },
284 apex_available: [
285 "//apex_available:platform",
286 "myapex"
287 ],
Colin Cross203b4212021-04-26 17:19:41 -0700288 llndk: {
289 symbol_file: "libdl.map.txt",
290 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900291 }
292 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900293 name: "libft2",
294 no_libcrt: true,
295 nocrt: true,
296 system_shared_libs: [],
297 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700298 llndk: {
299 symbol_file: "libft2.map.txt",
300 private: true,
301 }
Jooyung Han097087b2019-10-22 19:32:18 +0900302 }
303 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900304 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700305 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900306 nocrt: true,
307 system_shared_libs: [],
308 stl: "none",
309 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500310 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900311 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900312 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900313 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900314 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900315 apex_available: [
316 "//apex_available:platform",
317 "//apex_available:anyapex",
318 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900319 }
320 cc_library {
321 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700322 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900323 nocrt: true,
324 system_shared_libs: [],
325 stl: "none",
326 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900327 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900328 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900329 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900330 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900331 vndk: {
332 enabled: true,
333 support_system_process: true,
334 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800335 apex_available: [
336 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500337 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800338 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900339 }
340 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700341 name: "libc++demangle",
342 no_libcrt: true,
343 nocrt: true,
344 system_shared_libs: [],
345 stl: "none",
346 host_supported: false,
347 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500348 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900349 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700350 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900351 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900352 apex_available: [
353 "//apex_available:platform",
354 "//apex_available:anyapex",
355 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700356 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900357
Jiyong Park541142c2020-03-07 16:35:46 +0900358 cc_defaults {
359 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100360 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900361 recovery_available: true,
362 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500363 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900364 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900365 native_bridge_supported: true,
366 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700367 min_sdk_version: "16",
368 crt: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900369 apex_available: [
370 "//apex_available:platform",
371 "//apex_available:anyapex",
372 ],
373 }
374
Inseob Kimc0907f12019-02-08 21:00:45 +0900375 cc_object {
376 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900377 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900378 }
379
380 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700381 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900382 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700383 }
384
385 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900386 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900387 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900388 }
389
390 cc_object {
391 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900392 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900393 }
394
395 cc_object {
396 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900397 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900398 }
399
400 cc_library {
401 name: "libprotobuf-cpp-lite",
402 }
Colin Crossf28329d2020-02-15 11:00:10 -0800403
404 cc_library {
405 name: "ndk_libunwind",
406 sdk_version: "current",
407 stl: "none",
408 system_shared_libs: [],
409 }
410
Dan Albertde5aade2020-06-30 12:32:51 -0700411 ndk_library {
412 name: "libc",
413 first_version: "minimum",
414 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800415 }
416
Dan Albertde5aade2020-06-30 12:32:51 -0700417 ndk_library {
418 name: "libm",
419 first_version: "minimum",
420 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800421 }
422
Dan Albertde5aade2020-06-30 12:32:51 -0700423 ndk_library {
424 name: "libdl",
425 first_version: "minimum",
426 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800427 }
428
Colin Crossf28329d2020-02-15 11:00:10 -0800429 ndk_prebuilt_shared_stl {
430 name: "ndk_libc++_shared",
431 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900432
433 cc_library_static {
434 name: "libgoogle-benchmark",
435 sdk_version: "current",
436 stl: "none",
437 system_shared_libs: [],
438 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700439
440 cc_library_static {
441 name: "note_memtag_heap_async",
442 }
443
444 cc_library_static {
445 name: "note_memtag_heap_sync",
446 }
Colin Crossf28329d2020-02-15 11:00:10 -0800447 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000448}
Colin Crossf28329d2020-02-15 11:00:10 -0800449
Paul Duffin02a3d652021-02-24 18:51:54 +0000450func withWindowsModules() string {
451 return `
Paul Duffina04c1072020-03-02 10:16:35 +0000452 toolchain_library {
453 name: "libwinpthread",
454 host_supported: true,
455 enabled: false,
456 target: {
457 windows: {
458 enabled: true,
459 },
460 },
461 src: "",
462 }
463 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000464}
465
466func withFuchsiaModules() string {
467 return `
468 cc_library {
469 name: "libbioniccompat",
470 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000471 }
Paul Duffin02a3d652021-02-24 18:51:54 +0000472 cc_library {
473 name: "libcompiler_rt",
474 stl: "none",
475 }
476 `
477}
478
479func withLinuxBionic() string {
480 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100481 cc_binary {
482 name: "linker",
483 defaults: ["linux_bionic_supported"],
484 recovery_available: true,
485 stl: "none",
486 nocrt: true,
487 static_executable: true,
488 native_coverage: false,
489 system_shared_libs: [],
490 }
491
492 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700493 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100494 host_supported: true,
495 device_supported: false,
496 target: {
497 host: {
498 enabled: false,
499 },
500 linux_bionic: {
501 enabled: true,
502 },
503 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700504 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100505 }
506
507 cc_defaults {
508 name: "linux_bionic_supported",
509 host_supported: true,
510 target: {
511 host: {
512 enabled: false,
513 },
514 linux_bionic: {
515 enabled: true,
516 },
517 },
518 }
519 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000520}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100521
Paul Duffin02a3d652021-02-24 18:51:54 +0000522func withoutLinuxBionic() string {
523 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100524 cc_defaults {
525 name: "linux_bionic_supported",
526 }
527 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900528}
Colin Cross9a942872019-05-14 15:44:26 -0700529
Colin Crossf28329d2020-02-15 11:00:10 -0800530func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800531}
532
Paul Duffin02a3d652021-02-24 18:51:54 +0000533// The directory in which cc linux bionic default modules will be defined.
534//
535// Placing them here ensures that their location does not conflict with default test modules
536// defined by other packages.
537const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
538
539// The directory in which the default cc common test modules will be defined.
540//
541// Placing them here ensures that their location does not conflict with default test modules
542// defined by other packages.
543const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
544
545// Test fixture preparer that will register most cc build components.
546//
547// Singletons and mutators should only be added here if they are needed for a majority of cc
548// module types, otherwise they should be added under a separate preparer to allow them to be
549// selected only when needed to reduce test execution time.
550//
551// Module types do not have much of an overhead unless they are used so this should include as many
552// module types as possible. The exceptions are those module types that require mutators and/or
553// singletons in order to function in which case they should be kept together in a separate
554// preparer.
555var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
556 android.PrepareForTestWithAndroidBuildComponents,
557 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
558 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
559 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
560 ctx.RegisterModuleType("cc_test", TestFactory)
561 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000562 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
563
564 RegisterVndkLibraryTxtTypes(ctx)
565 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000566
567 // Additional files needed in tests that disallow non-existent source files.
568 // This includes files that are needed by all, or at least most, instances of a cc module type.
569 android.MockFS{
570 // Needed for ndk_prebuilt_(shared|static)_stl.
571 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
572 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000573)
574
575// Preparer that will define default cc modules, e.g. standard prebuilt modules.
576var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
577 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000578
579 // Additional files needed in tests that disallow non-existent source.
580 android.MockFS{
581 "defaults/cc/common/libc.map.txt": nil,
582 "defaults/cc/common/libdl.map.txt": nil,
583 "defaults/cc/common/libm.map.txt": nil,
584 }.AddToFixture(),
585
Paul Duffin02a3d652021-02-24 18:51:54 +0000586 // Place the default cc test modules that are common to all platforms in a location that will not
587 // conflict with default test modules defined by other packages.
588 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
589 // Disable linux bionic by default.
590 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
591)
592
593// Prepare a fixture to use all cc module types, mutators and singletons fully.
594//
595// This should only be used by tests that want to run with as much of the build enabled as possible.
596var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
597 android.PrepareForIntegrationTestWithAndroid,
598 genrule.PrepareForIntegrationTestWithGenrule,
599 PrepareForTestWithCcDefaultModules,
600)
601
602// The preparer to include if running a cc related test for windows.
603var PrepareForTestOnWindows = android.GroupFixturePreparers(
604 // Place the default cc test modules for windows platforms in a location that will not conflict
605 // with default test modules defined by other packages.
606 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
607)
608
609// The preparer to include if running a cc related test for linux bionic.
610var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000611 // Enable linux bionic
612 //
613 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
614 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
615 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000616)
617
Paul Duffinecdac8a2021-02-24 19:18:42 +0000618// The preparer to include if running a cc related test for fuchsia.
619var PrepareForTestOnFuchsia = android.GroupFixturePreparers(
620 // Place the default cc test modules for fuschia in a location that will not conflict with default
621 // test modules defined by other packages.
622 android.FixtureAddTextFile("defaults/cc/fuschia/Android.bp", withFuchsiaModules()),
623 android.PrepareForTestSetDeviceToFuchsia,
624)
625
Paul Duffin02a3d652021-02-24 18:51:54 +0000626// This adds some additional modules and singletons which might negatively impact the performance
627// of tests so they are not included in the PrepareForIntegrationTestWithCc.
628var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
629 PrepareForIntegrationTestWithCc,
630 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400631 VendorSnapshotImageSingleton.Init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000632 recoverySnapshotImageSingleton.init(ctx)
633 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
634 }),
635)
636
637// TestConfig is the legacy way of creating a test Config for testing cc modules.
638//
639// See testCc for an explanation as to how to stop using this deprecated method.
640//
641// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800642func TestConfig(buildDir string, os android.OsType, env map[string]string,
643 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700644
Colin Cross98be1bb2019-12-13 20:41:13 -0800645 // add some modules that are required by the compiler and/or linker
646 bp = bp + GatherRequiredDepsForTest(os)
647
Colin Cross2fce23a2020-06-07 17:02:48 -0700648 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800649
Colin Crossf28329d2020-02-15 11:00:10 -0800650 GatherRequiredFilesForTest(mockFS)
651
Colin Cross98be1bb2019-12-13 20:41:13 -0800652 for k, v := range fs {
653 mockFS[k] = v
654 }
655
656 var config android.Config
657 if os == android.Fuchsia {
Paul Duffinecdac8a2021-02-24 19:18:42 +0000658 panic("Fuchsia not supported use test fixture instead")
Colin Cross98be1bb2019-12-13 20:41:13 -0800659 } else {
660 config = android.TestArchConfig(buildDir, env, bp, mockFS)
661 }
662
663 return config
664}
665
Paul Duffin02a3d652021-02-24 18:51:54 +0000666// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
667//
668// See testCc for an explanation as to how to stop using this deprecated method.
669//
670// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700671func CreateTestContext(config android.Config) *android.TestContext {
672 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000673 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800674 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800675 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400676 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800677 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
678 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000679
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400680 VendorSnapshotImageSingleton.Init(ctx)
Colin Crosse0edaf92021-01-11 17:31:17 -0800681 recoverySnapshotImageSingleton.init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000682 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800683 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000684
Colin Crosse1bb5d02019-09-24 14:55:04 -0700685 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100686 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100687 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700688
Colin Cross9a942872019-05-14 15:44:26 -0700689 return ctx
690}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400691
692func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
693 t.Helper()
694 mod := ctx.ModuleForTests(moduleName, variant)
695 outputFiles := mod.OutputFiles(t, "")
696 if len(outputFiles) != 1 {
697 t.Errorf("%q must have single output\n", moduleName)
698 return
699 }
700 snapshotPath := filepath.Join(subDir, snapshotFilename)
701
702 if include {
703 out := singleton.Output(snapshotPath)
704 if fake {
705 if out.Rule == nil {
706 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
707 }
708 } else {
709 if out.Input.String() != outputFiles[0].String() {
710 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
711 }
712 }
713 } else {
714 out := singleton.MaybeOutput(snapshotPath)
715 if out.Rule != nil {
716 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
717 }
718 }
719}
720
721func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
722 t.Helper()
723 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
724}
725
726func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
727 t.Helper()
728 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
729}
730
731func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
732 t.Helper()
733 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
734}
735
736func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
737 t.Helper()
738 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
739 if m.ExcludeFromVendorSnapshot() != expected {
740 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
741 }
742}
743
744func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
745 for _, moduleName := range moduleNames {
746 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
747 output := module.outputFile.Path().RelativeToTop()
748 paths = append(paths, output)
749 }
750 return paths
751}