blob: 6a655db9ed56e35a8914455879c745644275fa9f [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
Jiyong Park46a512f2020-12-04 18:02:13 +090038 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000039 ctx.RegisterModuleType("cc_object", ObjectFactory)
Wei Libcd39942021-09-16 23:57:28 +000040 ctx.RegisterModuleType("cc_genrule", GenRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080041 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070042 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080043 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070044 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Spandan Das73bcafc2022-08-18 23:26:00 +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 `
Liz Kammer718eb272022-01-07 10:53:37 -050071 cc_defaults {
72 name: "toolchain_libs_defaults",
Inseob Kimc0907f12019-02-08 21:00:45 +090073 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090074 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090075 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050076 no_libcrt: true,
77 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090078 nocrt: true,
Jooyung Han75568392020-03-20 04:29:24 +090079 system_shared_libs: [],
80 stl: "none",
Jooyung Han75568392020-03-20 04:29:24 +090081 check_elf_files: false,
82 sanitize: {
83 never: true,
84 },
85 }
86
Liz Kammer718eb272022-01-07 10:53:37 -050087 cc_prebuilt_library_static {
88 name: "libcompiler_rt-extras",
89 defaults: ["toolchain_libs_defaults"],
90 vendor_ramdisk_available: true,
Colin Cross3e5e7782022-06-17 22:17:05 +000091 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -050092 }
93
94 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -080095 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -080096 defaults: ["toolchain_libs_defaults"],
97 host_supported: true,
Colin Cross4c4c1be2022-02-10 11:41:18 -080098 vendor_available: true,
99 vendor_ramdisk_available: true,
100 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000101 srcs: [""],
Colin Cross06c80eb2022-02-10 10:34:19 -0800102 }
103
Liz Kammer718eb272022-01-07 10:53:37 -0500104 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800105 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500106 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000107 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500108 }
109
110 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800111 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500112 defaults: [
113 "linux_bionic_supported",
114 "toolchain_libs_defaults",
115 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500116 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800117 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000118 srcs: [""],
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800119 }
120
Liz Kammer718eb272022-01-07 10:53:37 -0500121 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800122 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500123 defaults: [
124 "linux_bionic_supported",
125 "toolchain_libs_defaults",
126 ],
Colin Cross3e5e7782022-06-17 22:17:05 +0000127 srcs: [""],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700128 }
129
Paul Duffind6867912019-12-19 14:38:36 +0000130 // Needed for sanitizer
131 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800132 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500133 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000134 srcs: [""],
Paul Duffind6867912019-12-19 14:38:36 +0000135 }
136
Colin Cross06c80eb2022-02-10 10:34:19 -0800137 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800138 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800139 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000140 host_supported: true,
141 target: {
142 android_arm64: {
143 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
144 },
145 android_arm: {
146 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
147 },
148 linux_glibc_x86_64: {
149 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
150 },
151 linux_glibc_x86: {
152 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
153 },
154 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800155 }
156
Inseob Kimc0907f12019-02-08 21:00:45 +0900157 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900158 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100159 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700160 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900161 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800162 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900163 system_shared_libs: [],
164 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800165 stubs: {
166 versions: ["27", "28", "29"],
167 },
Colin Cross203b4212021-04-26 17:19:41 -0700168 llndk: {
169 symbol_file: "libc.map.txt",
170 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900171 }
172 cc_library {
173 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100174 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700175 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900176 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800177 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900178 system_shared_libs: [],
179 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800180 stubs: {
181 versions: ["27", "28", "29"],
182 },
183 apex_available: [
184 "//apex_available:platform",
185 "myapex"
186 ],
Colin Cross203b4212021-04-26 17:19:41 -0700187 llndk: {
188 symbol_file: "libm.map.txt",
189 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900190 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400191
192 // Coverage libraries
193 cc_library {
194 name: "libprofile-extras",
195 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500196 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900197 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400198 recovery_available: true,
199 native_coverage: false,
200 system_shared_libs: [],
201 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400202 }
203 cc_library {
204 name: "libprofile-clang-extras",
205 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500206 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900207 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400208 recovery_available: true,
209 native_coverage: false,
210 system_shared_libs: [],
211 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400212 }
213 cc_library {
214 name: "libprofile-extras_ndk",
215 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900216 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400217 native_coverage: false,
218 system_shared_libs: [],
219 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400220 sdk_version: "current",
221 }
222 cc_library {
223 name: "libprofile-clang-extras_ndk",
224 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900225 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400226 native_coverage: false,
227 system_shared_libs: [],
228 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400229 sdk_version: "current",
230 }
231
Inseob Kimc0907f12019-02-08 21:00:45 +0900232 cc_library {
233 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100234 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700235 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900236 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800237 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900238 system_shared_libs: [],
239 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800240 stubs: {
241 versions: ["27", "28", "29"],
242 },
243 apex_available: [
244 "//apex_available:platform",
245 "myapex"
246 ],
Colin Cross203b4212021-04-26 17:19:41 -0700247 llndk: {
248 symbol_file: "libdl.map.txt",
249 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900250 }
251 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900252 name: "libft2",
253 no_libcrt: true,
254 nocrt: true,
255 system_shared_libs: [],
256 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700257 llndk: {
258 symbol_file: "libft2.map.txt",
259 private: true,
260 }
Jooyung Han097087b2019-10-22 19:32:18 +0900261 }
262 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900263 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700264 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900265 nocrt: true,
266 system_shared_libs: [],
267 stl: "none",
268 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500269 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900270 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900271 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900272 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900273 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900274 apex_available: [
275 "//apex_available:platform",
276 "//apex_available:anyapex",
277 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900278 }
279 cc_library {
280 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700281 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900282 nocrt: true,
283 system_shared_libs: [],
284 stl: "none",
285 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900286 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900287 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900288 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900289 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900290 vndk: {
291 enabled: true,
292 support_system_process: true,
293 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800294 apex_available: [
295 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500296 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800297 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 }
299 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700300 name: "libc++demangle",
301 no_libcrt: true,
302 nocrt: true,
303 system_shared_libs: [],
304 stl: "none",
305 host_supported: false,
306 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500307 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900308 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700309 recovery_available: 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 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700315 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900316
Jiyong Park541142c2020-03-07 16:35:46 +0900317 cc_defaults {
318 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100319 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900320 recovery_available: true,
321 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500322 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900323 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900324 native_bridge_supported: true,
325 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700326 min_sdk_version: "16",
327 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700328 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900329 apex_available: [
330 "//apex_available:platform",
331 "//apex_available:anyapex",
332 ],
333 }
334
Inseob Kimc0907f12019-02-08 21:00:45 +0900335 cc_object {
336 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900337 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900338 srcs: ["crtbegin_so.c"],
339 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900340 }
341
342 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700343 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900344 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900345 srcs: ["crtbegin.c"],
346 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700347 }
348
349 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900350 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900351 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900352 srcs: ["crtbegin.c"],
353 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900354 }
355
356 cc_object {
357 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900358 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900359 srcs: ["crtend_so.c"],
360 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900361 }
362
363 cc_object {
364 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900365 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900366 srcs: ["crtend.c"],
367 objs: ["crtbrand"],
368 }
369
370 cc_object {
371 name: "crtbrand",
372 defaults: ["crt_defaults"],
373 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900374 }
375
376 cc_library {
377 name: "libprotobuf-cpp-lite",
378 }
Colin Crossf28329d2020-02-15 11:00:10 -0800379
380 cc_library {
381 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700382 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800383 stl: "none",
384 system_shared_libs: [],
385 }
386
Dan Albertde5aade2020-06-30 12:32:51 -0700387 ndk_library {
388 name: "libc",
389 first_version: "minimum",
390 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800391 }
392
Dan Albertde5aade2020-06-30 12:32:51 -0700393 ndk_library {
394 name: "libm",
395 first_version: "minimum",
396 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800397 }
398
Dan Albertde5aade2020-06-30 12:32:51 -0700399 ndk_library {
400 name: "libdl",
401 first_version: "minimum",
402 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800403 }
404
Colin Crossf28329d2020-02-15 11:00:10 -0800405 ndk_prebuilt_shared_stl {
406 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700407 export_include_dirs: ["ndk_libc++_shared"],
408 }
409
410 ndk_prebuilt_static_stl {
411 name: "ndk_libandroid_support",
412 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800413 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900414
415 cc_library_static {
416 name: "libgoogle-benchmark",
417 sdk_version: "current",
418 stl: "none",
419 system_shared_libs: [],
420 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700421
422 cc_library_static {
423 name: "note_memtag_heap_async",
424 }
425
426 cc_library_static {
427 name: "note_memtag_heap_sync",
428 }
Colin Cross528d67e2021-07-23 22:23:07 +0000429
Colin Cross528d67e2021-07-23 22:23:07 +0000430 cc_library {
431 name: "libc_musl",
432 host_supported: true,
433 no_libcrt: true,
434 nocrt: true,
435 system_shared_libs: [],
436 stl: "none",
437 }
Colin Crossf28329d2020-02-15 11:00:10 -0800438 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000439}
Colin Crossf28329d2020-02-15 11:00:10 -0800440
Paul Duffin02a3d652021-02-24 18:51:54 +0000441func withWindowsModules() string {
442 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500443 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000444 name: "libwinpthread",
445 host_supported: true,
446 enabled: false,
447 target: {
448 windows: {
449 enabled: true,
450 },
451 },
Liz Kammer718eb272022-01-07 10:53:37 -0500452 stl: "none",
453 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000454 }
455 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000456}
457
Paul Duffin02a3d652021-02-24 18:51:54 +0000458func withLinuxBionic() string {
459 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100460 cc_binary {
461 name: "linker",
462 defaults: ["linux_bionic_supported"],
463 recovery_available: true,
464 stl: "none",
465 nocrt: true,
466 static_executable: true,
467 native_coverage: false,
468 system_shared_libs: [],
469 }
470
471 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700472 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100473 host_supported: true,
474 device_supported: false,
475 target: {
476 host: {
477 enabled: false,
478 },
479 linux_bionic: {
480 enabled: true,
481 },
482 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700483 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100484 }
485
486 cc_defaults {
487 name: "linux_bionic_supported",
488 host_supported: true,
489 target: {
490 host: {
491 enabled: false,
492 },
493 linux_bionic: {
494 enabled: true,
495 },
496 },
497 }
498 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000499}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100500
Paul Duffin02a3d652021-02-24 18:51:54 +0000501func withoutLinuxBionic() string {
502 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100503 cc_defaults {
504 name: "linux_bionic_supported",
505 }
506 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900507}
Colin Cross9a942872019-05-14 15:44:26 -0700508
Colin Crossf28329d2020-02-15 11:00:10 -0800509func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800510}
511
Paul Duffin02a3d652021-02-24 18:51:54 +0000512// The directory in which cc linux bionic default modules will be defined.
513//
514// Placing them here ensures that their location does not conflict with default test modules
515// defined by other packages.
516const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
517
518// The directory in which the default cc common test modules will be defined.
519//
520// Placing them here ensures that their location does not conflict with default test modules
521// defined by other packages.
522const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
523
524// Test fixture preparer that will register most cc build components.
525//
526// Singletons and mutators should only be added here if they are needed for a majority of cc
527// module types, otherwise they should be added under a separate preparer to allow them to be
528// selected only when needed to reduce test execution time.
529//
530// Module types do not have much of an overhead unless they are used so this should include as many
531// module types as possible. The exceptions are those module types that require mutators and/or
532// singletons in order to function in which case they should be kept together in a separate
533// preparer.
534var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
535 android.PrepareForTestWithAndroidBuildComponents,
536 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
537 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000538 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000539 ctx.RegisterModuleType("cc_test", TestFactory)
540 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000541 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
542
543 RegisterVndkLibraryTxtTypes(ctx)
544 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000545
546 // Additional files needed in tests that disallow non-existent source files.
547 // This includes files that are needed by all, or at least most, instances of a cc module type.
548 android.MockFS{
549 // Needed for ndk_prebuilt_(shared|static)_stl.
550 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
551 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000552)
553
554// Preparer that will define default cc modules, e.g. standard prebuilt modules.
555var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
556 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000557
558 // Additional files needed in tests that disallow non-existent source.
559 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700560 "defaults/cc/common/libc.map.txt": nil,
561 "defaults/cc/common/libdl.map.txt": nil,
562 "defaults/cc/common/libm.map.txt": nil,
563 "defaults/cc/common/ndk_libandroid_support": nil,
564 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900565 "defaults/cc/common/crtbegin_so.c": nil,
566 "defaults/cc/common/crtbegin.c": nil,
567 "defaults/cc/common/crtend_so.c": nil,
568 "defaults/cc/common/crtend.c": nil,
569 "defaults/cc/common/crtbrand.c": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000570
571 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
572 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
573 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
574 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000575 }.AddToFixture(),
576
Paul Duffin02a3d652021-02-24 18:51:54 +0000577 // Place the default cc test modules that are common to all platforms in a location that will not
578 // conflict with default test modules defined by other packages.
579 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
580 // Disable linux bionic by default.
581 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
582)
583
584// Prepare a fixture to use all cc module types, mutators and singletons fully.
585//
586// This should only be used by tests that want to run with as much of the build enabled as possible.
587var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
588 android.PrepareForIntegrationTestWithAndroid,
589 genrule.PrepareForIntegrationTestWithGenrule,
590 PrepareForTestWithCcDefaultModules,
591)
592
593// The preparer to include if running a cc related test for windows.
594var PrepareForTestOnWindows = android.GroupFixturePreparers(
595 // Place the default cc test modules for windows platforms in a location that will not conflict
596 // with default test modules defined by other packages.
597 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
598)
599
600// The preparer to include if running a cc related test for linux bionic.
601var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000602 // Enable linux bionic
603 //
604 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
605 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
606 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000607)
608
609// This adds some additional modules and singletons which might negatively impact the performance
610// of tests so they are not included in the PrepareForIntegrationTestWithCc.
611var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
612 PrepareForIntegrationTestWithCc,
613 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900614 snapshot.VendorSnapshotImageSingleton.Init(ctx)
615 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
616 RegisterVendorSnapshotModules(ctx)
617 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000618 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
619 }),
620)
621
622// TestConfig is the legacy way of creating a test Config for testing cc modules.
623//
624// See testCc for an explanation as to how to stop using this deprecated method.
625//
626// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800627func TestConfig(buildDir string, os android.OsType, env map[string]string,
628 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700629
Colin Cross98be1bb2019-12-13 20:41:13 -0800630 // add some modules that are required by the compiler and/or linker
631 bp = bp + GatherRequiredDepsForTest(os)
632
Colin Cross2fce23a2020-06-07 17:02:48 -0700633 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800634
Colin Crossf28329d2020-02-15 11:00:10 -0800635 GatherRequiredFilesForTest(mockFS)
636
Colin Cross98be1bb2019-12-13 20:41:13 -0800637 for k, v := range fs {
638 mockFS[k] = v
639 }
640
Colin Crosscb0ac952021-07-20 13:17:15 -0700641 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800642}
643
Paul Duffin02a3d652021-02-24 18:51:54 +0000644// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
645//
646// See testCc for an explanation as to how to stop using this deprecated method.
647//
648// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700649func CreateTestContext(config android.Config) *android.TestContext {
650 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000651 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000652 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800653 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400654 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800655 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
656 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000657
Kiyoung Kim48f37782021-07-07 12:42:39 +0900658 snapshot.VendorSnapshotImageSingleton.Init(ctx)
659 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
660 RegisterVendorSnapshotModules(ctx)
661 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000662 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800663 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000664
Colin Crosse1bb5d02019-09-24 14:55:04 -0700665 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100666 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100667 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700668
Colin Cross9a942872019-05-14 15:44:26 -0700669 return ctx
670}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400671
672func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
673 t.Helper()
674 mod := ctx.ModuleForTests(moduleName, variant)
675 outputFiles := mod.OutputFiles(t, "")
676 if len(outputFiles) != 1 {
677 t.Errorf("%q must have single output\n", moduleName)
678 return
679 }
680 snapshotPath := filepath.Join(subDir, snapshotFilename)
681
682 if include {
683 out := singleton.Output(snapshotPath)
684 if fake {
685 if out.Rule == nil {
686 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
687 }
688 } else {
689 if out.Input.String() != outputFiles[0].String() {
690 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
691 }
692 }
693 } else {
694 out := singleton.MaybeOutput(snapshotPath)
695 if out.Rule != nil {
696 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
697 }
698 }
699}
700
701func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
702 t.Helper()
703 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
704}
705
706func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
707 t.Helper()
708 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
709}
710
711func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
712 t.Helper()
713 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
714}
715
716func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
717 t.Helper()
718 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
719 if m.ExcludeFromVendorSnapshot() != expected {
720 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
721 }
722}
723
724func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
725 for _, moduleName := range moduleNames {
726 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
727 output := module.outputFile.Path().RelativeToTop()
728 paths = append(paths, output)
729 }
730 return paths
731}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500732
733func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
734 t.Helper()
735 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
736 if m.ExcludeFromRecoverySnapshot() != expected {
737 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
738 }
739}
Inseob Kima1888ce2022-10-04 14:42:02 +0900740
741func checkOverrides(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, jsonPath string, expected []string) {
742 out := singleton.MaybeOutput(jsonPath)
743 content := android.ContentFromFileRuleForTests(t, out)
744
745 var flags snapshotJsonFlags
746 if err := json.Unmarshal([]byte(content), &flags); err != nil {
747 t.Errorf("Error while unmarshalling json %q: %w", jsonPath, err)
748 return
749 }
750
751 for _, moduleName := range expected {
752 if !android.InList(moduleName, flags.Overrides) {
753 t.Errorf("expected %q to be in %q: %q", moduleName, flags.Overrides, content)
754 return
755 }
756 }
757}