blob: 3d0c10a884c6c7314f7313048b73c0362d01df14 [file] [log] [blame]
Inseob Kimc0907f12019-02-08 21:00:45 +09001// Copyright (C) 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
Ivan Lozanod67a6b02021-05-20 13:01:32 -040018 "path/filepath"
19 "testing"
20
Inseob Kimc0907f12019-02-08 21:00:45 +090021 "android/soong/android"
Colin Crosse9fe2942020-11-10 18:12:15 -080022 "android/soong/genrule"
Kiyoung Kim48f37782021-07-07 12:42:39 +090023 "android/soong/snapshot"
Inseob Kimc0907f12019-02-08 21:00:45 +090024)
25
Paul Duffin77980a82019-12-19 16:01:36 +000026func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000027 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000028 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000029 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000030 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000031 RegisterLibraryHeadersBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000032
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)
Wei Libcd39942021-09-16 23:57:28 +000035 ctx.RegisterModuleType("cc_genrule", GenRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080036 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070037 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080038 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070039 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000040}
41
Paul Duffina04c1072020-03-02 10:16:35 +000042func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000043 ret := commonDefaultModules()
44
45 supportLinuxBionic := false
46 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000047 if os == android.Windows {
48 ret += withWindowsModules()
49 }
50 if os == android.LinuxBionic {
51 supportLinuxBionic = true
52 ret += withLinuxBionic()
53 }
54 }
55
56 if !supportLinuxBionic {
57 ret += withoutLinuxBionic()
58 }
59
60 return ret
61}
62
63func commonDefaultModules() string {
64 return `
Liz Kammer718eb272022-01-07 10:53:37 -050065 cc_defaults {
66 name: "toolchain_libs_defaults",
Inseob Kimc0907f12019-02-08 21:00:45 +090067 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090068 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090069 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050070 no_libcrt: true,
71 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090072 nocrt: true,
Jooyung Han75568392020-03-20 04:29:24 +090073 system_shared_libs: [],
74 stl: "none",
75 srcs: [""],
76 check_elf_files: false,
77 sanitize: {
78 never: true,
79 },
80 }
81
Liz Kammer718eb272022-01-07 10:53:37 -050082 cc_prebuilt_library_static {
83 name: "libcompiler_rt-extras",
84 defaults: ["toolchain_libs_defaults"],
85 vendor_ramdisk_available: true,
86 }
87
88 cc_prebuilt_library_static {
89 name: "libclang_rt.builtins-arm-android",
90 defaults: ["toolchain_libs_defaults"],
91 native_bridge_supported: true,
92 vendor_ramdisk_available: true,
93 }
94
95 cc_prebuilt_library_static {
96 name: "libclang_rt.builtins-aarch64-android",
97 defaults: ["toolchain_libs_defaults"],
98 native_bridge_supported: true,
99 vendor_ramdisk_available: true,
100 }
101
102 cc_prebuilt_library_shared {
103 name: "libclang_rt.hwasan-aarch64-android",
104 defaults: ["toolchain_libs_defaults"],
105 }
106
107 cc_prebuilt_library_static {
Inseob Kimc0907f12019-02-08 21:00:45 +0900108 name: "libclang_rt.builtins-i686-android",
Liz Kammer718eb272022-01-07 10:53:37 -0500109 defaults: ["toolchain_libs_defaults"],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500110 vendor_ramdisk_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800111 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900112 }
113
Liz Kammer718eb272022-01-07 10:53:37 -0500114 cc_prebuilt_library_static {
Inseob Kimc0907f12019-02-08 21:00:45 +0900115 name: "libclang_rt.builtins-x86_64-android",
Liz Kammer718eb272022-01-07 10:53:37 -0500116 defaults: [
117 "linux_bionic_supported",
118 "toolchain_libs_defaults",
119 ],
Colin Crossf9aabd72020-02-15 11:29:50 -0800120 native_bridge_supported: true,
Liz Kammer718eb272022-01-07 10:53:37 -0500121 vendor_ramdisk_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900122 }
123
Liz Kammer718eb272022-01-07 10:53:37 -0500124 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800125 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500126 defaults: [
127 "linux_bionic_supported",
128 "toolchain_libs_defaults",
129 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500130 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800131 native_bridge_supported: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800132 }
133
Liz Kammer718eb272022-01-07 10:53:37 -0500134 cc_prebuilt_library_static {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700135 name: "libclang_rt.fuzzer-arm-android",
Liz Kammer718eb272022-01-07 10:53:37 -0500136 defaults: ["toolchain_libs_defaults"],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700137 }
138
Liz Kammer718eb272022-01-07 10:53:37 -0500139 cc_prebuilt_library_static {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700140 name: "libclang_rt.fuzzer-aarch64-android",
Liz Kammer718eb272022-01-07 10:53:37 -0500141 defaults: ["toolchain_libs_defaults"],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700142 }
143
Liz Kammer718eb272022-01-07 10:53:37 -0500144 cc_prebuilt_library_static {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700145 name: "libclang_rt.fuzzer-i686-android",
Liz Kammer718eb272022-01-07 10:53:37 -0500146 defaults: ["toolchain_libs_defaults"],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700147 }
148
Liz Kammer718eb272022-01-07 10:53:37 -0500149 cc_prebuilt_library_static {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700150 name: "libclang_rt.fuzzer-x86_64-android",
Liz Kammer718eb272022-01-07 10:53:37 -0500151 defaults: [
152 "linux_bionic_supported",
153 "toolchain_libs_defaults",
154 ],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700155 }
156
Liz Kammer718eb272022-01-07 10:53:37 -0500157 cc_prebuilt_library_static {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700158 name: "libclang_rt.fuzzer-x86_64",
Liz Kammer718eb272022-01-07 10:53:37 -0500159 defaults: [
160 "linux_bionic_supported",
161 "toolchain_libs_defaults",
162 ],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700163 }
164
Paul Duffind6867912019-12-19 14:38:36 +0000165 // Needed for sanitizer
166 cc_prebuilt_library_shared {
167 name: "libclang_rt.ubsan_standalone-aarch64-android",
Liz Kammer718eb272022-01-07 10:53:37 -0500168 defaults: ["toolchain_libs_defaults"],
Paul Duffind6867912019-12-19 14:38:36 +0000169 }
170
Inseob Kimc0907f12019-02-08 21:00:45 +0900171 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900172 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100173 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700174 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900175 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800176 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900177 system_shared_libs: [],
178 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800179 stubs: {
180 versions: ["27", "28", "29"],
181 },
Colin Cross203b4212021-04-26 17:19:41 -0700182 llndk: {
183 symbol_file: "libc.map.txt",
184 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900185 }
186 cc_library {
187 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100188 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700189 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900190 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800191 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900192 system_shared_libs: [],
193 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800194 stubs: {
195 versions: ["27", "28", "29"],
196 },
197 apex_available: [
198 "//apex_available:platform",
199 "myapex"
200 ],
Colin Cross203b4212021-04-26 17:19:41 -0700201 llndk: {
202 symbol_file: "libm.map.txt",
203 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900204 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400205
206 // Coverage libraries
207 cc_library {
208 name: "libprofile-extras",
209 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500210 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900211 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400212 recovery_available: true,
213 native_coverage: false,
214 system_shared_libs: [],
215 stl: "none",
216 notice: "custom_notice",
217 }
218 cc_library {
219 name: "libprofile-clang-extras",
220 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500221 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900222 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400223 recovery_available: true,
224 native_coverage: false,
225 system_shared_libs: [],
226 stl: "none",
227 notice: "custom_notice",
228 }
229 cc_library {
230 name: "libprofile-extras_ndk",
231 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900232 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400233 native_coverage: false,
234 system_shared_libs: [],
235 stl: "none",
236 notice: "custom_notice",
237 sdk_version: "current",
238 }
239 cc_library {
240 name: "libprofile-clang-extras_ndk",
241 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900242 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400243 native_coverage: false,
244 system_shared_libs: [],
245 stl: "none",
246 notice: "custom_notice",
247 sdk_version: "current",
248 }
249
Inseob Kimc0907f12019-02-08 21:00:45 +0900250 cc_library {
251 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100252 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700253 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900254 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800255 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900256 system_shared_libs: [],
257 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800258 stubs: {
259 versions: ["27", "28", "29"],
260 },
261 apex_available: [
262 "//apex_available:platform",
263 "myapex"
264 ],
Colin Cross203b4212021-04-26 17:19:41 -0700265 llndk: {
266 symbol_file: "libdl.map.txt",
267 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900268 }
269 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900270 name: "libft2",
271 no_libcrt: true,
272 nocrt: true,
273 system_shared_libs: [],
274 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700275 llndk: {
276 symbol_file: "libft2.map.txt",
277 private: true,
278 }
Jooyung Han097087b2019-10-22 19:32:18 +0900279 }
280 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900281 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700282 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900283 nocrt: true,
284 system_shared_libs: [],
285 stl: "none",
286 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500287 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900288 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900289 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900290 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900291 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900292 apex_available: [
293 "//apex_available:platform",
294 "//apex_available:anyapex",
295 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900296 }
297 cc_library {
298 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700299 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 nocrt: true,
301 system_shared_libs: [],
302 stl: "none",
303 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900304 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900305 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900306 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900307 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900308 vndk: {
309 enabled: true,
310 support_system_process: true,
311 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800312 apex_available: [
313 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500314 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800315 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900316 }
317 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700318 name: "libc++demangle",
319 no_libcrt: true,
320 nocrt: true,
321 system_shared_libs: [],
322 stl: "none",
323 host_supported: false,
324 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500325 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900326 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700327 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900328 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900329 apex_available: [
330 "//apex_available:platform",
331 "//apex_available:anyapex",
332 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700333 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900334
Jiyong Park541142c2020-03-07 16:35:46 +0900335 cc_defaults {
336 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100337 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900338 recovery_available: true,
339 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500340 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900341 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900342 native_bridge_supported: true,
343 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700344 min_sdk_version: "16",
345 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700346 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900347 apex_available: [
348 "//apex_available:platform",
349 "//apex_available:anyapex",
350 ],
351 }
352
Inseob Kimc0907f12019-02-08 21:00:45 +0900353 cc_object {
354 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900355 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900356 srcs: ["crtbegin_so.c"],
357 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900358 }
359
360 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700361 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900362 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900363 srcs: ["crtbegin.c"],
364 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700365 }
366
367 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900368 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900369 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900370 srcs: ["crtbegin.c"],
371 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900372 }
373
374 cc_object {
375 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900376 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900377 srcs: ["crtend_so.c"],
378 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900379 }
380
381 cc_object {
382 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900383 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900384 srcs: ["crtend.c"],
385 objs: ["crtbrand"],
386 }
387
388 cc_object {
389 name: "crtbrand",
390 defaults: ["crt_defaults"],
391 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900392 }
393
394 cc_library {
395 name: "libprotobuf-cpp-lite",
396 }
Colin Crossf28329d2020-02-15 11:00:10 -0800397
398 cc_library {
399 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700400 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800401 stl: "none",
402 system_shared_libs: [],
403 }
404
Dan Albertde5aade2020-06-30 12:32:51 -0700405 ndk_library {
406 name: "libc",
407 first_version: "minimum",
408 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800409 }
410
Dan Albertde5aade2020-06-30 12:32:51 -0700411 ndk_library {
412 name: "libm",
413 first_version: "minimum",
414 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800415 }
416
Dan Albertde5aade2020-06-30 12:32:51 -0700417 ndk_library {
418 name: "libdl",
419 first_version: "minimum",
420 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800421 }
422
Colin Crossf28329d2020-02-15 11:00:10 -0800423 ndk_prebuilt_shared_stl {
424 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700425 export_include_dirs: ["ndk_libc++_shared"],
426 }
427
428 ndk_prebuilt_static_stl {
429 name: "ndk_libandroid_support",
430 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800431 }
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 Cross528d67e2021-07-23 22:23:07 +0000447
Colin Cross528d67e2021-07-23 22:23:07 +0000448 cc_library {
449 name: "libc_musl",
450 host_supported: true,
451 no_libcrt: true,
452 nocrt: true,
453 system_shared_libs: [],
454 stl: "none",
455 }
Colin Crossf28329d2020-02-15 11:00:10 -0800456 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000457}
Colin Crossf28329d2020-02-15 11:00:10 -0800458
Paul Duffin02a3d652021-02-24 18:51:54 +0000459func withWindowsModules() string {
460 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500461 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000462 name: "libwinpthread",
463 host_supported: true,
464 enabled: false,
465 target: {
466 windows: {
467 enabled: true,
468 },
469 },
Liz Kammer718eb272022-01-07 10:53:37 -0500470 stl: "none",
471 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000472 }
473 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000474}
475
Paul Duffin02a3d652021-02-24 18:51:54 +0000476func 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 {
Colin Cross9cfe6112021-06-11 18:02:22 -0700490 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100491 host_supported: true,
492 device_supported: false,
493 target: {
494 host: {
495 enabled: false,
496 },
497 linux_bionic: {
498 enabled: true,
499 },
500 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700501 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100502 }
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("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
560
561 RegisterVndkLibraryTxtTypes(ctx)
562 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000563
564 // Additional files needed in tests that disallow non-existent source files.
565 // This includes files that are needed by all, or at least most, instances of a cc module type.
566 android.MockFS{
567 // Needed for ndk_prebuilt_(shared|static)_stl.
568 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
569 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000570)
571
572// Preparer that will define default cc modules, e.g. standard prebuilt modules.
573var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
574 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000575
576 // Additional files needed in tests that disallow non-existent source.
577 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700578 "defaults/cc/common/libc.map.txt": nil,
579 "defaults/cc/common/libdl.map.txt": nil,
580 "defaults/cc/common/libm.map.txt": nil,
581 "defaults/cc/common/ndk_libandroid_support": nil,
582 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900583 "defaults/cc/common/crtbegin_so.c": nil,
584 "defaults/cc/common/crtbegin.c": nil,
585 "defaults/cc/common/crtend_so.c": nil,
586 "defaults/cc/common/crtend.c": nil,
587 "defaults/cc/common/crtbrand.c": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000588 }.AddToFixture(),
589
Paul Duffin02a3d652021-02-24 18:51:54 +0000590 // Place the default cc test modules that are common to all platforms in a location that will not
591 // conflict with default test modules defined by other packages.
592 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
593 // Disable linux bionic by default.
594 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
595)
596
597// Prepare a fixture to use all cc module types, mutators and singletons fully.
598//
599// This should only be used by tests that want to run with as much of the build enabled as possible.
600var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
601 android.PrepareForIntegrationTestWithAndroid,
602 genrule.PrepareForIntegrationTestWithGenrule,
603 PrepareForTestWithCcDefaultModules,
604)
605
606// The preparer to include if running a cc related test for windows.
607var PrepareForTestOnWindows = android.GroupFixturePreparers(
608 // Place the default cc test modules for windows platforms in a location that will not conflict
609 // with default test modules defined by other packages.
610 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
611)
612
613// The preparer to include if running a cc related test for linux bionic.
614var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000615 // Enable linux bionic
616 //
617 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
618 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
619 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000620)
621
622// This adds some additional modules and singletons which might negatively impact the performance
623// of tests so they are not included in the PrepareForIntegrationTestWithCc.
624var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
625 PrepareForIntegrationTestWithCc,
626 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900627 snapshot.VendorSnapshotImageSingleton.Init(ctx)
628 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
629 RegisterVendorSnapshotModules(ctx)
630 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000631 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
Colin Crosscb0ac952021-07-20 13:17:15 -0700654 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800655}
656
Paul Duffin02a3d652021-02-24 18:51:54 +0000657// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
658//
659// See testCc for an explanation as to how to stop using this deprecated method.
660//
661// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700662func CreateTestContext(config android.Config) *android.TestContext {
663 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000664 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800665 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800666 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400667 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800668 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
669 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000670
Kiyoung Kim48f37782021-07-07 12:42:39 +0900671 snapshot.VendorSnapshotImageSingleton.Init(ctx)
672 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
673 RegisterVendorSnapshotModules(ctx)
674 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000675 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800676 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000677
Colin Crosse1bb5d02019-09-24 14:55:04 -0700678 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100679 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100680 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700681
Colin Cross9a942872019-05-14 15:44:26 -0700682 return ctx
683}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400684
685func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
686 t.Helper()
687 mod := ctx.ModuleForTests(moduleName, variant)
688 outputFiles := mod.OutputFiles(t, "")
689 if len(outputFiles) != 1 {
690 t.Errorf("%q must have single output\n", moduleName)
691 return
692 }
693 snapshotPath := filepath.Join(subDir, snapshotFilename)
694
695 if include {
696 out := singleton.Output(snapshotPath)
697 if fake {
698 if out.Rule == nil {
699 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
700 }
701 } else {
702 if out.Input.String() != outputFiles[0].String() {
703 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
704 }
705 }
706 } else {
707 out := singleton.MaybeOutput(snapshotPath)
708 if out.Rule != nil {
709 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
710 }
711 }
712}
713
714func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
715 t.Helper()
716 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
717}
718
719func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
720 t.Helper()
721 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
722}
723
724func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
725 t.Helper()
726 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
727}
728
729func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
730 t.Helper()
731 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
732 if m.ExcludeFromVendorSnapshot() != expected {
733 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
734 }
735}
736
737func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
738 for _, moduleName := range moduleNames {
739 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
740 output := module.outputFile.Path().RelativeToTop()
741 paths = append(paths, output)
742 }
743 return paths
744}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500745
746func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
747 t.Helper()
748 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
749 if m.ExcludeFromRecoverySnapshot() != expected {
750 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
751 }
752}