blob: e8f3481156f84c412d1f390a4374999f75fa06b3 [file] [log] [blame]
Inseob Kimc0907f12019-02-08 21:00:45 +09001// Copyright (C) 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
Ivan Lozanod67a6b02021-05-20 13:01:32 -040018 "path/filepath"
19 "testing"
20
Inseob Kimc0907f12019-02-08 21:00:45 +090021 "android/soong/android"
Colin Crosse9fe2942020-11-10 18:12:15 -080022 "android/soong/genrule"
Kiyoung Kim48f37782021-07-07 12:42:39 +090023 "android/soong/snapshot"
Inseob Kimc0907f12019-02-08 21:00:45 +090024)
25
Paul Duffin77980a82019-12-19 16:01:36 +000026func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000027 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000028 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000029 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000030 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000031 RegisterLibraryHeadersBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000032
33 ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
Jiyong Park46a512f2020-12-04 18:02:13 +090034 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000035 ctx.RegisterModuleType("cc_object", ObjectFactory)
Martin Stjernholm7feceb22020-07-11 04:33:29 +010036 ctx.RegisterModuleType("cc_genrule", genRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080037 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070038 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080039 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070040 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000041}
42
Paul Duffina04c1072020-03-02 10:16:35 +000043func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000044 ret := commonDefaultModules()
45
46 supportLinuxBionic := false
47 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000048 if os == android.Windows {
49 ret += withWindowsModules()
50 }
51 if os == android.LinuxBionic {
52 supportLinuxBionic = true
53 ret += withLinuxBionic()
54 }
55 }
56
57 if !supportLinuxBionic {
58 ret += withoutLinuxBionic()
59 }
60
61 return ret
62}
63
64func commonDefaultModules() string {
65 return `
Inseob Kimc0907f12019-02-08 21:00:45 +090066 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +090067 name: "libcompiler_rt-extras",
68 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050069 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090070 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090071 recovery_available: true,
72 src: "",
73 }
74
75 toolchain_library {
76 name: "libclang_rt.builtins-arm-android",
77 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050078 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090079 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090080 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080081 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090082 src: "",
83 }
84
85 toolchain_library {
86 name: "libclang_rt.builtins-aarch64-android",
87 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050088 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090089 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090090 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080091 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090092 src: "",
93 }
94
Jooyung Han75568392020-03-20 04:29:24 +090095 cc_prebuilt_library_shared {
96 name: "libclang_rt.hwasan-aarch64-android",
97 nocrt: true,
98 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090099 product_available: true,
Jooyung Han75568392020-03-20 04:29:24 +0900100 recovery_available: true,
101 system_shared_libs: [],
102 stl: "none",
103 srcs: [""],
104 check_elf_files: false,
105 sanitize: {
106 never: true,
107 },
108 }
109
Inseob Kimc0907f12019-02-08 21:00:45 +0900110 toolchain_library {
111 name: "libclang_rt.builtins-i686-android",
112 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500113 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900114 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900115 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800116 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900117 src: "",
118 }
119
120 toolchain_library {
121 name: "libclang_rt.builtins-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100122 defaults: ["linux_bionic_supported"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900123 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500124 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900125 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900126 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800127 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900128 src: "",
129 }
130
131 toolchain_library {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800132 name: "libunwind",
133 defaults: ["linux_bionic_supported"],
134 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500135 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800136 product_available: true,
137 recovery_available: true,
138 native_bridge_supported: true,
139 src: "",
140 }
141
142 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700143 name: "libclang_rt.fuzzer-arm-android",
144 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900145 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700146 recovery_available: true,
147 src: "",
148 }
149
150 toolchain_library {
151 name: "libclang_rt.fuzzer-aarch64-android",
152 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900153 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700154 recovery_available: true,
155 src: "",
156 }
157
158 toolchain_library {
159 name: "libclang_rt.fuzzer-i686-android",
160 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900161 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700162 recovery_available: true,
163 src: "",
164 }
165
166 toolchain_library {
167 name: "libclang_rt.fuzzer-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100168 defaults: ["linux_bionic_supported"],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700169 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900170 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700171 recovery_available: true,
172 src: "",
173 }
174
175 toolchain_library {
176 name: "libclang_rt.fuzzer-x86_64",
177 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900178 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700179 recovery_available: true,
180 src: "",
181 }
182
Paul Duffind6867912019-12-19 14:38:36 +0000183 // Needed for sanitizer
184 cc_prebuilt_library_shared {
185 name: "libclang_rt.ubsan_standalone-aarch64-android",
186 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900187 product_available: true,
Paul Duffind6867912019-12-19 14:38:36 +0000188 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800189 system_shared_libs: [],
Paul Duffind6867912019-12-19 14:38:36 +0000190 srcs: [""],
191 }
192
Inseob Kimc0907f12019-02-08 21:00:45 +0900193 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100195 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700196 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900197 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800198 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900199 system_shared_libs: [],
200 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800201 stubs: {
202 versions: ["27", "28", "29"],
203 },
Colin Cross203b4212021-04-26 17:19:41 -0700204 llndk: {
205 symbol_file: "libc.map.txt",
206 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900207 }
208 cc_library {
209 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100210 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700211 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900212 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800213 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900214 system_shared_libs: [],
215 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800216 stubs: {
217 versions: ["27", "28", "29"],
218 },
219 apex_available: [
220 "//apex_available:platform",
221 "myapex"
222 ],
Colin Cross203b4212021-04-26 17:19:41 -0700223 llndk: {
224 symbol_file: "libm.map.txt",
225 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900226 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400227
228 // Coverage libraries
229 cc_library {
230 name: "libprofile-extras",
231 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500232 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900233 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400234 recovery_available: true,
235 native_coverage: false,
236 system_shared_libs: [],
237 stl: "none",
238 notice: "custom_notice",
239 }
240 cc_library {
241 name: "libprofile-clang-extras",
242 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500243 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900244 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400245 recovery_available: true,
246 native_coverage: false,
247 system_shared_libs: [],
248 stl: "none",
249 notice: "custom_notice",
250 }
251 cc_library {
252 name: "libprofile-extras_ndk",
253 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900254 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400255 native_coverage: false,
256 system_shared_libs: [],
257 stl: "none",
258 notice: "custom_notice",
259 sdk_version: "current",
260 }
261 cc_library {
262 name: "libprofile-clang-extras_ndk",
263 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900264 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400265 native_coverage: false,
266 system_shared_libs: [],
267 stl: "none",
268 notice: "custom_notice",
269 sdk_version: "current",
270 }
271
Inseob Kimc0907f12019-02-08 21:00:45 +0900272 cc_library {
273 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100274 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700275 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900276 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800277 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900278 system_shared_libs: [],
279 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800280 stubs: {
281 versions: ["27", "28", "29"],
282 },
283 apex_available: [
284 "//apex_available:platform",
285 "myapex"
286 ],
Colin Cross203b4212021-04-26 17:19:41 -0700287 llndk: {
288 symbol_file: "libdl.map.txt",
289 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900290 }
291 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900292 name: "libft2",
293 no_libcrt: true,
294 nocrt: true,
295 system_shared_libs: [],
296 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700297 llndk: {
298 symbol_file: "libft2.map.txt",
299 private: true,
300 }
Jooyung Han097087b2019-10-22 19:32:18 +0900301 }
302 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900303 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700304 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900305 nocrt: true,
306 system_shared_libs: [],
307 stl: "none",
308 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500309 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900310 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900311 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900312 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900313 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900314 apex_available: [
315 "//apex_available:platform",
316 "//apex_available:anyapex",
317 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900318 }
319 cc_library {
320 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700321 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900322 nocrt: true,
323 system_shared_libs: [],
324 stl: "none",
325 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900326 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900327 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900328 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900329 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900330 vndk: {
331 enabled: true,
332 support_system_process: true,
333 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800334 apex_available: [
335 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500336 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800337 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900338 }
339 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700340 name: "libc++demangle",
341 no_libcrt: true,
342 nocrt: true,
343 system_shared_libs: [],
344 stl: "none",
345 host_supported: false,
346 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500347 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900348 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700349 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900350 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900351 apex_available: [
352 "//apex_available:platform",
353 "//apex_available:anyapex",
354 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700355 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900356
Jiyong Park541142c2020-03-07 16:35:46 +0900357 cc_defaults {
358 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100359 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900360 recovery_available: true,
361 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500362 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900363 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900364 native_bridge_supported: true,
365 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700366 min_sdk_version: "16",
367 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700368 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900369 apex_available: [
370 "//apex_available:platform",
371 "//apex_available:anyapex",
372 ],
373 }
374
Inseob Kimc0907f12019-02-08 21:00:45 +0900375 cc_object {
376 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900377 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900378 }
379
380 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700381 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900382 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700383 }
384
385 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900386 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900387 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900388 }
389
390 cc_object {
391 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900392 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900393 }
394
395 cc_object {
396 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900397 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900398 }
399
400 cc_library {
401 name: "libprotobuf-cpp-lite",
402 }
Colin Crossf28329d2020-02-15 11:00:10 -0800403
404 cc_library {
405 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700406 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800407 stl: "none",
408 system_shared_libs: [],
409 }
410
Dan Albertde5aade2020-06-30 12:32:51 -0700411 ndk_library {
412 name: "libc",
413 first_version: "minimum",
414 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800415 }
416
Dan Albertde5aade2020-06-30 12:32:51 -0700417 ndk_library {
418 name: "libm",
419 first_version: "minimum",
420 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800421 }
422
Dan Albertde5aade2020-06-30 12:32:51 -0700423 ndk_library {
424 name: "libdl",
425 first_version: "minimum",
426 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800427 }
428
Colin Crossf28329d2020-02-15 11:00:10 -0800429 ndk_prebuilt_shared_stl {
430 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700431 export_include_dirs: ["ndk_libc++_shared"],
432 }
433
434 ndk_prebuilt_static_stl {
435 name: "ndk_libandroid_support",
436 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800437 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900438
439 cc_library_static {
440 name: "libgoogle-benchmark",
441 sdk_version: "current",
442 stl: "none",
443 system_shared_libs: [],
444 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700445
446 cc_library_static {
447 name: "note_memtag_heap_async",
448 }
449
450 cc_library_static {
451 name: "note_memtag_heap_sync",
452 }
Colin Cross528d67e2021-07-23 22:23:07 +0000453
454
455 cc_library {
456 name: "libjemalloc5",
457 host_supported: true,
458 no_libcrt: true,
459 nocrt: true,
460 system_shared_libs: [],
461 stl: "none",
462 }
463
464 cc_library {
465 name: "libc_musl",
466 host_supported: true,
467 no_libcrt: true,
468 nocrt: true,
469 system_shared_libs: [],
470 stl: "none",
471 }
Colin Crossf28329d2020-02-15 11:00:10 -0800472 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000473}
Colin Crossf28329d2020-02-15 11:00:10 -0800474
Paul Duffin02a3d652021-02-24 18:51:54 +0000475func withWindowsModules() string {
476 return `
Paul Duffina04c1072020-03-02 10:16:35 +0000477 toolchain_library {
478 name: "libwinpthread",
479 host_supported: true,
480 enabled: false,
481 target: {
482 windows: {
483 enabled: true,
484 },
485 },
486 src: "",
487 }
488 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000489}
490
Paul Duffin02a3d652021-02-24 18:51:54 +0000491func withLinuxBionic() string {
492 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100493 cc_binary {
494 name: "linker",
495 defaults: ["linux_bionic_supported"],
496 recovery_available: true,
497 stl: "none",
498 nocrt: true,
499 static_executable: true,
500 native_coverage: false,
501 system_shared_libs: [],
502 }
503
504 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700505 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100506 host_supported: true,
507 device_supported: false,
508 target: {
509 host: {
510 enabled: false,
511 },
512 linux_bionic: {
513 enabled: true,
514 },
515 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700516 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100517 }
518
519 cc_defaults {
520 name: "linux_bionic_supported",
521 host_supported: true,
522 target: {
523 host: {
524 enabled: false,
525 },
526 linux_bionic: {
527 enabled: true,
528 },
529 },
530 }
531 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000532}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100533
Paul Duffin02a3d652021-02-24 18:51:54 +0000534func withoutLinuxBionic() string {
535 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100536 cc_defaults {
537 name: "linux_bionic_supported",
538 }
539 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900540}
Colin Cross9a942872019-05-14 15:44:26 -0700541
Colin Crossf28329d2020-02-15 11:00:10 -0800542func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800543}
544
Paul Duffin02a3d652021-02-24 18:51:54 +0000545// The directory in which cc linux bionic default modules will be defined.
546//
547// Placing them here ensures that their location does not conflict with default test modules
548// defined by other packages.
549const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
550
551// The directory in which the default cc common test modules will be defined.
552//
553// Placing them here ensures that their location does not conflict with default test modules
554// defined by other packages.
555const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
556
557// Test fixture preparer that will register most cc build components.
558//
559// Singletons and mutators should only be added here if they are needed for a majority of cc
560// module types, otherwise they should be added under a separate preparer to allow them to be
561// selected only when needed to reduce test execution time.
562//
563// Module types do not have much of an overhead unless they are used so this should include as many
564// module types as possible. The exceptions are those module types that require mutators and/or
565// singletons in order to function in which case they should be kept together in a separate
566// preparer.
567var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
568 android.PrepareForTestWithAndroidBuildComponents,
569 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
570 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
571 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
572 ctx.RegisterModuleType("cc_test", TestFactory)
573 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000574 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
575
576 RegisterVndkLibraryTxtTypes(ctx)
577 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000578
579 // Additional files needed in tests that disallow non-existent source files.
580 // This includes files that are needed by all, or at least most, instances of a cc module type.
581 android.MockFS{
582 // Needed for ndk_prebuilt_(shared|static)_stl.
583 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
584 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000585)
586
587// Preparer that will define default cc modules, e.g. standard prebuilt modules.
588var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
589 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000590
591 // Additional files needed in tests that disallow non-existent source.
592 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700593 "defaults/cc/common/libc.map.txt": nil,
594 "defaults/cc/common/libdl.map.txt": nil,
595 "defaults/cc/common/libm.map.txt": nil,
596 "defaults/cc/common/ndk_libandroid_support": nil,
597 "defaults/cc/common/ndk_libc++_shared": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000598 }.AddToFixture(),
599
Paul Duffin02a3d652021-02-24 18:51:54 +0000600 // Place the default cc test modules that are common to all platforms in a location that will not
601 // conflict with default test modules defined by other packages.
602 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
603 // Disable linux bionic by default.
604 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
605)
606
607// Prepare a fixture to use all cc module types, mutators and singletons fully.
608//
609// This should only be used by tests that want to run with as much of the build enabled as possible.
610var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
611 android.PrepareForIntegrationTestWithAndroid,
612 genrule.PrepareForIntegrationTestWithGenrule,
613 PrepareForTestWithCcDefaultModules,
614)
615
616// The preparer to include if running a cc related test for windows.
617var PrepareForTestOnWindows = android.GroupFixturePreparers(
618 // Place the default cc test modules for windows platforms in a location that will not conflict
619 // with default test modules defined by other packages.
620 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
621)
622
623// The preparer to include if running a cc related test for linux bionic.
624var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000625 // Enable linux bionic
626 //
627 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
628 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
629 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000630)
631
632// This adds some additional modules and singletons which might negatively impact the performance
633// of tests so they are not included in the PrepareForIntegrationTestWithCc.
634var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
635 PrepareForIntegrationTestWithCc,
636 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900637 snapshot.VendorSnapshotImageSingleton.Init(ctx)
638 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
639 RegisterVendorSnapshotModules(ctx)
640 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000641 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
642 }),
643)
644
645// TestConfig is the legacy way of creating a test Config for testing cc modules.
646//
647// See testCc for an explanation as to how to stop using this deprecated method.
648//
649// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800650func TestConfig(buildDir string, os android.OsType, env map[string]string,
651 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700652
Colin Cross98be1bb2019-12-13 20:41:13 -0800653 // add some modules that are required by the compiler and/or linker
654 bp = bp + GatherRequiredDepsForTest(os)
655
Colin Cross2fce23a2020-06-07 17:02:48 -0700656 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800657
Colin Crossf28329d2020-02-15 11:00:10 -0800658 GatherRequiredFilesForTest(mockFS)
659
Colin Cross98be1bb2019-12-13 20:41:13 -0800660 for k, v := range fs {
661 mockFS[k] = v
662 }
663
Colin Crosscb0ac952021-07-20 13:17:15 -0700664 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800665}
666
Paul Duffin02a3d652021-02-24 18:51:54 +0000667// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
668//
669// See testCc for an explanation as to how to stop using this deprecated method.
670//
671// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700672func CreateTestContext(config android.Config) *android.TestContext {
673 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000674 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800675 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800676 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400677 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800678 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
679 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000680
Kiyoung Kim48f37782021-07-07 12:42:39 +0900681 snapshot.VendorSnapshotImageSingleton.Init(ctx)
682 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
683 RegisterVendorSnapshotModules(ctx)
684 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000685 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800686 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000687
Colin Crosse1bb5d02019-09-24 14:55:04 -0700688 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100689 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100690 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700691
Colin Cross9a942872019-05-14 15:44:26 -0700692 return ctx
693}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400694
695func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
696 t.Helper()
697 mod := ctx.ModuleForTests(moduleName, variant)
698 outputFiles := mod.OutputFiles(t, "")
699 if len(outputFiles) != 1 {
700 t.Errorf("%q must have single output\n", moduleName)
701 return
702 }
703 snapshotPath := filepath.Join(subDir, snapshotFilename)
704
705 if include {
706 out := singleton.Output(snapshotPath)
707 if fake {
708 if out.Rule == nil {
709 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
710 }
711 } else {
712 if out.Input.String() != outputFiles[0].String() {
713 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
714 }
715 }
716 } else {
717 out := singleton.MaybeOutput(snapshotPath)
718 if out.Rule != nil {
719 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
720 }
721 }
722}
723
724func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
725 t.Helper()
726 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
727}
728
729func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
730 t.Helper()
731 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
732}
733
734func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
735 t.Helper()
736 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
737}
738
739func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
740 t.Helper()
741 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
742 if m.ExcludeFromVendorSnapshot() != expected {
743 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
744 }
745}
746
747func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
748 for _, moduleName := range moduleNames {
749 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
750 output := module.outputFile.Path().RelativeToTop()
751 paths = append(paths, output)
752 }
753 return paths
754}