blob: 00bf511243c290d28876420247c1387faa591379 [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 {
Paul Duffin02a3d652021-02-24 18:51:54 +000047 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 Cross203b4212021-04-26 17:19:41 -0700203 llndk: {
204 symbol_file: "libc.map.txt",
205 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900206 }
207 cc_library {
208 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100209 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700210 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900211 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800212 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900213 system_shared_libs: [],
214 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800215 stubs: {
216 versions: ["27", "28", "29"],
217 },
218 apex_available: [
219 "//apex_available:platform",
220 "myapex"
221 ],
Colin Cross203b4212021-04-26 17:19:41 -0700222 llndk: {
223 symbol_file: "libm.map.txt",
224 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900225 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400226
227 // Coverage libraries
228 cc_library {
229 name: "libprofile-extras",
230 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500231 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900232 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400233 recovery_available: true,
234 native_coverage: false,
235 system_shared_libs: [],
236 stl: "none",
237 notice: "custom_notice",
238 }
239 cc_library {
240 name: "libprofile-clang-extras",
241 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500242 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900243 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400244 recovery_available: true,
245 native_coverage: false,
246 system_shared_libs: [],
247 stl: "none",
248 notice: "custom_notice",
249 }
250 cc_library {
251 name: "libprofile-extras_ndk",
252 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900253 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400254 native_coverage: false,
255 system_shared_libs: [],
256 stl: "none",
257 notice: "custom_notice",
258 sdk_version: "current",
259 }
260 cc_library {
261 name: "libprofile-clang-extras_ndk",
262 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900263 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400264 native_coverage: false,
265 system_shared_libs: [],
266 stl: "none",
267 notice: "custom_notice",
268 sdk_version: "current",
269 }
270
Inseob Kimc0907f12019-02-08 21:00:45 +0900271 cc_library {
272 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100273 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700274 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900275 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800276 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900277 system_shared_libs: [],
278 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800279 stubs: {
280 versions: ["27", "28", "29"],
281 },
282 apex_available: [
283 "//apex_available:platform",
284 "myapex"
285 ],
Colin Cross203b4212021-04-26 17:19:41 -0700286 llndk: {
287 symbol_file: "libdl.map.txt",
288 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900289 }
290 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900291 name: "libft2",
292 no_libcrt: true,
293 nocrt: true,
294 system_shared_libs: [],
295 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700296 llndk: {
297 symbol_file: "libft2.map.txt",
298 private: true,
299 }
Jooyung Han097087b2019-10-22 19:32:18 +0900300 }
301 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900302 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700303 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900304 nocrt: true,
305 system_shared_libs: [],
306 stl: "none",
307 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500308 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900309 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900310 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900311 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900312 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900313 apex_available: [
314 "//apex_available:platform",
315 "//apex_available:anyapex",
316 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900317 }
318 cc_library {
319 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700320 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900321 nocrt: true,
322 system_shared_libs: [],
323 stl: "none",
324 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900325 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900326 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900327 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900328 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900329 vndk: {
330 enabled: true,
331 support_system_process: true,
332 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800333 apex_available: [
334 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500335 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800336 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900337 }
338 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700339 name: "libc++demangle",
340 no_libcrt: true,
341 nocrt: true,
342 system_shared_libs: [],
343 stl: "none",
344 host_supported: false,
345 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500346 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900347 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700348 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900349 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900350 apex_available: [
351 "//apex_available:platform",
352 "//apex_available:anyapex",
353 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700354 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900355
Jiyong Park541142c2020-03-07 16:35:46 +0900356 cc_defaults {
357 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100358 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900359 recovery_available: true,
360 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500361 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900362 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900363 native_bridge_supported: true,
364 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700365 min_sdk_version: "16",
366 crt: true,
Colin Cross137d7da2021-06-21 16:41:29 -0700367 default_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900368 apex_available: [
369 "//apex_available:platform",
370 "//apex_available:anyapex",
371 ],
372 }
373
Inseob Kimc0907f12019-02-08 21:00:45 +0900374 cc_object {
375 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900376 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900377 }
378
379 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700380 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900381 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700382 }
383
384 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900385 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900386 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900387 }
388
389 cc_object {
390 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900391 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900392 }
393
394 cc_object {
395 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900396 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900397 }
398
399 cc_library {
400 name: "libprotobuf-cpp-lite",
401 }
Colin Crossf28329d2020-02-15 11:00:10 -0800402
403 cc_library {
404 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700405 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800406 stl: "none",
407 system_shared_libs: [],
408 }
409
Dan Albertde5aade2020-06-30 12:32:51 -0700410 ndk_library {
411 name: "libc",
412 first_version: "minimum",
413 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800414 }
415
Dan Albertde5aade2020-06-30 12:32:51 -0700416 ndk_library {
417 name: "libm",
418 first_version: "minimum",
419 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800420 }
421
Dan Albertde5aade2020-06-30 12:32:51 -0700422 ndk_library {
423 name: "libdl",
424 first_version: "minimum",
425 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800426 }
427
Colin Crossf28329d2020-02-15 11:00:10 -0800428 ndk_prebuilt_shared_stl {
429 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700430 export_include_dirs: ["ndk_libc++_shared"],
431 }
432
433 ndk_prebuilt_static_stl {
434 name: "ndk_libandroid_support",
435 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800436 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900437
438 cc_library_static {
439 name: "libgoogle-benchmark",
440 sdk_version: "current",
441 stl: "none",
442 system_shared_libs: [],
443 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700444
445 cc_library_static {
446 name: "note_memtag_heap_async",
447 }
448
449 cc_library_static {
450 name: "note_memtag_heap_sync",
451 }
Colin Crossf28329d2020-02-15 11:00:10 -0800452 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000453}
Colin Crossf28329d2020-02-15 11:00:10 -0800454
Paul Duffin02a3d652021-02-24 18:51:54 +0000455func withWindowsModules() string {
456 return `
Paul Duffina04c1072020-03-02 10:16:35 +0000457 toolchain_library {
458 name: "libwinpthread",
459 host_supported: true,
460 enabled: false,
461 target: {
462 windows: {
463 enabled: true,
464 },
465 },
466 src: "",
467 }
468 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000469}
470
Paul Duffin02a3d652021-02-24 18:51:54 +0000471func withLinuxBionic() string {
472 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100473 cc_binary {
474 name: "linker",
475 defaults: ["linux_bionic_supported"],
476 recovery_available: true,
477 stl: "none",
478 nocrt: true,
479 static_executable: true,
480 native_coverage: false,
481 system_shared_libs: [],
482 }
483
484 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700485 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100486 host_supported: true,
487 device_supported: false,
488 target: {
489 host: {
490 enabled: false,
491 },
492 linux_bionic: {
493 enabled: true,
494 },
495 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700496 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100497 }
498
499 cc_defaults {
500 name: "linux_bionic_supported",
501 host_supported: true,
502 target: {
503 host: {
504 enabled: false,
505 },
506 linux_bionic: {
507 enabled: true,
508 },
509 },
510 }
511 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000512}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100513
Paul Duffin02a3d652021-02-24 18:51:54 +0000514func withoutLinuxBionic() string {
515 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100516 cc_defaults {
517 name: "linux_bionic_supported",
518 }
519 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900520}
Colin Cross9a942872019-05-14 15:44:26 -0700521
Colin Crossf28329d2020-02-15 11:00:10 -0800522func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800523}
524
Paul Duffin02a3d652021-02-24 18:51:54 +0000525// The directory in which cc linux bionic default modules will be defined.
526//
527// Placing them here ensures that their location does not conflict with default test modules
528// defined by other packages.
529const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
530
531// The directory in which the default cc common test modules will be defined.
532//
533// Placing them here ensures that their location does not conflict with default test modules
534// defined by other packages.
535const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
536
537// Test fixture preparer that will register most cc build components.
538//
539// Singletons and mutators should only be added here if they are needed for a majority of cc
540// module types, otherwise they should be added under a separate preparer to allow them to be
541// selected only when needed to reduce test execution time.
542//
543// Module types do not have much of an overhead unless they are used so this should include as many
544// module types as possible. The exceptions are those module types that require mutators and/or
545// singletons in order to function in which case they should be kept together in a separate
546// preparer.
547var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
548 android.PrepareForTestWithAndroidBuildComponents,
549 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
550 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
551 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
552 ctx.RegisterModuleType("cc_test", TestFactory)
553 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000554 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
555
556 RegisterVndkLibraryTxtTypes(ctx)
557 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000558
559 // Additional files needed in tests that disallow non-existent source files.
560 // This includes files that are needed by all, or at least most, instances of a cc module type.
561 android.MockFS{
562 // Needed for ndk_prebuilt_(shared|static)_stl.
563 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
564 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000565)
566
567// Preparer that will define default cc modules, e.g. standard prebuilt modules.
568var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
569 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000570
571 // Additional files needed in tests that disallow non-existent source.
572 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700573 "defaults/cc/common/libc.map.txt": nil,
574 "defaults/cc/common/libdl.map.txt": nil,
575 "defaults/cc/common/libm.map.txt": nil,
576 "defaults/cc/common/ndk_libandroid_support": nil,
577 "defaults/cc/common/ndk_libc++_shared": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000578 }.AddToFixture(),
579
Paul Duffin02a3d652021-02-24 18:51:54 +0000580 // Place the default cc test modules that are common to all platforms in a location that will not
581 // conflict with default test modules defined by other packages.
582 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
583 // Disable linux bionic by default.
584 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
585)
586
587// Prepare a fixture to use all cc module types, mutators and singletons fully.
588//
589// This should only be used by tests that want to run with as much of the build enabled as possible.
590var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
591 android.PrepareForIntegrationTestWithAndroid,
592 genrule.PrepareForIntegrationTestWithGenrule,
593 PrepareForTestWithCcDefaultModules,
594)
595
596// The preparer to include if running a cc related test for windows.
597var PrepareForTestOnWindows = android.GroupFixturePreparers(
598 // Place the default cc test modules for windows platforms in a location that will not conflict
599 // with default test modules defined by other packages.
600 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
601)
602
603// The preparer to include if running a cc related test for linux bionic.
604var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000605 // Enable linux bionic
606 //
607 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
608 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
609 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000610)
611
612// This adds some additional modules and singletons which might negatively impact the performance
613// of tests so they are not included in the PrepareForIntegrationTestWithCc.
614var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
615 PrepareForIntegrationTestWithCc,
616 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400617 VendorSnapshotImageSingleton.Init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000618 recoverySnapshotImageSingleton.init(ctx)
619 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
620 }),
621)
622
623// TestConfig is the legacy way of creating a test Config for testing cc modules.
624//
625// See testCc for an explanation as to how to stop using this deprecated method.
626//
627// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800628func TestConfig(buildDir string, os android.OsType, env map[string]string,
629 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700630
Colin Cross98be1bb2019-12-13 20:41:13 -0800631 // add some modules that are required by the compiler and/or linker
632 bp = bp + GatherRequiredDepsForTest(os)
633
Colin Cross2fce23a2020-06-07 17:02:48 -0700634 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800635
Colin Crossf28329d2020-02-15 11:00:10 -0800636 GatherRequiredFilesForTest(mockFS)
637
Colin Cross98be1bb2019-12-13 20:41:13 -0800638 for k, v := range fs {
639 mockFS[k] = v
640 }
641
Colin Crosscb0ac952021-07-20 13:17:15 -0700642 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800643}
644
Paul Duffin02a3d652021-02-24 18:51:54 +0000645// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
646//
647// See testCc for an explanation as to how to stop using this deprecated method.
648//
649// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700650func CreateTestContext(config android.Config) *android.TestContext {
651 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000652 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800653 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800654 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400655 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800656 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
657 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000658
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400659 VendorSnapshotImageSingleton.Init(ctx)
Colin Crosse0edaf92021-01-11 17:31:17 -0800660 recoverySnapshotImageSingleton.init(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000661 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800662 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000663
Colin Crosse1bb5d02019-09-24 14:55:04 -0700664 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100665 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100666 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700667
Colin Cross9a942872019-05-14 15:44:26 -0700668 return ctx
669}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400670
671func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
672 t.Helper()
673 mod := ctx.ModuleForTests(moduleName, variant)
674 outputFiles := mod.OutputFiles(t, "")
675 if len(outputFiles) != 1 {
676 t.Errorf("%q must have single output\n", moduleName)
677 return
678 }
679 snapshotPath := filepath.Join(subDir, snapshotFilename)
680
681 if include {
682 out := singleton.Output(snapshotPath)
683 if fake {
684 if out.Rule == nil {
685 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
686 }
687 } else {
688 if out.Input.String() != outputFiles[0].String() {
689 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
690 }
691 }
692 } else {
693 out := singleton.MaybeOutput(snapshotPath)
694 if out.Rule != nil {
695 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
696 }
697 }
698}
699
700func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
701 t.Helper()
702 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
703}
704
705func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
706 t.Helper()
707 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
708}
709
710func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
711 t.Helper()
712 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
713}
714
715func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
716 t.Helper()
717 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
718 if m.ExcludeFromVendorSnapshot() != expected {
719 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
720 }
721}
722
723func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
724 for _, moduleName := range moduleNames {
725 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
726 output := module.outputFile.Path().RelativeToTop()
727 paths = append(paths, output)
728 }
729 return paths
730}