blob: fb9dc9c1b142347ac4e7f65885d552b1fe027769 [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,
Jiyong Park541142c2020-03-07 16:35:46 +0900370 apex_available: [
371 "//apex_available:platform",
372 "//apex_available:anyapex",
373 ],
374 }
375
Inseob Kimc0907f12019-02-08 21:00:45 +0900376 cc_object {
377 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900378 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900379 }
380
381 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700382 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900383 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700384 }
385
386 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900387 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900388 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900389 }
390
391 cc_object {
392 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900393 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900394 }
395
396 cc_object {
397 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900398 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900399 }
400
401 cc_library {
402 name: "libprotobuf-cpp-lite",
403 }
Colin Crossf28329d2020-02-15 11:00:10 -0800404
405 cc_library {
406 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700407 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800408 stl: "none",
409 system_shared_libs: [],
410 }
411
Dan Albertde5aade2020-06-30 12:32:51 -0700412 ndk_library {
413 name: "libc",
414 first_version: "minimum",
415 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800416 }
417
Dan Albertde5aade2020-06-30 12:32:51 -0700418 ndk_library {
419 name: "libm",
420 first_version: "minimum",
421 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800422 }
423
Dan Albertde5aade2020-06-30 12:32:51 -0700424 ndk_library {
425 name: "libdl",
426 first_version: "minimum",
427 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800428 }
429
Colin Crossf28329d2020-02-15 11:00:10 -0800430 ndk_prebuilt_shared_stl {
431 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700432 export_include_dirs: ["ndk_libc++_shared"],
433 }
434
435 ndk_prebuilt_static_stl {
436 name: "ndk_libandroid_support",
437 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800438 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900439
440 cc_library_static {
441 name: "libgoogle-benchmark",
442 sdk_version: "current",
443 stl: "none",
444 system_shared_libs: [],
445 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700446
447 cc_library_static {
448 name: "note_memtag_heap_async",
449 }
450
451 cc_library_static {
452 name: "note_memtag_heap_sync",
453 }
Colin Crossf28329d2020-02-15 11:00:10 -0800454 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000455}
Colin Crossf28329d2020-02-15 11:00:10 -0800456
Paul Duffin02a3d652021-02-24 18:51:54 +0000457func withWindowsModules() string {
458 return `
Paul Duffina04c1072020-03-02 10:16:35 +0000459 toolchain_library {
460 name: "libwinpthread",
461 host_supported: true,
462 enabled: false,
463 target: {
464 windows: {
465 enabled: true,
466 },
467 },
468 src: "",
469 }
470 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000471}
472
473func withFuchsiaModules() string {
474 return `
475 cc_library {
476 name: "libbioniccompat",
477 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000478 }
Paul Duffin02a3d652021-02-24 18:51:54 +0000479 cc_library {
480 name: "libcompiler_rt",
481 stl: "none",
482 }
483 `
484}
485
486func withLinuxBionic() string {
487 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100488 cc_binary {
489 name: "linker",
490 defaults: ["linux_bionic_supported"],
491 recovery_available: true,
492 stl: "none",
493 nocrt: true,
494 static_executable: true,
495 native_coverage: false,
496 system_shared_libs: [],
497 }
498
499 cc_genrule {
500 name: "host_bionic_linker_flags",
501 host_supported: true,
502 device_supported: false,
503 target: {
504 host: {
505 enabled: false,
506 },
507 linux_bionic: {
508 enabled: true,
509 },
510 },
511 out: ["linker.flags"],
512 }
513
514 cc_defaults {
515 name: "linux_bionic_supported",
516 host_supported: true,
517 target: {
518 host: {
519 enabled: false,
520 },
521 linux_bionic: {
522 enabled: true,
523 },
524 },
525 }
526 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000527}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100528
Paul Duffin02a3d652021-02-24 18:51:54 +0000529func withoutLinuxBionic() string {
530 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100531 cc_defaults {
532 name: "linux_bionic_supported",
533 }
534 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900535}
Colin Cross9a942872019-05-14 15:44:26 -0700536
Colin Crossf28329d2020-02-15 11:00:10 -0800537func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800538}
539
Paul Duffin02a3d652021-02-24 18:51:54 +0000540// The directory in which cc linux bionic default modules will be defined.
541//
542// Placing them here ensures that their location does not conflict with default test modules
543// defined by other packages.
544const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
545
546// The directory in which the default cc common test modules will be defined.
547//
548// Placing them here ensures that their location does not conflict with default test modules
549// defined by other packages.
550const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
551
552// Test fixture preparer that will register most cc build components.
553//
554// Singletons and mutators should only be added here if they are needed for a majority of cc
555// module types, otherwise they should be added under a separate preparer to allow them to be
556// selected only when needed to reduce test execution time.
557//
558// Module types do not have much of an overhead unless they are used so this should include as many
559// module types as possible. The exceptions are those module types that require mutators and/or
560// singletons in order to function in which case they should be kept together in a separate
561// preparer.
562var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
563 android.PrepareForTestWithAndroidBuildComponents,
564 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
565 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
566 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
567 ctx.RegisterModuleType("cc_test", TestFactory)
568 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000569 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
570
571 RegisterVndkLibraryTxtTypes(ctx)
572 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000573
574 // Additional files needed in tests that disallow non-existent source files.
575 // This includes files that are needed by all, or at least most, instances of a cc module type.
576 android.MockFS{
577 // Needed for ndk_prebuilt_(shared|static)_stl.
578 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
579 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000580)
581
582// Preparer that will define default cc modules, e.g. standard prebuilt modules.
583var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
584 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000585
586 // Additional files needed in tests that disallow non-existent source.
587 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700588 "defaults/cc/common/libc.map.txt": nil,
589 "defaults/cc/common/libdl.map.txt": nil,
590 "defaults/cc/common/libm.map.txt": nil,
591 "defaults/cc/common/ndk_libandroid_support": nil,
592 "defaults/cc/common/ndk_libc++_shared": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000593 }.AddToFixture(),
594
Paul Duffin02a3d652021-02-24 18:51:54 +0000595 // Place the default cc test modules that are common to all platforms in a location that will not
596 // conflict with default test modules defined by other packages.
597 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
598 // Disable linux bionic by default.
599 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
600)
601
602// Prepare a fixture to use all cc module types, mutators and singletons fully.
603//
604// This should only be used by tests that want to run with as much of the build enabled as possible.
605var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
606 android.PrepareForIntegrationTestWithAndroid,
607 genrule.PrepareForIntegrationTestWithGenrule,
608 PrepareForTestWithCcDefaultModules,
609)
610
611// The preparer to include if running a cc related test for windows.
612var PrepareForTestOnWindows = android.GroupFixturePreparers(
613 // Place the default cc test modules for windows platforms in a location that will not conflict
614 // with default test modules defined by other packages.
615 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
616)
617
618// The preparer to include if running a cc related test for linux bionic.
619var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000620 // Enable linux bionic
621 //
622 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
623 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
624 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000625)
626
Paul Duffinecdac8a2021-02-24 19:18:42 +0000627// The preparer to include if running a cc related test for fuchsia.
628var PrepareForTestOnFuchsia = android.GroupFixturePreparers(
629 // Place the default cc test modules for fuschia in a location that will not conflict with default
630 // test modules defined by other packages.
631 android.FixtureAddTextFile("defaults/cc/fuschia/Android.bp", withFuchsiaModules()),
632 android.PrepareForTestSetDeviceToFuchsia,
633)
634
Paul Duffin02a3d652021-02-24 18:51:54 +0000635// This adds some additional modules and singletons which might negatively impact the performance
636// of tests so they are not included in the PrepareForIntegrationTestWithCc.
637var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
638 PrepareForIntegrationTestWithCc,
639 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400640 VendorSnapshotImageSingleton.Init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000641 recoverySnapshotImageSingleton.init(ctx)
642 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
643 }),
644)
645
646// TestConfig is the legacy way of creating a test Config for testing cc modules.
647//
648// See testCc for an explanation as to how to stop using this deprecated method.
649//
650// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800651func TestConfig(buildDir string, os android.OsType, env map[string]string,
652 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700653
Colin Cross98be1bb2019-12-13 20:41:13 -0800654 // add some modules that are required by the compiler and/or linker
655 bp = bp + GatherRequiredDepsForTest(os)
656
Colin Cross2fce23a2020-06-07 17:02:48 -0700657 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800658
Colin Crossf28329d2020-02-15 11:00:10 -0800659 GatherRequiredFilesForTest(mockFS)
660
Colin Cross98be1bb2019-12-13 20:41:13 -0800661 for k, v := range fs {
662 mockFS[k] = v
663 }
664
665 var config android.Config
666 if os == android.Fuchsia {
Paul Duffinecdac8a2021-02-24 19:18:42 +0000667 panic("Fuchsia not supported use test fixture instead")
Colin Cross98be1bb2019-12-13 20:41:13 -0800668 } else {
669 config = android.TestArchConfig(buildDir, env, bp, mockFS)
670 }
671
672 return config
673}
674
Paul Duffin02a3d652021-02-24 18:51:54 +0000675// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
676//
677// See testCc for an explanation as to how to stop using this deprecated method.
678//
679// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700680func CreateTestContext(config android.Config) *android.TestContext {
681 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000682 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800683 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800684 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400685 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800686 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
687 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000688
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400689 VendorSnapshotImageSingleton.Init(ctx)
Colin Crosse0edaf92021-01-11 17:31:17 -0800690 recoverySnapshotImageSingleton.init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000691 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800692 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000693
Colin Crosse1bb5d02019-09-24 14:55:04 -0700694 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100695 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100696 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700697
Colin Cross9a942872019-05-14 15:44:26 -0700698 return ctx
699}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400700
701func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
702 t.Helper()
703 mod := ctx.ModuleForTests(moduleName, variant)
704 outputFiles := mod.OutputFiles(t, "")
705 if len(outputFiles) != 1 {
706 t.Errorf("%q must have single output\n", moduleName)
707 return
708 }
709 snapshotPath := filepath.Join(subDir, snapshotFilename)
710
711 if include {
712 out := singleton.Output(snapshotPath)
713 if fake {
714 if out.Rule == nil {
715 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
716 }
717 } else {
718 if out.Input.String() != outputFiles[0].String() {
719 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
720 }
721 }
722 } else {
723 out := singleton.MaybeOutput(snapshotPath)
724 if out.Rule != nil {
725 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
726 }
727 }
728}
729
730func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
731 t.Helper()
732 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
733}
734
735func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
736 t.Helper()
737 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
738}
739
740func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
741 t.Helper()
742 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
743}
744
745func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
746 t.Helper()
747 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
748 if m.ExcludeFromVendorSnapshot() != expected {
749 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
750 }
751}
752
753func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
754 for _, moduleName := range moduleNames {
755 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
756 output := module.outputFile.Path().RelativeToTop()
757 paths = append(paths, output)
758 }
759 return paths
760}