blob: d38a57ca82462ac364dd99510aa06f67c91466a3 [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",
Colin Cross5dc62c92023-02-15 12:20:19 -080073 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090074 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090075 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090076 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050077 no_libcrt: true,
78 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090079 nocrt: true,
Jooyung Han75568392020-03-20 04:29:24 +090080 system_shared_libs: [],
81 stl: "none",
Jooyung Han75568392020-03-20 04:29:24 +090082 check_elf_files: false,
83 sanitize: {
84 never: true,
85 },
86 }
87
Liz Kammer718eb272022-01-07 10:53:37 -050088 cc_prebuilt_library_static {
89 name: "libcompiler_rt-extras",
90 defaults: ["toolchain_libs_defaults"],
91 vendor_ramdisk_available: true,
Colin Cross3e5e7782022-06-17 22:17:05 +000092 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -050093 }
94
95 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -080096 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -080097 defaults: ["toolchain_libs_defaults"],
98 host_supported: true,
Colin Cross4c4c1be2022-02-10 11:41:18 -080099 vendor_available: true,
100 vendor_ramdisk_available: true,
101 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000102 srcs: [""],
Colin Cross06c80eb2022-02-10 10:34:19 -0800103 }
104
Liz Kammer718eb272022-01-07 10:53:37 -0500105 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800106 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500107 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000108 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500109 }
110
111 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800112 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500113 defaults: [
114 "linux_bionic_supported",
115 "toolchain_libs_defaults",
116 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500117 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800118 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000119 srcs: [""],
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800120 }
121
Liz Kammer718eb272022-01-07 10:53:37 -0500122 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800123 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500124 defaults: [
125 "linux_bionic_supported",
126 "toolchain_libs_defaults",
127 ],
Colin Cross3e5e7782022-06-17 22:17:05 +0000128 srcs: [""],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700129 }
130
Paul Duffind6867912019-12-19 14:38:36 +0000131 // Needed for sanitizer
132 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800133 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500134 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000135 srcs: [""],
Paul Duffind6867912019-12-19 14:38:36 +0000136 }
137
Colin Cross06c80eb2022-02-10 10:34:19 -0800138 cc_prebuilt_library_static {
Colin Cross5dc62c92023-02-15 12:20:19 -0800139 name: "libclang_rt.ubsan_standalone.static",
140 defaults: ["toolchain_libs_defaults"],
141 srcs: [""],
142 }
143
144 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800145 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800146 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000147 host_supported: true,
148 target: {
149 android_arm64: {
150 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
151 },
152 android_arm: {
153 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
154 },
155 linux_glibc_x86_64: {
156 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
157 },
158 linux_glibc_x86: {
159 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
160 },
Colin Cross5dc62c92023-02-15 12:20:19 -0800161 linux_musl_x86_64: {
162 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
163 },
164 linux_musl_x86: {
165 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
166 },
Colin Cross3e5e7782022-06-17 22:17:05 +0000167 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800168 }
169
Inseob Kimc0907f12019-02-08 21:00:45 +0900170 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900171 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100172 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700173 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900174 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800175 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900176 system_shared_libs: [],
177 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800178 stubs: {
179 versions: ["27", "28", "29"],
180 },
Colin Cross203b4212021-04-26 17:19:41 -0700181 llndk: {
182 symbol_file: "libc.map.txt",
183 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900184 }
185 cc_library {
186 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100187 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700188 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900189 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800190 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900191 system_shared_libs: [],
192 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800193 stubs: {
194 versions: ["27", "28", "29"],
195 },
196 apex_available: [
197 "//apex_available:platform",
198 "myapex"
199 ],
Colin Cross203b4212021-04-26 17:19:41 -0700200 llndk: {
201 symbol_file: "libm.map.txt",
202 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900203 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400204
205 // Coverage libraries
206 cc_library {
207 name: "libprofile-extras",
208 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500209 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900210 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400211 recovery_available: true,
212 native_coverage: false,
213 system_shared_libs: [],
214 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400215 }
216 cc_library {
217 name: "libprofile-clang-extras",
218 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500219 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900220 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400221 recovery_available: true,
222 native_coverage: false,
223 system_shared_libs: [],
224 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400225 }
226 cc_library {
227 name: "libprofile-extras_ndk",
228 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900229 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400230 native_coverage: false,
231 system_shared_libs: [],
232 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400233 sdk_version: "current",
234 }
235 cc_library {
236 name: "libprofile-clang-extras_ndk",
237 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900238 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400239 native_coverage: false,
240 system_shared_libs: [],
241 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400242 sdk_version: "current",
243 }
244
Inseob Kimc0907f12019-02-08 21:00:45 +0900245 cc_library {
246 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100247 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700248 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900249 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800250 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900251 system_shared_libs: [],
252 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800253 stubs: {
254 versions: ["27", "28", "29"],
255 },
256 apex_available: [
257 "//apex_available:platform",
258 "myapex"
259 ],
Colin Cross203b4212021-04-26 17:19:41 -0700260 llndk: {
261 symbol_file: "libdl.map.txt",
262 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900263 }
264 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900265 name: "libft2",
266 no_libcrt: true,
267 nocrt: true,
268 system_shared_libs: [],
269 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700270 llndk: {
271 symbol_file: "libft2.map.txt",
272 private: true,
273 }
Jooyung Han097087b2019-10-22 19:32:18 +0900274 }
275 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900276 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700277 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900278 nocrt: true,
279 system_shared_libs: [],
280 stl: "none",
281 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500282 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900283 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900284 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900285 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900286 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900287 apex_available: [
288 "//apex_available:platform",
289 "//apex_available:anyapex",
290 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900291 }
292 cc_library {
293 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700294 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900295 nocrt: true,
296 system_shared_libs: [],
297 stl: "none",
298 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900299 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900301 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900302 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900303 vndk: {
304 enabled: true,
305 support_system_process: true,
306 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800307 apex_available: [
308 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500309 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800310 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900311 }
312 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700313 name: "libc++demangle",
314 no_libcrt: true,
315 nocrt: true,
316 system_shared_libs: [],
317 stl: "none",
318 host_supported: false,
319 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500320 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900321 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700322 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900323 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900324 apex_available: [
325 "//apex_available:platform",
326 "//apex_available:anyapex",
327 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700328 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900329
Jiyong Park541142c2020-03-07 16:35:46 +0900330 cc_defaults {
331 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100332 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900333 recovery_available: true,
334 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500335 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900336 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900337 native_bridge_supported: true,
338 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700339 min_sdk_version: "16",
340 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700341 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900342 apex_available: [
343 "//apex_available:platform",
344 "//apex_available:anyapex",
345 ],
346 }
347
Inseob Kimc0907f12019-02-08 21:00:45 +0900348 cc_object {
349 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900350 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900351 srcs: ["crtbegin_so.c"],
352 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900353 }
354
355 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700356 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900357 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900358 srcs: ["crtbegin.c"],
359 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700360 }
361
362 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900363 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900364 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900365 srcs: ["crtbegin.c"],
366 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900367 }
368
369 cc_object {
370 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900371 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900372 srcs: ["crtend_so.c"],
373 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900374 }
375
376 cc_object {
377 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900378 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900379 srcs: ["crtend.c"],
380 objs: ["crtbrand"],
381 }
382
383 cc_object {
384 name: "crtbrand",
385 defaults: ["crt_defaults"],
386 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900387 }
388
389 cc_library {
390 name: "libprotobuf-cpp-lite",
391 }
Colin Crossf28329d2020-02-15 11:00:10 -0800392
393 cc_library {
394 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700395 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800396 stl: "none",
397 system_shared_libs: [],
398 }
399
Dan Albertde5aade2020-06-30 12:32:51 -0700400 ndk_library {
401 name: "libc",
402 first_version: "minimum",
403 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800404 }
405
Dan Albertde5aade2020-06-30 12:32:51 -0700406 ndk_library {
407 name: "libm",
408 first_version: "minimum",
409 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800410 }
411
Dan Albertde5aade2020-06-30 12:32:51 -0700412 ndk_library {
413 name: "libdl",
414 first_version: "minimum",
415 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800416 }
417
Colin Crossf28329d2020-02-15 11:00:10 -0800418 ndk_prebuilt_shared_stl {
419 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700420 export_include_dirs: ["ndk_libc++_shared"],
421 }
422
423 ndk_prebuilt_static_stl {
424 name: "ndk_libandroid_support",
425 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800426 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900427
428 cc_library_static {
429 name: "libgoogle-benchmark",
430 sdk_version: "current",
431 stl: "none",
432 system_shared_libs: [],
433 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700434
435 cc_library_static {
436 name: "note_memtag_heap_async",
437 }
438
439 cc_library_static {
440 name: "note_memtag_heap_sync",
441 }
Colin Cross528d67e2021-07-23 22:23:07 +0000442
Colin Cross528d67e2021-07-23 22:23:07 +0000443 cc_library {
444 name: "libc_musl",
445 host_supported: true,
446 no_libcrt: true,
447 nocrt: true,
448 system_shared_libs: [],
449 stl: "none",
450 }
Colin Crossf28329d2020-02-15 11:00:10 -0800451 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000452}
Colin Crossf28329d2020-02-15 11:00:10 -0800453
Paul Duffin02a3d652021-02-24 18:51:54 +0000454func withWindowsModules() string {
455 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500456 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000457 name: "libwinpthread",
458 host_supported: true,
459 enabled: false,
460 target: {
461 windows: {
462 enabled: true,
463 },
464 },
Liz Kammer718eb272022-01-07 10:53:37 -0500465 stl: "none",
466 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000467 }
468 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000469}
470
Paul Duffin02a3d652021-02-24 18:51:54 +0000471func withLinuxBionic() string {
472 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100473 cc_binary {
474 name: "linker",
475 defaults: ["linux_bionic_supported"],
476 recovery_available: true,
477 stl: "none",
478 nocrt: true,
479 static_executable: true,
480 native_coverage: false,
481 system_shared_libs: [],
482 }
483
484 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700485 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100486 host_supported: true,
487 device_supported: false,
488 target: {
489 host: {
490 enabled: false,
491 },
492 linux_bionic: {
493 enabled: true,
494 },
495 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700496 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100497 }
498
499 cc_defaults {
500 name: "linux_bionic_supported",
501 host_supported: true,
502 target: {
503 host: {
504 enabled: false,
505 },
506 linux_bionic: {
507 enabled: true,
508 },
509 },
510 }
511 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000512}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100513
Paul Duffin02a3d652021-02-24 18:51:54 +0000514func withoutLinuxBionic() string {
515 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100516 cc_defaults {
517 name: "linux_bionic_supported",
518 }
519 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900520}
Colin Cross9a942872019-05-14 15:44:26 -0700521
Colin Crossf28329d2020-02-15 11:00:10 -0800522func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800523}
524
Paul Duffin02a3d652021-02-24 18:51:54 +0000525// The directory in which cc linux bionic default modules will be defined.
526//
527// Placing them here ensures that their location does not conflict with default test modules
528// defined by other packages.
529const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
530
531// The directory in which the default cc common test modules will be defined.
532//
533// Placing them here ensures that their location does not conflict with default test modules
534// defined by other packages.
535const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
536
537// Test fixture preparer that will register most cc build components.
538//
539// Singletons and mutators should only be added here if they are needed for a majority of cc
540// module types, otherwise they should be added under a separate preparer to allow them to be
541// selected only when needed to reduce test execution time.
542//
543// Module types do not have much of an overhead unless they are used so this should include as many
544// module types as possible. The exceptions are those module types that require mutators and/or
545// singletons in order to function in which case they should be kept together in a separate
546// preparer.
547var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
548 android.PrepareForTestWithAndroidBuildComponents,
549 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
550 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000551 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000552 ctx.RegisterModuleType("cc_test", TestFactory)
553 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000554 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
555
556 RegisterVndkLibraryTxtTypes(ctx)
557 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000558
559 // Additional files needed in tests that disallow non-existent source files.
560 // This includes files that are needed by all, or at least most, instances of a cc module type.
561 android.MockFS{
562 // Needed for ndk_prebuilt_(shared|static)_stl.
563 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
564 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000565)
566
567// Preparer that will define default cc modules, e.g. standard prebuilt modules.
568var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
569 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000570
571 // Additional files needed in tests that disallow non-existent source.
572 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700573 "defaults/cc/common/libc.map.txt": nil,
574 "defaults/cc/common/libdl.map.txt": nil,
575 "defaults/cc/common/libm.map.txt": nil,
576 "defaults/cc/common/ndk_libandroid_support": nil,
577 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900578 "defaults/cc/common/crtbegin_so.c": nil,
579 "defaults/cc/common/crtbegin.c": nil,
580 "defaults/cc/common/crtend_so.c": nil,
581 "defaults/cc/common/crtend.c": nil,
582 "defaults/cc/common/crtbrand.c": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000583
584 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
585 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
586 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
587 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": 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
Colin Cross5dc62c92023-02-15 12:20:19 -0800635// PrepareForTestWithHostMusl sets the host configuration to musl libc instead of glibc. It also disables the test
636// on mac, which doesn't support musl libc, and adds musl modules.
637var PrepareForTestWithHostMusl = android.GroupFixturePreparers(
638 android.FixtureModifyConfig(android.ModifyTestConfigForMusl),
639 android.PrepareForSkipTestOnMac,
640 android.FixtureAddTextFile("external/musl/Android.bp", `
641 cc_defaults {
642 name: "libc_musl_crt_defaults",
643 host_supported: true,
644 device_supported: false,
645 }
646
647 cc_object {
648 name: "libc_musl_crtbegin_so",
649 defaults: ["libc_musl_crt_defaults"],
650 }
651
652 cc_object {
653 name: "libc_musl_crtend_so",
654 defaults: ["libc_musl_crt_defaults"],
655 }
656
657 cc_object {
658 name: "libc_musl_crtbegin_dynamic",
659 defaults: ["libc_musl_crt_defaults"],
660 }
661
662 cc_object {
663 name: "libc_musl_crtbegin_static",
664 defaults: ["libc_musl_crt_defaults"],
665 }
666
667 cc_object {
668 name: "libc_musl_crtend",
669 defaults: ["libc_musl_crt_defaults"],
670 }
671 `),
672)
673
Paul Duffin02a3d652021-02-24 18:51:54 +0000674// TestConfig is the legacy way of creating a test Config for testing cc modules.
675//
676// See testCc for an explanation as to how to stop using this deprecated method.
677//
678// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800679func TestConfig(buildDir string, os android.OsType, env map[string]string,
680 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700681
Colin Cross98be1bb2019-12-13 20:41:13 -0800682 // add some modules that are required by the compiler and/or linker
683 bp = bp + GatherRequiredDepsForTest(os)
684
Colin Cross2fce23a2020-06-07 17:02:48 -0700685 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800686
Colin Crossf28329d2020-02-15 11:00:10 -0800687 GatherRequiredFilesForTest(mockFS)
688
Colin Cross98be1bb2019-12-13 20:41:13 -0800689 for k, v := range fs {
690 mockFS[k] = v
691 }
692
Colin Crosscb0ac952021-07-20 13:17:15 -0700693 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800694}
695
Paul Duffin02a3d652021-02-24 18:51:54 +0000696// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
697//
698// See testCc for an explanation as to how to stop using this deprecated method.
699//
700// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700701func CreateTestContext(config android.Config) *android.TestContext {
702 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000703 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000704 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800705 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400706 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800707 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
708 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000709
Kiyoung Kim48f37782021-07-07 12:42:39 +0900710 snapshot.VendorSnapshotImageSingleton.Init(ctx)
711 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
712 RegisterVendorSnapshotModules(ctx)
713 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000714 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800715 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000716
Colin Crosse1bb5d02019-09-24 14:55:04 -0700717 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100718 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100719 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700720
Colin Cross9a942872019-05-14 15:44:26 -0700721 return ctx
722}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400723
724func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
725 t.Helper()
726 mod := ctx.ModuleForTests(moduleName, variant)
727 outputFiles := mod.OutputFiles(t, "")
728 if len(outputFiles) != 1 {
729 t.Errorf("%q must have single output\n", moduleName)
730 return
731 }
732 snapshotPath := filepath.Join(subDir, snapshotFilename)
733
734 if include {
735 out := singleton.Output(snapshotPath)
736 if fake {
737 if out.Rule == nil {
738 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
739 }
740 } else {
741 if out.Input.String() != outputFiles[0].String() {
742 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
743 }
744 }
745 } else {
746 out := singleton.MaybeOutput(snapshotPath)
747 if out.Rule != nil {
748 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
749 }
750 }
751}
752
753func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
754 t.Helper()
755 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
756}
757
758func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
759 t.Helper()
760 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
761}
762
763func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
764 t.Helper()
765 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
766}
767
768func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
769 t.Helper()
770 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
771 if m.ExcludeFromVendorSnapshot() != expected {
772 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
773 }
774}
775
776func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
777 for _, moduleName := range moduleNames {
778 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
779 output := module.outputFile.Path().RelativeToTop()
780 paths = append(paths, output)
781 }
782 return paths
783}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500784
785func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
786 t.Helper()
787 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
788 if m.ExcludeFromRecoverySnapshot() != expected {
789 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
790 }
791}
Inseob Kima1888ce2022-10-04 14:42:02 +0900792
793func 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 +0000794 t.Helper()
Inseob Kima1888ce2022-10-04 14:42:02 +0900795 out := singleton.MaybeOutput(jsonPath)
796 content := android.ContentFromFileRuleForTests(t, out)
797
798 var flags snapshotJsonFlags
799 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 +0000800 t.Errorf("Error while unmarshalling json %q: %s", jsonPath, err.Error())
Inseob Kima1888ce2022-10-04 14:42:02 +0900801 return
802 }
803
804 for _, moduleName := range expected {
805 if !android.InList(moduleName, flags.Overrides) {
806 t.Errorf("expected %q to be in %q: %q", moduleName, flags.Overrides, content)
807 return
808 }
809 }
810}