blob: 36bc261e0b4e18a707c4b94099798d3bc2b9d980 [file] [log] [blame]
Inseob Kimc0907f12019-02-08 21:00:45 +09001// Copyright (C) 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
Inseob Kima1888ce2022-10-04 14:42:02 +090018 "encoding/json"
Ivan Lozanod67a6b02021-05-20 13:01:32 -040019 "path/filepath"
20 "testing"
21
Inseob Kimc0907f12019-02-08 21:00:45 +090022 "android/soong/android"
Colin Crosse9fe2942020-11-10 18:12:15 -080023 "android/soong/genrule"
Kiyoung Kim487689e2022-07-26 09:48:22 +090024 "android/soong/multitree"
Kiyoung Kim48f37782021-07-07 12:42:39 +090025 "android/soong/snapshot"
Inseob Kimc0907f12019-02-08 21:00:45 +090026)
27
Paul Duffin77980a82019-12-19 16:01:36 +000028func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000029 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000030 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000031 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000032 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000033 RegisterLibraryHeadersBuildComponents(ctx)
Inseob Kim5eb7ee92022-04-27 10:30:34 +090034 RegisterLibraryStubBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000035
Kiyoung Kim487689e2022-07-26 09:48:22 +090036 multitree.RegisterApiImportsModule(ctx)
37
Sam Delmerico9333ac12023-09-11 17:18:08 +000038 ctx.RegisterModuleType("prebuilt_build_tool", android.NewPrebuiltBuildTool)
Jiyong Park46a512f2020-12-04 18:02:13 +090039 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000040 ctx.RegisterModuleType("cc_object", ObjectFactory)
Wei Libcd39942021-09-16 23:57:28 +000041 ctx.RegisterModuleType("cc_genrule", GenRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080042 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070043 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070044 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Spandan Das319711b2023-09-19 19:04:41 +000045 ctx.RegisterModuleType("ndk_headers", NdkHeadersFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000046}
47
Paul Duffina04c1072020-03-02 10:16:35 +000048func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000049 ret := commonDefaultModules()
50
51 supportLinuxBionic := false
52 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000053 if os == android.Windows {
54 ret += withWindowsModules()
55 }
56 if os == android.LinuxBionic {
57 supportLinuxBionic = true
58 ret += withLinuxBionic()
59 }
60 }
61
62 if !supportLinuxBionic {
63 ret += withoutLinuxBionic()
64 }
65
66 return ret
67}
68
69func commonDefaultModules() string {
70 return `
Sam Delmericoa588d152023-06-16 10:28:04 -040071 prebuilt_build_tool {
72 name: "clang++",
73 src: "bin/clang++",
74 }
75 prebuilt_build_tool {
76 name: "clang++.real",
77 src: "bin/clang++.real",
78 }
79 prebuilt_build_tool {
80 name: "lld",
81 src: "bin/lld",
82 }
83 prebuilt_build_tool {
84 name: "ld.lld",
85 src: "bin/ld.lld",
86 }
87 prebuilt_build_tool {
88 name: "llvm-ar",
89 src: "bin/llvm-ar",
90 }
Liz Kammer718eb272022-01-07 10:53:37 -050091 cc_defaults {
92 name: "toolchain_libs_defaults",
Colin Cross5dc62c92023-02-15 12:20:19 -080093 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090094 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090095 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090096 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050097 no_libcrt: true,
98 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090099 nocrt: true,
Jooyung Han75568392020-03-20 04:29:24 +0900100 system_shared_libs: [],
101 stl: "none",
Jooyung Han75568392020-03-20 04:29:24 +0900102 check_elf_files: false,
103 sanitize: {
104 never: true,
105 },
Spandan Das4de7b492023-05-05 21:13:01 +0000106 apex_available: [
107 "//apex_available:anyapex",
108 "//apex_available:platform",
109 ],
Jooyung Han75568392020-03-20 04:29:24 +0900110 }
111
Liz Kammer718eb272022-01-07 10:53:37 -0500112 cc_prebuilt_library_static {
113 name: "libcompiler_rt-extras",
114 defaults: ["toolchain_libs_defaults"],
115 vendor_ramdisk_available: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000116 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500117 }
118
119 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800120 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -0800121 defaults: ["toolchain_libs_defaults"],
122 host_supported: true,
Colin Cross4c4c1be2022-02-10 11:41:18 -0800123 vendor_available: true,
124 vendor_ramdisk_available: true,
125 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000126 srcs: [""],
Colin Cross06c80eb2022-02-10 10:34:19 -0800127 }
128
Liz Kammer718eb272022-01-07 10:53:37 -0500129 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800130 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500131 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000132 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500133 }
134
135 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800136 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500137 defaults: [
138 "linux_bionic_supported",
139 "toolchain_libs_defaults",
140 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500141 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800142 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000143 srcs: [""],
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800144 }
145
Liz Kammer718eb272022-01-07 10:53:37 -0500146 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800147 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500148 defaults: [
149 "linux_bionic_supported",
150 "toolchain_libs_defaults",
151 ],
Colin Cross3e5e7782022-06-17 22:17:05 +0000152 srcs: [""],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700153 }
154
Paul Duffind6867912019-12-19 14:38:36 +0000155 // Needed for sanitizer
156 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800157 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500158 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000159 srcs: [""],
Paul Duffind6867912019-12-19 14:38:36 +0000160 }
161
Colin Cross06c80eb2022-02-10 10:34:19 -0800162 cc_prebuilt_library_static {
Colin Cross5dc62c92023-02-15 12:20:19 -0800163 name: "libclang_rt.ubsan_standalone.static",
164 defaults: ["toolchain_libs_defaults"],
165 srcs: [""],
166 }
167
168 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800169 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800170 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000171 host_supported: true,
172 target: {
173 android_arm64: {
174 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
175 },
176 android_arm: {
177 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
178 },
179 linux_glibc_x86_64: {
180 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
181 },
182 linux_glibc_x86: {
183 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
184 },
Colin Cross5dc62c92023-02-15 12:20:19 -0800185 linux_musl_x86_64: {
186 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
187 },
188 linux_musl_x86: {
189 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
190 },
Colin Cross3e5e7782022-06-17 22:17:05 +0000191 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800192 }
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",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400239 }
240 cc_library {
241 name: "libprofile-clang-extras",
242 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500243 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900244 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400245 recovery_available: true,
246 native_coverage: false,
247 system_shared_libs: [],
248 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400249 }
250 cc_library {
251 name: "libprofile-extras_ndk",
252 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900253 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400254 native_coverage: false,
255 system_shared_libs: [],
256 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400257 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",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400266 sdk_version: "current",
267 }
268
Inseob Kimc0907f12019-02-08 21:00:45 +0900269 cc_library {
270 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100271 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700272 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900273 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800274 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900275 system_shared_libs: [],
276 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800277 stubs: {
278 versions: ["27", "28", "29"],
279 },
280 apex_available: [
281 "//apex_available:platform",
282 "myapex"
283 ],
Colin Cross203b4212021-04-26 17:19:41 -0700284 llndk: {
285 symbol_file: "libdl.map.txt",
286 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900287 }
288 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900289 name: "libft2",
290 no_libcrt: true,
291 nocrt: true,
292 system_shared_libs: [],
293 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700294 llndk: {
295 symbol_file: "libft2.map.txt",
296 private: true,
297 }
Jooyung Han097087b2019-10-22 19:32:18 +0900298 }
299 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700301 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900302 nocrt: true,
303 system_shared_libs: [],
304 stl: "none",
305 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500306 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900307 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900308 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900309 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900310 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900311 apex_available: [
312 "//apex_available:platform",
313 "//apex_available:anyapex",
314 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900315 }
316 cc_library {
317 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700318 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900319 nocrt: true,
320 system_shared_libs: [],
321 stl: "none",
322 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900323 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900324 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900325 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900326 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900327 vndk: {
328 enabled: true,
329 support_system_process: true,
330 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800331 apex_available: [
332 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500333 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800334 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900335 }
336 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700337 name: "libc++demangle",
338 no_libcrt: true,
339 nocrt: true,
340 system_shared_libs: [],
341 stl: "none",
342 host_supported: false,
343 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500344 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900345 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700346 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900347 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900348 apex_available: [
349 "//apex_available:platform",
350 "//apex_available:anyapex",
351 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700352 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900353
Jiyong Park541142c2020-03-07 16:35:46 +0900354 cc_defaults {
355 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100356 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900357 recovery_available: true,
358 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500359 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900360 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900361 native_bridge_supported: true,
362 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700363 min_sdk_version: "16",
364 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700365 system_shared_libs: [],
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"],
Jiyong Park7549d462021-08-25 16:16:03 +0900375 srcs: ["crtbegin_so.c"],
376 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900377 }
378
379 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700380 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900381 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900382 srcs: ["crtbegin.c"],
383 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700384 }
385
386 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900387 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900388 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900389 srcs: ["crtbegin.c"],
390 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900391 }
392
393 cc_object {
394 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900395 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900396 srcs: ["crtend_so.c"],
397 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900398 }
399
400 cc_object {
401 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900402 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900403 srcs: ["crtend.c"],
404 objs: ["crtbrand"],
405 }
406
407 cc_object {
408 name: "crtbrand",
409 defaults: ["crt_defaults"],
410 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900411 }
412
413 cc_library {
414 name: "libprotobuf-cpp-lite",
415 }
Colin Crossf28329d2020-02-15 11:00:10 -0800416
417 cc_library {
418 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700419 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800420 stl: "none",
421 system_shared_libs: [],
422 }
423
Dan Albertde5aade2020-06-30 12:32:51 -0700424 ndk_library {
425 name: "libc",
426 first_version: "minimum",
427 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800428 }
429
Dan Albertde5aade2020-06-30 12:32:51 -0700430 ndk_library {
431 name: "libm",
432 first_version: "minimum",
433 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800434 }
435
Dan Albertde5aade2020-06-30 12:32:51 -0700436 ndk_library {
437 name: "libdl",
438 first_version: "minimum",
439 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800440 }
441
Colin Crossf28329d2020-02-15 11:00:10 -0800442 ndk_prebuilt_shared_stl {
443 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700444 export_include_dirs: ["ndk_libc++_shared"],
445 }
446
Jiyong Park46a512f2020-12-04 18:02:13 +0900447 cc_library_static {
448 name: "libgoogle-benchmark",
449 sdk_version: "current",
450 stl: "none",
451 system_shared_libs: [],
452 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700453
454 cc_library_static {
455 name: "note_memtag_heap_async",
456 }
457
458 cc_library_static {
459 name: "note_memtag_heap_sync",
460 }
Colin Cross528d67e2021-07-23 22:23:07 +0000461
Colin Cross528d67e2021-07-23 22:23:07 +0000462 cc_library {
463 name: "libc_musl",
464 host_supported: true,
465 no_libcrt: true,
466 nocrt: true,
467 system_shared_libs: [],
468 stl: "none",
469 }
Colin Crossf28329d2020-02-15 11:00:10 -0800470 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000471}
Colin Crossf28329d2020-02-15 11:00:10 -0800472
Paul Duffin02a3d652021-02-24 18:51:54 +0000473func withWindowsModules() string {
474 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500475 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000476 name: "libwinpthread",
477 host_supported: true,
478 enabled: false,
479 target: {
480 windows: {
481 enabled: true,
482 },
483 },
Liz Kammer718eb272022-01-07 10:53:37 -0500484 stl: "none",
485 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000486 }
487 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000488}
489
Paul Duffin02a3d652021-02-24 18:51:54 +0000490func withLinuxBionic() string {
491 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100492 cc_binary {
493 name: "linker",
494 defaults: ["linux_bionic_supported"],
495 recovery_available: true,
496 stl: "none",
497 nocrt: true,
498 static_executable: true,
499 native_coverage: false,
500 system_shared_libs: [],
501 }
502
503 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700504 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100505 host_supported: true,
506 device_supported: false,
507 target: {
508 host: {
509 enabled: false,
510 },
511 linux_bionic: {
512 enabled: true,
513 },
514 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700515 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100516 }
517
518 cc_defaults {
519 name: "linux_bionic_supported",
520 host_supported: true,
521 target: {
522 host: {
523 enabled: false,
524 },
525 linux_bionic: {
526 enabled: true,
527 },
528 },
529 }
530 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000531}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100532
Paul Duffin02a3d652021-02-24 18:51:54 +0000533func withoutLinuxBionic() string {
534 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100535 cc_defaults {
536 name: "linux_bionic_supported",
537 }
538 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900539}
Colin Cross9a942872019-05-14 15:44:26 -0700540
Colin Crossf28329d2020-02-15 11:00:10 -0800541func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800542}
543
Paul Duffin02a3d652021-02-24 18:51:54 +0000544// The directory in which cc linux bionic default modules will be defined.
545//
546// Placing them here ensures that their location does not conflict with default test modules
547// defined by other packages.
548const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
549
550// The directory in which the default cc common test modules will be defined.
551//
552// Placing them here ensures that their location does not conflict with default test modules
553// defined by other packages.
554const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
555
556// Test fixture preparer that will register most cc build components.
557//
558// Singletons and mutators should only be added here if they are needed for a majority of cc
559// module types, otherwise they should be added under a separate preparer to allow them to be
560// selected only when needed to reduce test execution time.
561//
562// Module types do not have much of an overhead unless they are used so this should include as many
563// module types as possible. The exceptions are those module types that require mutators and/or
564// singletons in order to function in which case they should be kept together in a separate
565// preparer.
566var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
567 android.PrepareForTestWithAndroidBuildComponents,
568 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
569 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000570 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000571 ctx.RegisterModuleType("cc_test", TestFactory)
572 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000573 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
574
575 RegisterVndkLibraryTxtTypes(ctx)
576 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000577
578 // Additional files needed in tests that disallow non-existent source files.
579 // This includes files that are needed by all, or at least most, instances of a cc module type.
580 android.MockFS{
581 // Needed for ndk_prebuilt_(shared|static)_stl.
Spandan Das6e332d22023-09-13 17:58:52 +0000582 "defaults/cc/common/current/sources/cxx-stl/llvm-libc++/libs": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000583 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000584)
585
586// Preparer that will define default cc modules, e.g. standard prebuilt modules.
587var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
588 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000589
590 // Additional files needed in tests that disallow non-existent source.
591 android.MockFS{
Sam Delmericoa588d152023-06-16 10:28:04 -0400592 "defaults/cc/common/bin/clang++": nil,
593 "defaults/cc/common/bin/clang++.real": nil,
594 "defaults/cc/common/bin/lld": nil,
595 "defaults/cc/common/bin/ld.lld": nil,
596 "defaults/cc/common/bin/llvm-ar": nil,
597
Dan Albert94dd5652023-07-20 18:16:19 +0000598 "defaults/cc/common/libc.map.txt": nil,
599 "defaults/cc/common/libdl.map.txt": nil,
600 "defaults/cc/common/libm.map.txt": nil,
601 "defaults/cc/common/ndk_libc++_shared": nil,
602 "defaults/cc/common/crtbegin_so.c": nil,
603 "defaults/cc/common/crtbegin.c": nil,
604 "defaults/cc/common/crtend_so.c": nil,
605 "defaults/cc/common/crtend.c": nil,
606 "defaults/cc/common/crtbrand.c": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000607
608 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
609 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
610 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
611 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000612 }.AddToFixture(),
613
Paul Duffin02a3d652021-02-24 18:51:54 +0000614 // Place the default cc test modules that are common to all platforms in a location that will not
615 // conflict with default test modules defined by other packages.
616 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
617 // Disable linux bionic by default.
618 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
619)
620
621// Prepare a fixture to use all cc module types, mutators and singletons fully.
622//
623// This should only be used by tests that want to run with as much of the build enabled as possible.
624var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
625 android.PrepareForIntegrationTestWithAndroid,
626 genrule.PrepareForIntegrationTestWithGenrule,
627 PrepareForTestWithCcDefaultModules,
628)
629
630// The preparer to include if running a cc related test for windows.
631var PrepareForTestOnWindows = android.GroupFixturePreparers(
632 // Place the default cc test modules for windows platforms in a location that will not conflict
633 // with default test modules defined by other packages.
634 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
635)
636
637// The preparer to include if running a cc related test for linux bionic.
638var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000639 // Enable linux bionic
640 //
641 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
642 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
643 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000644)
645
646// This adds some additional modules and singletons which might negatively impact the performance
647// of tests so they are not included in the PrepareForIntegrationTestWithCc.
648var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
649 PrepareForIntegrationTestWithCc,
650 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900651 snapshot.VendorSnapshotImageSingleton.Init(ctx)
652 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
653 RegisterVendorSnapshotModules(ctx)
654 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000655 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
656 }),
657)
658
Colin Cross5dc62c92023-02-15 12:20:19 -0800659// PrepareForTestWithHostMusl sets the host configuration to musl libc instead of glibc. It also disables the test
660// on mac, which doesn't support musl libc, and adds musl modules.
661var PrepareForTestWithHostMusl = android.GroupFixturePreparers(
662 android.FixtureModifyConfig(android.ModifyTestConfigForMusl),
663 android.PrepareForSkipTestOnMac,
664 android.FixtureAddTextFile("external/musl/Android.bp", `
665 cc_defaults {
666 name: "libc_musl_crt_defaults",
667 host_supported: true,
668 device_supported: false,
669 }
670
671 cc_object {
672 name: "libc_musl_crtbegin_so",
673 defaults: ["libc_musl_crt_defaults"],
674 }
675
676 cc_object {
677 name: "libc_musl_crtend_so",
678 defaults: ["libc_musl_crt_defaults"],
679 }
680
681 cc_object {
682 name: "libc_musl_crtbegin_dynamic",
683 defaults: ["libc_musl_crt_defaults"],
684 }
685
686 cc_object {
687 name: "libc_musl_crtbegin_static",
688 defaults: ["libc_musl_crt_defaults"],
689 }
690
691 cc_object {
692 name: "libc_musl_crtend",
693 defaults: ["libc_musl_crt_defaults"],
694 }
695 `),
696)
697
Vinh Trancde10162023-03-09 22:07:19 -0500698// PrepareForTestWithFdoProfile registers module types to test with fdo_profile
699var PrepareForTestWithFdoProfile = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
700 ctx.RegisterModuleType("soong_namespace", android.NamespaceFactory)
Vinh Trance40b922023-06-05 12:57:55 -0400701 ctx.RegisterModuleType("fdo_profile", FdoProfileFactory)
Vinh Trancde10162023-03-09 22:07:19 -0500702})
703
Paul Duffin02a3d652021-02-24 18:51:54 +0000704// TestConfig is the legacy way of creating a test Config for testing cc modules.
705//
706// See testCc for an explanation as to how to stop using this deprecated method.
707//
708// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800709func TestConfig(buildDir string, os android.OsType, env map[string]string,
710 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700711
Colin Cross98be1bb2019-12-13 20:41:13 -0800712 // add some modules that are required by the compiler and/or linker
713 bp = bp + GatherRequiredDepsForTest(os)
714
Colin Cross2fce23a2020-06-07 17:02:48 -0700715 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800716
Colin Crossf28329d2020-02-15 11:00:10 -0800717 GatherRequiredFilesForTest(mockFS)
718
Colin Cross98be1bb2019-12-13 20:41:13 -0800719 for k, v := range fs {
720 mockFS[k] = v
721 }
722
Colin Crosscb0ac952021-07-20 13:17:15 -0700723 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800724}
725
Paul Duffin02a3d652021-02-24 18:51:54 +0000726// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
727//
728// See testCc for an explanation as to how to stop using this deprecated method.
729//
730// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700731func CreateTestContext(config android.Config) *android.TestContext {
732 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000733 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000734 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800735 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400736 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800737 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
738 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000739
Kiyoung Kim48f37782021-07-07 12:42:39 +0900740 snapshot.VendorSnapshotImageSingleton.Init(ctx)
741 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
742 RegisterVendorSnapshotModules(ctx)
743 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000744 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800745 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000746
Colin Crosse1bb5d02019-09-24 14:55:04 -0700747 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100748 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100749 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700750
Colin Cross9a942872019-05-14 15:44:26 -0700751 return ctx
752}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400753
754func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
755 t.Helper()
756 mod := ctx.ModuleForTests(moduleName, variant)
757 outputFiles := mod.OutputFiles(t, "")
758 if len(outputFiles) != 1 {
759 t.Errorf("%q must have single output\n", moduleName)
760 return
761 }
762 snapshotPath := filepath.Join(subDir, snapshotFilename)
763
764 if include {
765 out := singleton.Output(snapshotPath)
766 if fake {
767 if out.Rule == nil {
768 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
769 }
770 } else {
771 if out.Input.String() != outputFiles[0].String() {
772 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
773 }
774 }
775 } else {
776 out := singleton.MaybeOutput(snapshotPath)
777 if out.Rule != nil {
778 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
779 }
780 }
781}
782
783func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
784 t.Helper()
785 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
786}
787
788func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
789 t.Helper()
790 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
791}
792
793func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
794 t.Helper()
795 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
796}
797
798func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
799 t.Helper()
800 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
801 if m.ExcludeFromVendorSnapshot() != expected {
802 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
803 }
804}
805
806func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
807 for _, moduleName := range moduleNames {
808 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
809 output := module.outputFile.Path().RelativeToTop()
810 paths = append(paths, output)
811 }
812 return paths
813}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500814
815func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
816 t.Helper()
817 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
818 if m.ExcludeFromRecoverySnapshot() != expected {
819 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
820 }
821}
Inseob Kima1888ce2022-10-04 14:42:02 +0900822
823func checkOverrides(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, jsonPath string, expected []string) {
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7a11dc82022-10-06 15:20:37 +0000824 t.Helper()
Inseob Kima1888ce2022-10-04 14:42:02 +0900825 out := singleton.MaybeOutput(jsonPath)
826 content := android.ContentFromFileRuleForTests(t, out)
827
828 var flags snapshotJsonFlags
829 if err := json.Unmarshal([]byte(content), &flags); err != nil {
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7a11dc82022-10-06 15:20:37 +0000830 t.Errorf("Error while unmarshalling json %q: %s", jsonPath, err.Error())
Inseob Kima1888ce2022-10-04 14:42:02 +0900831 return
832 }
833
834 for _, moduleName := range expected {
835 if !android.InList(moduleName, flags.Overrides) {
836 t.Errorf("expected %q to be in %q: %q", moduleName, flags.Overrides, content)
837 return
838 }
839 }
840}