blob: c549b5dcc824023940b348fb4ed84ec0f9bdfb2c [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"
Inseob Kimc0907f12019-02-08 21:00:45 +090023)
24
Paul Duffin77980a82019-12-19 16:01:36 +000025func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000026 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000027 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000028 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000029 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000030 RegisterLibraryHeadersBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000031
32 ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
Jiyong Park46a512f2020-12-04 18:02:13 +090033 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000034 ctx.RegisterModuleType("cc_object", ObjectFactory)
Martin Stjernholm7feceb22020-07-11 04:33:29 +010035 ctx.RegisterModuleType("cc_genrule", genRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080036 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070037 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080038 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070039 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000040}
41
Paul Duffina04c1072020-03-02 10:16:35 +000042func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000043 ret := commonDefaultModules()
44
45 supportLinuxBionic := false
46 for _, os := range oses {
47 if os == android.Fuchsia {
48 ret += withFuchsiaModules()
49 }
50 if os == android.Windows {
51 ret += withWindowsModules()
52 }
53 if os == android.LinuxBionic {
54 supportLinuxBionic = true
55 ret += withLinuxBionic()
56 }
57 }
58
59 if !supportLinuxBionic {
60 ret += withoutLinuxBionic()
61 }
62
63 return ret
64}
65
66func commonDefaultModules() string {
67 return `
Inseob Kimc0907f12019-02-08 21:00:45 +090068 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +090069 name: "libcompiler_rt-extras",
70 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050071 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090072 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090073 recovery_available: true,
74 src: "",
75 }
76
77 toolchain_library {
78 name: "libclang_rt.builtins-arm-android",
79 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050080 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090081 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090082 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080083 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090084 src: "",
85 }
86
87 toolchain_library {
88 name: "libclang_rt.builtins-aarch64-android",
89 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050090 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090091 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090092 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080093 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090094 src: "",
95 }
96
Jooyung Han75568392020-03-20 04:29:24 +090097 cc_prebuilt_library_shared {
98 name: "libclang_rt.hwasan-aarch64-android",
99 nocrt: true,
100 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900101 product_available: true,
Jooyung Han75568392020-03-20 04:29:24 +0900102 recovery_available: true,
103 system_shared_libs: [],
104 stl: "none",
105 srcs: [""],
106 check_elf_files: false,
107 sanitize: {
108 never: true,
109 },
110 }
111
Inseob Kimc0907f12019-02-08 21:00:45 +0900112 toolchain_library {
113 name: "libclang_rt.builtins-i686-android",
114 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500115 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900116 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900117 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800118 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900119 src: "",
120 }
121
122 toolchain_library {
123 name: "libclang_rt.builtins-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100124 defaults: ["linux_bionic_supported"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900125 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500126 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900127 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900128 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800129 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900130 src: "",
131 }
132
133 toolchain_library {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800134 name: "libunwind",
135 defaults: ["linux_bionic_supported"],
136 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500137 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800138 product_available: true,
139 recovery_available: true,
140 native_bridge_supported: true,
141 src: "",
142 }
143
144 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700145 name: "libclang_rt.fuzzer-arm-android",
146 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900147 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700148 recovery_available: true,
149 src: "",
150 }
151
152 toolchain_library {
153 name: "libclang_rt.fuzzer-aarch64-android",
154 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900155 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700156 recovery_available: true,
157 src: "",
158 }
159
160 toolchain_library {
161 name: "libclang_rt.fuzzer-i686-android",
162 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900163 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700164 recovery_available: true,
165 src: "",
166 }
167
168 toolchain_library {
169 name: "libclang_rt.fuzzer-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100170 defaults: ["linux_bionic_supported"],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700171 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900172 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700173 recovery_available: true,
174 src: "",
175 }
176
177 toolchain_library {
178 name: "libclang_rt.fuzzer-x86_64",
179 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900180 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700181 recovery_available: true,
182 src: "",
183 }
184
Paul Duffind6867912019-12-19 14:38:36 +0000185 // Needed for sanitizer
186 cc_prebuilt_library_shared {
187 name: "libclang_rt.ubsan_standalone-aarch64-android",
188 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900189 product_available: true,
Paul Duffind6867912019-12-19 14:38:36 +0000190 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800191 system_shared_libs: [],
Paul Duffind6867912019-12-19 14:38:36 +0000192 srcs: [""],
193 }
194
Inseob Kimc0907f12019-02-08 21:00:45 +0900195 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900196 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100197 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700198 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900199 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800200 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900201 system_shared_libs: [],
202 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800203 stubs: {
204 versions: ["27", "28", "29"],
205 },
Colin Cross203b4212021-04-26 17:19:41 -0700206 llndk: {
207 symbol_file: "libc.map.txt",
208 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900209 }
210 cc_library {
211 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100212 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700213 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900214 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800215 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900216 system_shared_libs: [],
217 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800218 stubs: {
219 versions: ["27", "28", "29"],
220 },
221 apex_available: [
222 "//apex_available:platform",
223 "myapex"
224 ],
Colin Cross203b4212021-04-26 17:19:41 -0700225 llndk: {
226 symbol_file: "libm.map.txt",
227 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900228 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400229
230 // Coverage libraries
231 cc_library {
232 name: "libprofile-extras",
233 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500234 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900235 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400236 recovery_available: true,
237 native_coverage: false,
238 system_shared_libs: [],
239 stl: "none",
240 notice: "custom_notice",
241 }
242 cc_library {
243 name: "libprofile-clang-extras",
244 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500245 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900246 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400247 recovery_available: true,
248 native_coverage: false,
249 system_shared_libs: [],
250 stl: "none",
251 notice: "custom_notice",
252 }
253 cc_library {
254 name: "libprofile-extras_ndk",
255 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900256 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400257 native_coverage: false,
258 system_shared_libs: [],
259 stl: "none",
260 notice: "custom_notice",
261 sdk_version: "current",
262 }
263 cc_library {
264 name: "libprofile-clang-extras_ndk",
265 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900266 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400267 native_coverage: false,
268 system_shared_libs: [],
269 stl: "none",
270 notice: "custom_notice",
271 sdk_version: "current",
272 }
273
Inseob Kimc0907f12019-02-08 21:00:45 +0900274 cc_library {
275 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100276 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700277 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900278 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800279 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900280 system_shared_libs: [],
281 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800282 stubs: {
283 versions: ["27", "28", "29"],
284 },
285 apex_available: [
286 "//apex_available:platform",
287 "myapex"
288 ],
Colin Cross203b4212021-04-26 17:19:41 -0700289 llndk: {
290 symbol_file: "libdl.map.txt",
291 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900292 }
293 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900294 name: "libft2",
295 no_libcrt: true,
296 nocrt: true,
297 system_shared_libs: [],
298 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700299 llndk: {
300 symbol_file: "libft2.map.txt",
301 private: true,
302 }
Jooyung Han097087b2019-10-22 19:32:18 +0900303 }
304 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900305 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700306 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 nocrt: true,
308 system_shared_libs: [],
309 stl: "none",
310 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500311 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900312 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900313 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900314 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900315 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900316 apex_available: [
317 "//apex_available:platform",
318 "//apex_available:anyapex",
319 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900320 }
321 cc_library {
322 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700323 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900324 nocrt: true,
325 system_shared_libs: [],
326 stl: "none",
327 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900328 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900329 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900330 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900331 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900332 vndk: {
333 enabled: true,
334 support_system_process: true,
335 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800336 apex_available: [
337 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500338 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800339 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900340 }
341 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700342 name: "libc++demangle",
343 no_libcrt: true,
344 nocrt: true,
345 system_shared_libs: [],
346 stl: "none",
347 host_supported: false,
348 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500349 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900350 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700351 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900352 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900353 apex_available: [
354 "//apex_available:platform",
355 "//apex_available:anyapex",
356 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700357 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900358
Jiyong Park541142c2020-03-07 16:35:46 +0900359 cc_defaults {
360 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100361 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900362 recovery_available: true,
363 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500364 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900365 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900366 native_bridge_supported: true,
367 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700368 min_sdk_version: "16",
369 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700370 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900371 apex_available: [
372 "//apex_available:platform",
373 "//apex_available:anyapex",
374 ],
375 }
376
Inseob Kimc0907f12019-02-08 21:00:45 +0900377 cc_object {
378 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900379 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900380 }
381
382 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700383 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900384 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700385 }
386
387 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900388 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900389 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900390 }
391
392 cc_object {
393 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900394 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900395 }
396
397 cc_object {
398 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900399 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900400 }
401
402 cc_library {
403 name: "libprotobuf-cpp-lite",
404 }
Colin Crossf28329d2020-02-15 11:00:10 -0800405
406 cc_library {
407 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700408 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800409 stl: "none",
410 system_shared_libs: [],
411 }
412
Dan Albertde5aade2020-06-30 12:32:51 -0700413 ndk_library {
414 name: "libc",
415 first_version: "minimum",
416 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800417 }
418
Dan Albertde5aade2020-06-30 12:32:51 -0700419 ndk_library {
420 name: "libm",
421 first_version: "minimum",
422 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800423 }
424
Dan Albertde5aade2020-06-30 12:32:51 -0700425 ndk_library {
426 name: "libdl",
427 first_version: "minimum",
428 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800429 }
430
Colin Crossf28329d2020-02-15 11:00:10 -0800431 ndk_prebuilt_shared_stl {
432 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700433 export_include_dirs: ["ndk_libc++_shared"],
434 }
435
436 ndk_prebuilt_static_stl {
437 name: "ndk_libandroid_support",
438 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800439 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900440
441 cc_library_static {
442 name: "libgoogle-benchmark",
443 sdk_version: "current",
444 stl: "none",
445 system_shared_libs: [],
446 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700447
448 cc_library_static {
449 name: "note_memtag_heap_async",
450 }
451
452 cc_library_static {
453 name: "note_memtag_heap_sync",
454 }
Colin Crossf28329d2020-02-15 11:00:10 -0800455 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000456}
Colin Crossf28329d2020-02-15 11:00:10 -0800457
Paul Duffin02a3d652021-02-24 18:51:54 +0000458func withWindowsModules() string {
459 return `
Paul Duffina04c1072020-03-02 10:16:35 +0000460 toolchain_library {
461 name: "libwinpthread",
462 host_supported: true,
463 enabled: false,
464 target: {
465 windows: {
466 enabled: true,
467 },
468 },
469 src: "",
470 }
471 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000472}
473
474func withFuchsiaModules() string {
475 return `
476 cc_library {
477 name: "libbioniccompat",
478 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000479 }
Paul Duffin02a3d652021-02-24 18:51:54 +0000480 cc_library {
481 name: "libcompiler_rt",
482 stl: "none",
483 }
484 `
485}
486
487func withLinuxBionic() string {
488 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100489 cc_binary {
490 name: "linker",
491 defaults: ["linux_bionic_supported"],
492 recovery_available: true,
493 stl: "none",
494 nocrt: true,
495 static_executable: true,
496 native_coverage: false,
497 system_shared_libs: [],
498 }
499
500 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700501 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100502 host_supported: true,
503 device_supported: false,
504 target: {
505 host: {
506 enabled: false,
507 },
508 linux_bionic: {
509 enabled: true,
510 },
511 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700512 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100513 }
514
515 cc_defaults {
516 name: "linux_bionic_supported",
517 host_supported: true,
518 target: {
519 host: {
520 enabled: false,
521 },
522 linux_bionic: {
523 enabled: true,
524 },
525 },
526 }
527 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000528}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100529
Paul Duffin02a3d652021-02-24 18:51:54 +0000530func withoutLinuxBionic() string {
531 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100532 cc_defaults {
533 name: "linux_bionic_supported",
534 }
535 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900536}
Colin Cross9a942872019-05-14 15:44:26 -0700537
Colin Crossf28329d2020-02-15 11:00:10 -0800538func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800539}
540
Paul Duffin02a3d652021-02-24 18:51:54 +0000541// The directory in which cc linux bionic default modules will be defined.
542//
543// Placing them here ensures that their location does not conflict with default test modules
544// defined by other packages.
545const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
546
547// The directory in which the default cc common test modules will be defined.
548//
549// Placing them here ensures that their location does not conflict with default test modules
550// defined by other packages.
551const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
552
553// Test fixture preparer that will register most cc build components.
554//
555// Singletons and mutators should only be added here if they are needed for a majority of cc
556// module types, otherwise they should be added under a separate preparer to allow them to be
557// selected only when needed to reduce test execution time.
558//
559// Module types do not have much of an overhead unless they are used so this should include as many
560// module types as possible. The exceptions are those module types that require mutators and/or
561// singletons in order to function in which case they should be kept together in a separate
562// preparer.
563var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
564 android.PrepareForTestWithAndroidBuildComponents,
565 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
566 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
567 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
568 ctx.RegisterModuleType("cc_test", TestFactory)
569 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000570 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
571
572 RegisterVndkLibraryTxtTypes(ctx)
573 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000574
575 // Additional files needed in tests that disallow non-existent source files.
576 // This includes files that are needed by all, or at least most, instances of a cc module type.
577 android.MockFS{
578 // Needed for ndk_prebuilt_(shared|static)_stl.
579 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
580 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000581)
582
583// Preparer that will define default cc modules, e.g. standard prebuilt modules.
584var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
585 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000586
587 // Additional files needed in tests that disallow non-existent source.
588 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700589 "defaults/cc/common/libc.map.txt": nil,
590 "defaults/cc/common/libdl.map.txt": nil,
591 "defaults/cc/common/libm.map.txt": nil,
592 "defaults/cc/common/ndk_libandroid_support": nil,
593 "defaults/cc/common/ndk_libc++_shared": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000594 }.AddToFixture(),
595
Paul Duffin02a3d652021-02-24 18:51:54 +0000596 // Place the default cc test modules that are common to all platforms in a location that will not
597 // conflict with default test modules defined by other packages.
598 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
599 // Disable linux bionic by default.
600 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
601)
602
603// Prepare a fixture to use all cc module types, mutators and singletons fully.
604//
605// This should only be used by tests that want to run with as much of the build enabled as possible.
606var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
607 android.PrepareForIntegrationTestWithAndroid,
608 genrule.PrepareForIntegrationTestWithGenrule,
609 PrepareForTestWithCcDefaultModules,
610)
611
612// The preparer to include if running a cc related test for windows.
613var PrepareForTestOnWindows = android.GroupFixturePreparers(
614 // Place the default cc test modules for windows platforms in a location that will not conflict
615 // with default test modules defined by other packages.
616 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
617)
618
619// The preparer to include if running a cc related test for linux bionic.
620var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000621 // Enable linux bionic
622 //
623 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
624 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
625 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000626)
627
Paul Duffinecdac8a2021-02-24 19:18:42 +0000628// The preparer to include if running a cc related test for fuchsia.
629var PrepareForTestOnFuchsia = android.GroupFixturePreparers(
630 // Place the default cc test modules for fuschia in a location that will not conflict with default
631 // test modules defined by other packages.
632 android.FixtureAddTextFile("defaults/cc/fuschia/Android.bp", withFuchsiaModules()),
633 android.PrepareForTestSetDeviceToFuchsia,
634)
635
Paul Duffin02a3d652021-02-24 18:51:54 +0000636// This adds some additional modules and singletons which might negatively impact the performance
637// of tests so they are not included in the PrepareForIntegrationTestWithCc.
638var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
639 PrepareForIntegrationTestWithCc,
640 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400641 VendorSnapshotImageSingleton.Init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000642 recoverySnapshotImageSingleton.init(ctx)
643 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
644 }),
645)
646
647// TestConfig is the legacy way of creating a test Config for testing cc modules.
648//
649// See testCc for an explanation as to how to stop using this deprecated method.
650//
651// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800652func TestConfig(buildDir string, os android.OsType, env map[string]string,
653 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700654
Colin Cross98be1bb2019-12-13 20:41:13 -0800655 // add some modules that are required by the compiler and/or linker
656 bp = bp + GatherRequiredDepsForTest(os)
657
Colin Cross2fce23a2020-06-07 17:02:48 -0700658 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800659
Colin Crossf28329d2020-02-15 11:00:10 -0800660 GatherRequiredFilesForTest(mockFS)
661
Colin Cross98be1bb2019-12-13 20:41:13 -0800662 for k, v := range fs {
663 mockFS[k] = v
664 }
665
666 var config android.Config
667 if os == android.Fuchsia {
Paul Duffinecdac8a2021-02-24 19:18:42 +0000668 panic("Fuchsia not supported use test fixture instead")
Colin Cross98be1bb2019-12-13 20:41:13 -0800669 } else {
670 config = android.TestArchConfig(buildDir, env, bp, mockFS)
671 }
672
673 return config
674}
675
Paul Duffin02a3d652021-02-24 18:51:54 +0000676// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
677//
678// See testCc for an explanation as to how to stop using this deprecated method.
679//
680// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700681func CreateTestContext(config android.Config) *android.TestContext {
682 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000683 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800684 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800685 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400686 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800687 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
688 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000689
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400690 VendorSnapshotImageSingleton.Init(ctx)
Colin Crosse0edaf92021-01-11 17:31:17 -0800691 recoverySnapshotImageSingleton.init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000692 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800693 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000694
Colin Crosse1bb5d02019-09-24 14:55:04 -0700695 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100696 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100697 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700698
Colin Cross9a942872019-05-14 15:44:26 -0700699 return ctx
700}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400701
702func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
703 t.Helper()
704 mod := ctx.ModuleForTests(moduleName, variant)
705 outputFiles := mod.OutputFiles(t, "")
706 if len(outputFiles) != 1 {
707 t.Errorf("%q must have single output\n", moduleName)
708 return
709 }
710 snapshotPath := filepath.Join(subDir, snapshotFilename)
711
712 if include {
713 out := singleton.Output(snapshotPath)
714 if fake {
715 if out.Rule == nil {
716 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
717 }
718 } else {
719 if out.Input.String() != outputFiles[0].String() {
720 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
721 }
722 }
723 } else {
724 out := singleton.MaybeOutput(snapshotPath)
725 if out.Rule != nil {
726 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
727 }
728 }
729}
730
731func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
732 t.Helper()
733 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
734}
735
736func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
737 t.Helper()
738 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
739}
740
741func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
742 t.Helper()
743 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
744}
745
746func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
747 t.Helper()
748 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
749 if m.ExcludeFromVendorSnapshot() != expected {
750 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
751 }
752}
753
754func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
755 for _, moduleName := range moduleNames {
756 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
757 output := module.outputFile.Path().RelativeToTop()
758 paths = append(paths, output)
759 }
760 return paths
761}