blob: ff32bfffd77c8a1576d096be1c13733cd39c35ef [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 (
18 "android/soong/android"
Colin Crosse9fe2942020-11-10 18:12:15 -080019 "android/soong/genrule"
Inseob Kimc0907f12019-02-08 21:00:45 +090020)
21
Paul Duffin77980a82019-12-19 16:01:36 +000022func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000023 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000024 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000025 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000026 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000027 RegisterLibraryHeadersBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000028
29 ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
30 ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)
Jiyong Park46a512f2020-12-04 18:02:13 +090031 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000032 ctx.RegisterModuleType("cc_object", ObjectFactory)
Martin Stjernholm7feceb22020-07-11 04:33:29 +010033 ctx.RegisterModuleType("cc_genrule", genRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080034 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
35 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070036 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000037}
38
Paul Duffina04c1072020-03-02 10:16:35 +000039func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000040 ret := commonDefaultModules()
41
42 supportLinuxBionic := false
43 for _, os := range oses {
44 if os == android.Fuchsia {
45 ret += withFuchsiaModules()
46 }
47 if os == android.Windows {
48 ret += withWindowsModules()
49 }
50 if os == android.LinuxBionic {
51 supportLinuxBionic = true
52 ret += withLinuxBionic()
53 }
54 }
55
56 if !supportLinuxBionic {
57 ret += withoutLinuxBionic()
58 }
59
60 return ret
61}
62
63func commonDefaultModules() string {
64 return `
Inseob Kimc0907f12019-02-08 21:00:45 +090065 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +090066 name: "libcompiler_rt-extras",
67 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050068 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090069 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090070 recovery_available: true,
71 src: "",
72 }
73
74 toolchain_library {
75 name: "libclang_rt.builtins-arm-android",
76 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050077 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090078 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090079 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080080 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090081 src: "",
82 }
83
84 toolchain_library {
85 name: "libclang_rt.builtins-aarch64-android",
86 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -050087 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090088 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090089 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080090 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090091 src: "",
92 }
93
Jooyung Han75568392020-03-20 04:29:24 +090094 cc_prebuilt_library_shared {
95 name: "libclang_rt.hwasan-aarch64-android",
96 nocrt: true,
97 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090098 product_available: true,
Jooyung Han75568392020-03-20 04:29:24 +090099 recovery_available: true,
100 system_shared_libs: [],
101 stl: "none",
102 srcs: [""],
103 check_elf_files: false,
104 sanitize: {
105 never: true,
106 },
107 }
108
Inseob Kimc0907f12019-02-08 21:00:45 +0900109 toolchain_library {
110 name: "libclang_rt.builtins-i686-android",
111 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500112 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900113 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900114 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800115 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900116 src: "",
117 }
118
119 toolchain_library {
120 name: "libclang_rt.builtins-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100121 defaults: ["linux_bionic_supported"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900122 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500123 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900124 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900125 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800126 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900127 src: "",
128 }
129
130 toolchain_library {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800131 name: "libunwind",
132 defaults: ["linux_bionic_supported"],
133 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500134 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800135 product_available: true,
136 recovery_available: true,
137 native_bridge_supported: true,
138 src: "",
139 }
140
141 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700142 name: "libclang_rt.fuzzer-arm-android",
143 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900144 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700145 recovery_available: true,
146 src: "",
147 }
148
149 toolchain_library {
150 name: "libclang_rt.fuzzer-aarch64-android",
151 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900152 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700153 recovery_available: true,
154 src: "",
155 }
156
157 toolchain_library {
158 name: "libclang_rt.fuzzer-i686-android",
159 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900160 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700161 recovery_available: true,
162 src: "",
163 }
164
165 toolchain_library {
166 name: "libclang_rt.fuzzer-x86_64-android",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100167 defaults: ["linux_bionic_supported"],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700168 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900169 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700170 recovery_available: true,
171 src: "",
172 }
173
174 toolchain_library {
175 name: "libclang_rt.fuzzer-x86_64",
176 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900177 product_available: true,
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700178 recovery_available: true,
179 src: "",
180 }
181
Paul Duffind6867912019-12-19 14:38:36 +0000182 // Needed for sanitizer
183 cc_prebuilt_library_shared {
184 name: "libclang_rt.ubsan_standalone-aarch64-android",
185 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900186 product_available: true,
Paul Duffind6867912019-12-19 14:38:36 +0000187 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800188 system_shared_libs: [],
Paul Duffind6867912019-12-19 14:38:36 +0000189 srcs: [""],
190 }
191
Inseob Kimc0907f12019-02-08 21:00:45 +0900192 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900193 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100194 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700195 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900196 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800197 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900198 system_shared_libs: [],
199 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800200 stubs: {
201 versions: ["27", "28", "29"],
202 },
Colin Cross0477b422020-10-13 18:43:54 -0700203 llndk_stubs: "libc.llndk",
Justin Yun63e9ec72020-10-29 16:49:43 +0900204 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900205 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700206 name: "libc.llndk",
Inseob Kimc0907f12019-02-08 21:00:45 +0900207 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000208 sdk_version: "current",
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 Cross0477b422020-10-13 18:43:54 -0700225 llndk_stubs: "libm.llndk",
Inseob Kimc0907f12019-02-08 21:00:45 +0900226 }
227 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700228 name: "libm.llndk",
Inseob Kimc0907f12019-02-08 21:00:45 +0900229 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000230 sdk_version: "current",
Inseob Kimc0907f12019-02-08 21:00:45 +0900231 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400232
233 // Coverage libraries
234 cc_library {
235 name: "libprofile-extras",
236 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500237 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900238 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400239 recovery_available: true,
240 native_coverage: false,
241 system_shared_libs: [],
242 stl: "none",
243 notice: "custom_notice",
244 }
245 cc_library {
246 name: "libprofile-clang-extras",
247 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500248 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900249 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400250 recovery_available: true,
251 native_coverage: false,
252 system_shared_libs: [],
253 stl: "none",
254 notice: "custom_notice",
255 }
256 cc_library {
257 name: "libprofile-extras_ndk",
258 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900259 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400260 native_coverage: false,
261 system_shared_libs: [],
262 stl: "none",
263 notice: "custom_notice",
264 sdk_version: "current",
265 }
266 cc_library {
267 name: "libprofile-clang-extras_ndk",
268 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900269 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400270 native_coverage: false,
271 system_shared_libs: [],
272 stl: "none",
273 notice: "custom_notice",
274 sdk_version: "current",
275 }
276
Inseob Kimc0907f12019-02-08 21:00:45 +0900277 cc_library {
278 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100279 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700280 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900281 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800282 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900283 system_shared_libs: [],
284 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800285 stubs: {
286 versions: ["27", "28", "29"],
287 },
288 apex_available: [
289 "//apex_available:platform",
290 "myapex"
291 ],
Colin Cross0477b422020-10-13 18:43:54 -0700292 llndk_stubs: "libdl.llndk",
Inseob Kimc0907f12019-02-08 21:00:45 +0900293 }
294 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700295 name: "libdl.llndk",
Inseob Kimc0907f12019-02-08 21:00:45 +0900296 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000297 sdk_version: "current",
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 }
299 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900300 name: "libft2",
301 no_libcrt: true,
302 nocrt: true,
303 system_shared_libs: [],
304 recovery_available: true,
Colin Cross0477b422020-10-13 18:43:54 -0700305 llndk_stubs: "libft2.llndk",
Jooyung Han097087b2019-10-22 19:32:18 +0900306 }
307 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700308 name: "libft2.llndk",
Jooyung Han097087b2019-10-22 19:32:18 +0900309 symbol_file: "",
Justin Yunc0d8c492021-01-07 17:45:31 +0900310 private: true,
Colin Crossc511bc52020-04-07 16:50:32 +0000311 sdk_version: "current",
Jooyung Han097087b2019-10-22 19:32:18 +0900312 }
313 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900314 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700315 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900316 nocrt: true,
317 system_shared_libs: [],
318 stl: "none",
319 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500320 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900321 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900322 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900323 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900324 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900325 apex_available: [
326 "//apex_available:platform",
327 "//apex_available:anyapex",
328 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900329 }
330 cc_library {
331 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700332 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900333 nocrt: true,
334 system_shared_libs: [],
335 stl: "none",
336 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900337 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900338 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900339 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900340 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900341 vndk: {
342 enabled: true,
343 support_system_process: true,
344 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800345 apex_available: [
346 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500347 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800348 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900349 }
350 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700351 name: "libc++demangle",
352 no_libcrt: true,
353 nocrt: true,
354 system_shared_libs: [],
355 stl: "none",
356 host_supported: false,
357 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500358 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900359 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700360 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900361 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900362 apex_available: [
363 "//apex_available:platform",
364 "//apex_available:anyapex",
365 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700366 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900367
Jiyong Park541142c2020-03-07 16:35:46 +0900368 cc_defaults {
369 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100370 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900371 recovery_available: true,
372 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500373 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900374 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900375 native_bridge_supported: true,
376 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700377 min_sdk_version: "16",
378 crt: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900379 apex_available: [
380 "//apex_available:platform",
381 "//apex_available:anyapex",
382 ],
383 }
384
Inseob Kimc0907f12019-02-08 21:00:45 +0900385 cc_object {
386 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900387 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900388 }
389
390 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700391 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900392 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700393 }
394
395 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900396 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900397 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900398 }
399
400 cc_object {
401 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900402 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900403 }
404
405 cc_object {
406 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900407 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900408 }
409
410 cc_library {
411 name: "libprotobuf-cpp-lite",
412 }
Colin Crossf28329d2020-02-15 11:00:10 -0800413
414 cc_library {
415 name: "ndk_libunwind",
416 sdk_version: "current",
417 stl: "none",
418 system_shared_libs: [],
419 }
420
Dan Albertde5aade2020-06-30 12:32:51 -0700421 ndk_library {
422 name: "libc",
423 first_version: "minimum",
424 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800425 }
426
Dan Albertde5aade2020-06-30 12:32:51 -0700427 ndk_library {
428 name: "libm",
429 first_version: "minimum",
430 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800431 }
432
Dan Albertde5aade2020-06-30 12:32:51 -0700433 ndk_library {
434 name: "libdl",
435 first_version: "minimum",
436 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800437 }
438
Colin Crossf28329d2020-02-15 11:00:10 -0800439 ndk_prebuilt_shared_stl {
440 name: "ndk_libc++_shared",
441 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900442
443 cc_library_static {
444 name: "libgoogle-benchmark",
445 sdk_version: "current",
446 stl: "none",
447 system_shared_libs: [],
448 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700449
450 cc_library_static {
451 name: "note_memtag_heap_async",
452 }
453
454 cc_library_static {
455 name: "note_memtag_heap_sync",
456 }
Colin Crossf28329d2020-02-15 11:00:10 -0800457 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000458}
Colin Crossf28329d2020-02-15 11:00:10 -0800459
Paul Duffin02a3d652021-02-24 18:51:54 +0000460func withWindowsModules() string {
461 return `
Paul Duffina04c1072020-03-02 10:16:35 +0000462 toolchain_library {
463 name: "libwinpthread",
464 host_supported: true,
465 enabled: false,
466 target: {
467 windows: {
468 enabled: true,
469 },
470 },
471 src: "",
472 }
473 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000474}
475
476func withFuchsiaModules() string {
477 return `
478 cc_library {
479 name: "libbioniccompat",
480 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000481 }
Paul Duffin02a3d652021-02-24 18:51:54 +0000482 cc_library {
483 name: "libcompiler_rt",
484 stl: "none",
485 }
486 `
487}
488
489func withLinuxBionic() string {
490 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100491 cc_binary {
492 name: "linker",
493 defaults: ["linux_bionic_supported"],
494 recovery_available: true,
495 stl: "none",
496 nocrt: true,
497 static_executable: true,
498 native_coverage: false,
499 system_shared_libs: [],
500 }
501
502 cc_genrule {
503 name: "host_bionic_linker_flags",
504 host_supported: true,
505 device_supported: false,
506 target: {
507 host: {
508 enabled: false,
509 },
510 linux_bionic: {
511 enabled: true,
512 },
513 },
514 out: ["linker.flags"],
515 }
516
517 cc_defaults {
518 name: "linux_bionic_supported",
519 host_supported: true,
520 target: {
521 host: {
522 enabled: false,
523 },
524 linux_bionic: {
525 enabled: true,
526 },
527 },
528 }
529 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000530}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100531
Paul Duffin02a3d652021-02-24 18:51:54 +0000532func withoutLinuxBionic() string {
533 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100534 cc_defaults {
535 name: "linux_bionic_supported",
536 }
537 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900538}
Colin Cross9a942872019-05-14 15:44:26 -0700539
Colin Crossf28329d2020-02-15 11:00:10 -0800540func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800541}
542
Paul Duffin02a3d652021-02-24 18:51:54 +0000543// The directory in which cc linux bionic default modules will be defined.
544//
545// Placing them here ensures that their location does not conflict with default test modules
546// defined by other packages.
547const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
548
549// The directory in which the default cc common test modules will be defined.
550//
551// Placing them here ensures that their location does not conflict with default test modules
552// defined by other packages.
553const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
554
555// Test fixture preparer that will register most cc build components.
556//
557// Singletons and mutators should only be added here if they are needed for a majority of cc
558// module types, otherwise they should be added under a separate preparer to allow them to be
559// selected only when needed to reduce test execution time.
560//
561// Module types do not have much of an overhead unless they are used so this should include as many
562// module types as possible. The exceptions are those module types that require mutators and/or
563// singletons in order to function in which case they should be kept together in a separate
564// preparer.
565var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
566 android.PrepareForTestWithAndroidBuildComponents,
567 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
568 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
569 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
570 ctx.RegisterModuleType("cc_test", TestFactory)
571 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
572 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
573 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
574 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{
593 "defaults/cc/common/libc.map.txt": nil,
594 "defaults/cc/common/libdl.map.txt": nil,
595 "defaults/cc/common/libm.map.txt": nil,
596 }.AddToFixture(),
597
Paul Duffin02a3d652021-02-24 18:51:54 +0000598 // Place the default cc test modules that are common to all platforms in a location that will not
599 // conflict with default test modules defined by other packages.
600 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
601 // Disable linux bionic by default.
602 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
603)
604
605// Prepare a fixture to use all cc module types, mutators and singletons fully.
606//
607// This should only be used by tests that want to run with as much of the build enabled as possible.
608var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
609 android.PrepareForIntegrationTestWithAndroid,
610 genrule.PrepareForIntegrationTestWithGenrule,
611 PrepareForTestWithCcDefaultModules,
612)
613
614// The preparer to include if running a cc related test for windows.
615var PrepareForTestOnWindows = android.GroupFixturePreparers(
616 // Place the default cc test modules for windows platforms in a location that will not conflict
617 // with default test modules defined by other packages.
618 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
619)
620
621// The preparer to include if running a cc related test for linux bionic.
622var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000623 // Enable linux bionic
624 //
625 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
626 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
627 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000628)
629
Paul Duffinecdac8a2021-02-24 19:18:42 +0000630// The preparer to include if running a cc related test for fuchsia.
631var PrepareForTestOnFuchsia = android.GroupFixturePreparers(
632 // Place the default cc test modules for fuschia in a location that will not conflict with default
633 // test modules defined by other packages.
634 android.FixtureAddTextFile("defaults/cc/fuschia/Android.bp", withFuchsiaModules()),
635 android.PrepareForTestSetDeviceToFuchsia,
636)
637
Paul Duffin02a3d652021-02-24 18:51:54 +0000638// This adds some additional modules and singletons which might negatively impact the performance
639// of tests so they are not included in the PrepareForIntegrationTestWithCc.
640var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
641 PrepareForIntegrationTestWithCc,
642 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
643 vendorSnapshotImageSingleton.init(ctx)
644 recoverySnapshotImageSingleton.init(ctx)
645 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
646 }),
647)
648
649// TestConfig is the legacy way of creating a test Config for testing cc modules.
650//
651// See testCc for an explanation as to how to stop using this deprecated method.
652//
653// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800654func TestConfig(buildDir string, os android.OsType, env map[string]string,
655 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700656
Colin Cross98be1bb2019-12-13 20:41:13 -0800657 // add some modules that are required by the compiler and/or linker
658 bp = bp + GatherRequiredDepsForTest(os)
659
Colin Cross2fce23a2020-06-07 17:02:48 -0700660 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800661
Colin Crossf28329d2020-02-15 11:00:10 -0800662 GatherRequiredFilesForTest(mockFS)
663
Colin Cross98be1bb2019-12-13 20:41:13 -0800664 for k, v := range fs {
665 mockFS[k] = v
666 }
667
668 var config android.Config
669 if os == android.Fuchsia {
Paul Duffinecdac8a2021-02-24 19:18:42 +0000670 panic("Fuchsia not supported use test fixture instead")
Colin Cross98be1bb2019-12-13 20:41:13 -0800671 } else {
672 config = android.TestArchConfig(buildDir, env, bp, mockFS)
673 }
674
675 return config
676}
677
Paul Duffin02a3d652021-02-24 18:51:54 +0000678// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
679//
680// See testCc for an explanation as to how to stop using this deprecated method.
681//
682// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700683func CreateTestContext(config android.Config) *android.TestContext {
684 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000685 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800686 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800687 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400688 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800689 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
690 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800691 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
692 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000693
Colin Crosse0edaf92021-01-11 17:31:17 -0800694 vendorSnapshotImageSingleton.init(ctx)
695 recoverySnapshotImageSingleton.init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000696 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800697 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000698
Colin Crosse1bb5d02019-09-24 14:55:04 -0700699 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100700 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100701 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700702
Colin Cross9a942872019-05-14 15:44:26 -0700703 return ctx
704}