blob: ced09290fef4c2fe3c651999e5604161f7ef662e [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)
Dan Albertde5aade2020-06-30 12:32:51 -070043 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Spandan Das73bcafc2022-08-18 23:26:00 +000044 ctx.RegisterModuleType("ndk_headers", ndkHeadersFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000045}
46
Paul Duffina04c1072020-03-02 10:16:35 +000047func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000048 ret := commonDefaultModules()
49
50 supportLinuxBionic := false
51 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000052 if os == android.Windows {
53 ret += withWindowsModules()
54 }
55 if os == android.LinuxBionic {
56 supportLinuxBionic = true
57 ret += withLinuxBionic()
58 }
59 }
60
61 if !supportLinuxBionic {
62 ret += withoutLinuxBionic()
63 }
64
65 return ret
66}
67
68func commonDefaultModules() string {
69 return `
Liz Kammer718eb272022-01-07 10:53:37 -050070 cc_defaults {
71 name: "toolchain_libs_defaults",
Colin Cross5dc62c92023-02-15 12:20:19 -080072 host_supported: true,
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 Cross5dc62c92023-02-15 12:20:19 -0800138 name: "libclang_rt.ubsan_standalone.static",
139 defaults: ["toolchain_libs_defaults"],
140 srcs: [""],
141 }
142
143 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800144 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800145 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000146 host_supported: true,
147 target: {
148 android_arm64: {
149 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
150 },
151 android_arm: {
152 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
153 },
154 linux_glibc_x86_64: {
155 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
156 },
157 linux_glibc_x86: {
158 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
159 },
Colin Cross5dc62c92023-02-15 12:20:19 -0800160 linux_musl_x86_64: {
161 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
162 },
163 linux_musl_x86: {
164 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
165 },
Colin Cross3e5e7782022-06-17 22:17:05 +0000166 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800167 }
168
Inseob Kimc0907f12019-02-08 21:00:45 +0900169 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900170 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100171 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700172 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900173 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800174 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900175 system_shared_libs: [],
176 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800177 stubs: {
178 versions: ["27", "28", "29"],
179 },
Colin Cross203b4212021-04-26 17:19:41 -0700180 llndk: {
181 symbol_file: "libc.map.txt",
182 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900183 }
184 cc_library {
185 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100186 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700187 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900188 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800189 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900190 system_shared_libs: [],
191 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800192 stubs: {
193 versions: ["27", "28", "29"],
194 },
195 apex_available: [
196 "//apex_available:platform",
197 "myapex"
198 ],
Colin Cross203b4212021-04-26 17:19:41 -0700199 llndk: {
200 symbol_file: "libm.map.txt",
201 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900202 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400203
204 // Coverage libraries
205 cc_library {
206 name: "libprofile-extras",
207 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500208 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900209 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400210 recovery_available: true,
211 native_coverage: false,
212 system_shared_libs: [],
213 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400214 }
215 cc_library {
216 name: "libprofile-clang-extras",
217 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500218 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900219 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400220 recovery_available: true,
221 native_coverage: false,
222 system_shared_libs: [],
223 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400224 }
225 cc_library {
226 name: "libprofile-extras_ndk",
227 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900228 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400229 native_coverage: false,
230 system_shared_libs: [],
231 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400232 sdk_version: "current",
233 }
234 cc_library {
235 name: "libprofile-clang-extras_ndk",
236 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900237 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400238 native_coverage: false,
239 system_shared_libs: [],
240 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400241 sdk_version: "current",
242 }
243
Inseob Kimc0907f12019-02-08 21:00:45 +0900244 cc_library {
245 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100246 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700247 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900248 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800249 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900250 system_shared_libs: [],
251 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800252 stubs: {
253 versions: ["27", "28", "29"],
254 },
255 apex_available: [
256 "//apex_available:platform",
257 "myapex"
258 ],
Colin Cross203b4212021-04-26 17:19:41 -0700259 llndk: {
260 symbol_file: "libdl.map.txt",
261 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900262 }
263 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900264 name: "libft2",
265 no_libcrt: true,
266 nocrt: true,
267 system_shared_libs: [],
268 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700269 llndk: {
270 symbol_file: "libft2.map.txt",
271 private: true,
272 }
Jooyung Han097087b2019-10-22 19:32:18 +0900273 }
274 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900275 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700276 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900277 nocrt: true,
278 system_shared_libs: [],
279 stl: "none",
280 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500281 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900282 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900283 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900284 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900285 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900286 apex_available: [
287 "//apex_available:platform",
288 "//apex_available:anyapex",
289 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900290 }
291 cc_library {
292 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700293 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900294 nocrt: true,
295 system_shared_libs: [],
296 stl: "none",
297 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900298 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900299 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900300 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900301 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900302 vndk: {
303 enabled: true,
304 support_system_process: true,
305 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800306 apex_available: [
307 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500308 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800309 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900310 }
311 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700312 name: "libc++demangle",
313 no_libcrt: true,
314 nocrt: true,
315 system_shared_libs: [],
316 stl: "none",
317 host_supported: false,
318 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500319 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900320 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700321 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900322 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900323 apex_available: [
324 "//apex_available:platform",
325 "//apex_available:anyapex",
326 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700327 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900328
Jiyong Park541142c2020-03-07 16:35:46 +0900329 cc_defaults {
330 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100331 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900332 recovery_available: true,
333 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500334 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900335 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900336 native_bridge_supported: true,
337 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700338 min_sdk_version: "16",
339 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700340 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900341 apex_available: [
342 "//apex_available:platform",
343 "//apex_available:anyapex",
344 ],
345 }
346
Inseob Kimc0907f12019-02-08 21:00:45 +0900347 cc_object {
348 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900349 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900350 srcs: ["crtbegin_so.c"],
351 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900352 }
353
354 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700355 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900356 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900357 srcs: ["crtbegin.c"],
358 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700359 }
360
361 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900362 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900363 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900364 srcs: ["crtbegin.c"],
365 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900366 }
367
368 cc_object {
369 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900370 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900371 srcs: ["crtend_so.c"],
372 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900373 }
374
375 cc_object {
376 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900377 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900378 srcs: ["crtend.c"],
379 objs: ["crtbrand"],
380 }
381
382 cc_object {
383 name: "crtbrand",
384 defaults: ["crt_defaults"],
385 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900386 }
387
388 cc_library {
389 name: "libprotobuf-cpp-lite",
390 }
Colin Crossf28329d2020-02-15 11:00:10 -0800391
392 cc_library {
393 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700394 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800395 stl: "none",
396 system_shared_libs: [],
397 }
398
Dan Albertde5aade2020-06-30 12:32:51 -0700399 ndk_library {
400 name: "libc",
401 first_version: "minimum",
402 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800403 }
404
Dan Albertde5aade2020-06-30 12:32:51 -0700405 ndk_library {
406 name: "libm",
407 first_version: "minimum",
408 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800409 }
410
Dan Albertde5aade2020-06-30 12:32:51 -0700411 ndk_library {
412 name: "libdl",
413 first_version: "minimum",
414 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800415 }
416
Colin Crossf28329d2020-02-15 11:00:10 -0800417 ndk_prebuilt_shared_stl {
418 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700419 export_include_dirs: ["ndk_libc++_shared"],
420 }
421
422 ndk_prebuilt_static_stl {
423 name: "ndk_libandroid_support",
424 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800425 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900426
427 cc_library_static {
428 name: "libgoogle-benchmark",
429 sdk_version: "current",
430 stl: "none",
431 system_shared_libs: [],
432 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700433
434 cc_library_static {
435 name: "note_memtag_heap_async",
436 }
437
438 cc_library_static {
439 name: "note_memtag_heap_sync",
440 }
Colin Cross528d67e2021-07-23 22:23:07 +0000441
Colin Cross528d67e2021-07-23 22:23:07 +0000442 cc_library {
443 name: "libc_musl",
444 host_supported: true,
445 no_libcrt: true,
446 nocrt: true,
447 system_shared_libs: [],
448 stl: "none",
449 }
Colin Crossf28329d2020-02-15 11:00:10 -0800450 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000451}
Colin Crossf28329d2020-02-15 11:00:10 -0800452
Paul Duffin02a3d652021-02-24 18:51:54 +0000453func withWindowsModules() string {
454 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500455 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000456 name: "libwinpthread",
457 host_supported: true,
458 enabled: false,
459 target: {
460 windows: {
461 enabled: true,
462 },
463 },
Liz Kammer718eb272022-01-07 10:53:37 -0500464 stl: "none",
465 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000466 }
467 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000468}
469
Paul Duffin02a3d652021-02-24 18:51:54 +0000470func withLinuxBionic() string {
471 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100472 cc_binary {
473 name: "linker",
474 defaults: ["linux_bionic_supported"],
475 recovery_available: true,
476 stl: "none",
477 nocrt: true,
478 static_executable: true,
479 native_coverage: false,
480 system_shared_libs: [],
481 }
482
483 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700484 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100485 host_supported: true,
486 device_supported: false,
487 target: {
488 host: {
489 enabled: false,
490 },
491 linux_bionic: {
492 enabled: true,
493 },
494 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700495 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100496 }
497
498 cc_defaults {
499 name: "linux_bionic_supported",
500 host_supported: true,
501 target: {
502 host: {
503 enabled: false,
504 },
505 linux_bionic: {
506 enabled: true,
507 },
508 },
509 }
510 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000511}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100512
Paul Duffin02a3d652021-02-24 18:51:54 +0000513func withoutLinuxBionic() string {
514 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100515 cc_defaults {
516 name: "linux_bionic_supported",
517 }
518 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900519}
Colin Cross9a942872019-05-14 15:44:26 -0700520
Colin Crossf28329d2020-02-15 11:00:10 -0800521func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800522}
523
Paul Duffin02a3d652021-02-24 18:51:54 +0000524// The directory in which cc linux bionic default modules will be defined.
525//
526// Placing them here ensures that their location does not conflict with default test modules
527// defined by other packages.
528const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
529
530// The directory in which the default cc common test 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 DefaultCcCommonTestModulesDir = "defaults/cc/common/"
535
536// Test fixture preparer that will register most cc build components.
537//
538// Singletons and mutators should only be added here if they are needed for a majority of cc
539// module types, otherwise they should be added under a separate preparer to allow them to be
540// selected only when needed to reduce test execution time.
541//
542// Module types do not have much of an overhead unless they are used so this should include as many
543// module types as possible. The exceptions are those module types that require mutators and/or
544// singletons in order to function in which case they should be kept together in a separate
545// preparer.
546var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
547 android.PrepareForTestWithAndroidBuildComponents,
548 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
549 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000550 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000551 ctx.RegisterModuleType("cc_test", TestFactory)
552 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000553 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
554
555 RegisterVndkLibraryTxtTypes(ctx)
556 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000557
558 // Additional files needed in tests that disallow non-existent source files.
559 // This includes files that are needed by all, or at least most, instances of a cc module type.
560 android.MockFS{
561 // Needed for ndk_prebuilt_(shared|static)_stl.
562 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
563 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000564)
565
566// Preparer that will define default cc modules, e.g. standard prebuilt modules.
567var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
568 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000569
570 // Additional files needed in tests that disallow non-existent source.
571 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700572 "defaults/cc/common/libc.map.txt": nil,
573 "defaults/cc/common/libdl.map.txt": nil,
574 "defaults/cc/common/libm.map.txt": nil,
575 "defaults/cc/common/ndk_libandroid_support": nil,
576 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900577 "defaults/cc/common/crtbegin_so.c": nil,
578 "defaults/cc/common/crtbegin.c": nil,
579 "defaults/cc/common/crtend_so.c": nil,
580 "defaults/cc/common/crtend.c": nil,
581 "defaults/cc/common/crtbrand.c": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000582
583 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
584 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
585 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
586 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000587 }.AddToFixture(),
588
Paul Duffin02a3d652021-02-24 18:51:54 +0000589 // Place the default cc test modules that are common to all platforms in a location that will not
590 // conflict with default test modules defined by other packages.
591 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
592 // Disable linux bionic by default.
593 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
594)
595
596// Prepare a fixture to use all cc module types, mutators and singletons fully.
597//
598// This should only be used by tests that want to run with as much of the build enabled as possible.
599var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
600 android.PrepareForIntegrationTestWithAndroid,
601 genrule.PrepareForIntegrationTestWithGenrule,
602 PrepareForTestWithCcDefaultModules,
603)
604
605// The preparer to include if running a cc related test for windows.
606var PrepareForTestOnWindows = android.GroupFixturePreparers(
607 // Place the default cc test modules for windows platforms in a location that will not conflict
608 // with default test modules defined by other packages.
609 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
610)
611
612// The preparer to include if running a cc related test for linux bionic.
613var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000614 // Enable linux bionic
615 //
616 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
617 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
618 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000619)
620
621// This adds some additional modules and singletons which might negatively impact the performance
622// of tests so they are not included in the PrepareForIntegrationTestWithCc.
623var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
624 PrepareForIntegrationTestWithCc,
625 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900626 snapshot.VendorSnapshotImageSingleton.Init(ctx)
627 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
628 RegisterVendorSnapshotModules(ctx)
629 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000630 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
631 }),
632)
633
Colin Cross5dc62c92023-02-15 12:20:19 -0800634// PrepareForTestWithHostMusl sets the host configuration to musl libc instead of glibc. It also disables the test
635// on mac, which doesn't support musl libc, and adds musl modules.
636var PrepareForTestWithHostMusl = android.GroupFixturePreparers(
637 android.FixtureModifyConfig(android.ModifyTestConfigForMusl),
638 android.PrepareForSkipTestOnMac,
639 android.FixtureAddTextFile("external/musl/Android.bp", `
640 cc_defaults {
641 name: "libc_musl_crt_defaults",
642 host_supported: true,
643 device_supported: false,
644 }
645
646 cc_object {
647 name: "libc_musl_crtbegin_so",
648 defaults: ["libc_musl_crt_defaults"],
649 }
650
651 cc_object {
652 name: "libc_musl_crtend_so",
653 defaults: ["libc_musl_crt_defaults"],
654 }
655
656 cc_object {
657 name: "libc_musl_crtbegin_dynamic",
658 defaults: ["libc_musl_crt_defaults"],
659 }
660
661 cc_object {
662 name: "libc_musl_crtbegin_static",
663 defaults: ["libc_musl_crt_defaults"],
664 }
665
666 cc_object {
667 name: "libc_musl_crtend",
668 defaults: ["libc_musl_crt_defaults"],
669 }
670 `),
671)
672
Vinh Trancde10162023-03-09 22:07:19 -0500673// PrepareForTestWithFdoProfile registers module types to test with fdo_profile
674var PrepareForTestWithFdoProfile = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
675 ctx.RegisterModuleType("soong_namespace", android.NamespaceFactory)
676 ctx.RegisterModuleType("fdo_profile", fdoProfileFactory)
677})
678
Paul Duffin02a3d652021-02-24 18:51:54 +0000679// TestConfig is the legacy way of creating a test Config for testing cc modules.
680//
681// See testCc for an explanation as to how to stop using this deprecated method.
682//
683// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800684func TestConfig(buildDir string, os android.OsType, env map[string]string,
685 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700686
Colin Cross98be1bb2019-12-13 20:41:13 -0800687 // add some modules that are required by the compiler and/or linker
688 bp = bp + GatherRequiredDepsForTest(os)
689
Colin Cross2fce23a2020-06-07 17:02:48 -0700690 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800691
Colin Crossf28329d2020-02-15 11:00:10 -0800692 GatherRequiredFilesForTest(mockFS)
693
Colin Cross98be1bb2019-12-13 20:41:13 -0800694 for k, v := range fs {
695 mockFS[k] = v
696 }
697
Colin Crosscb0ac952021-07-20 13:17:15 -0700698 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800699}
700
Paul Duffin02a3d652021-02-24 18:51:54 +0000701// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
702//
703// See testCc for an explanation as to how to stop using this deprecated method.
704//
705// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700706func CreateTestContext(config android.Config) *android.TestContext {
707 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000708 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000709 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800710 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400711 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800712 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
713 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000714
Kiyoung Kim48f37782021-07-07 12:42:39 +0900715 snapshot.VendorSnapshotImageSingleton.Init(ctx)
716 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
717 RegisterVendorSnapshotModules(ctx)
718 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000719 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800720 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000721
Colin Crosse1bb5d02019-09-24 14:55:04 -0700722 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100723 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100724 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700725
Colin Cross9a942872019-05-14 15:44:26 -0700726 return ctx
727}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400728
729func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
730 t.Helper()
731 mod := ctx.ModuleForTests(moduleName, variant)
732 outputFiles := mod.OutputFiles(t, "")
733 if len(outputFiles) != 1 {
734 t.Errorf("%q must have single output\n", moduleName)
735 return
736 }
737 snapshotPath := filepath.Join(subDir, snapshotFilename)
738
739 if include {
740 out := singleton.Output(snapshotPath)
741 if fake {
742 if out.Rule == nil {
743 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
744 }
745 } else {
746 if out.Input.String() != outputFiles[0].String() {
747 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
748 }
749 }
750 } else {
751 out := singleton.MaybeOutput(snapshotPath)
752 if out.Rule != nil {
753 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
754 }
755 }
756}
757
758func CheckSnapshot(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, true, false)
761}
762
763func CheckSnapshotExclude(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, false, false)
766}
767
768func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
769 t.Helper()
770 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
771}
772
773func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
774 t.Helper()
775 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
776 if m.ExcludeFromVendorSnapshot() != expected {
777 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
778 }
779}
780
781func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
782 for _, moduleName := range moduleNames {
783 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
784 output := module.outputFile.Path().RelativeToTop()
785 paths = append(paths, output)
786 }
787 return paths
788}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500789
790func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
791 t.Helper()
792 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
793 if m.ExcludeFromRecoverySnapshot() != expected {
794 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
795 }
796}
Inseob Kima1888ce2022-10-04 14:42:02 +0900797
798func 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 +0000799 t.Helper()
Inseob Kima1888ce2022-10-04 14:42:02 +0900800 out := singleton.MaybeOutput(jsonPath)
801 content := android.ContentFromFileRuleForTests(t, out)
802
803 var flags snapshotJsonFlags
804 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 +0000805 t.Errorf("Error while unmarshalling json %q: %s", jsonPath, err.Error())
Inseob Kima1888ce2022-10-04 14:42:02 +0900806 return
807 }
808
809 for _, moduleName := range expected {
810 if !android.InList(moduleName, flags.Overrides) {
811 t.Errorf("expected %q to be in %q: %q", moduleName, flags.Overrides, content)
812 return
813 }
814 }
815}