blob: ecdae8b15d2a622bde32255aaabd92b26b218ee1 [file] [log] [blame]
Inseob Kimc0907f12019-02-08 21:00:45 +09001// Copyright (C) 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
Ivan Lozanod67a6b02021-05-20 13:01:32 -040018 "path/filepath"
19 "testing"
20
Inseob Kimc0907f12019-02-08 21:00:45 +090021 "android/soong/android"
Colin Crosse9fe2942020-11-10 18:12:15 -080022 "android/soong/genrule"
Kiyoung Kim48f37782021-07-07 12:42:39 +090023 "android/soong/snapshot"
Inseob Kimc0907f12019-02-08 21:00:45 +090024)
25
Paul Duffin77980a82019-12-19 16:01:36 +000026func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000027 RegisterPrebuiltBuildComponents(ctx)
Paul Duffin036e7002019-12-19 19:16:28 +000028 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000029 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000030 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000031 RegisterLibraryHeadersBuildComponents(ctx)
Inseob Kim5eb7ee92022-04-27 10:30:34 +090032 RegisterLibraryStubBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000033
Jiyong Park46a512f2020-12-04 18:02:13 +090034 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000035 ctx.RegisterModuleType("cc_object", ObjectFactory)
Wei Libcd39942021-09-16 23:57:28 +000036 ctx.RegisterModuleType("cc_genrule", GenRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080037 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070038 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080039 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070040 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000041}
42
Paul Duffina04c1072020-03-02 10:16:35 +000043func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000044 ret := commonDefaultModules()
45
46 supportLinuxBionic := false
47 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000048 if os == android.Windows {
49 ret += withWindowsModules()
50 }
51 if os == android.LinuxBionic {
52 supportLinuxBionic = true
53 ret += withLinuxBionic()
54 }
55 }
56
57 if !supportLinuxBionic {
58 ret += withoutLinuxBionic()
59 }
60
61 return ret
62}
63
64func commonDefaultModules() string {
65 return `
Liz Kammer718eb272022-01-07 10:53:37 -050066 cc_defaults {
67 name: "toolchain_libs_defaults",
Inseob Kimc0907f12019-02-08 21:00:45 +090068 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090069 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090070 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050071 no_libcrt: true,
72 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090073 nocrt: true,
Jooyung Han75568392020-03-20 04:29:24 +090074 system_shared_libs: [],
75 stl: "none",
Colin Cross567d9832022-06-17 22:15:00 +000076 srcs: [""],
Jooyung Han75568392020-03-20 04:29:24 +090077 check_elf_files: false,
78 sanitize: {
79 never: true,
80 },
81 }
82
Liz Kammer718eb272022-01-07 10:53:37 -050083 cc_prebuilt_library_static {
84 name: "libcompiler_rt-extras",
85 defaults: ["toolchain_libs_defaults"],
86 vendor_ramdisk_available: true,
87 }
88
89 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -080090 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -080091 defaults: ["toolchain_libs_defaults"],
92 host_supported: true,
Colin Cross4c4c1be2022-02-10 11:41:18 -080093 vendor_available: true,
94 vendor_ramdisk_available: true,
95 native_bridge_supported: true,
Colin Cross06c80eb2022-02-10 10:34:19 -080096 }
97
Liz Kammer718eb272022-01-07 10:53:37 -050098 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -080099 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500100 defaults: ["toolchain_libs_defaults"],
101 }
102
103 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800104 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500105 defaults: [
106 "linux_bionic_supported",
107 "toolchain_libs_defaults",
108 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500109 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800110 native_bridge_supported: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800111 }
112
Liz Kammer718eb272022-01-07 10:53:37 -0500113 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800114 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500115 defaults: [
116 "linux_bionic_supported",
117 "toolchain_libs_defaults",
118 ],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700119 }
120
Paul Duffind6867912019-12-19 14:38:36 +0000121 // Needed for sanitizer
122 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800123 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500124 defaults: ["toolchain_libs_defaults"],
Paul Duffind6867912019-12-19 14:38:36 +0000125 }
126
Colin Cross06c80eb2022-02-10 10:34:19 -0800127 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800128 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800129 defaults: ["toolchain_libs_defaults"],
130 }
131
Inseob Kimc0907f12019-02-08 21:00:45 +0900132 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900133 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100134 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700135 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900136 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800137 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900138 system_shared_libs: [],
139 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800140 stubs: {
141 versions: ["27", "28", "29"],
142 },
Colin Cross203b4212021-04-26 17:19:41 -0700143 llndk: {
144 symbol_file: "libc.map.txt",
145 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900146 }
147 cc_library {
148 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100149 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700150 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900151 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800152 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900153 system_shared_libs: [],
154 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800155 stubs: {
156 versions: ["27", "28", "29"],
157 },
158 apex_available: [
159 "//apex_available:platform",
160 "myapex"
161 ],
Colin Cross203b4212021-04-26 17:19:41 -0700162 llndk: {
163 symbol_file: "libm.map.txt",
164 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900165 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400166
167 // Coverage libraries
168 cc_library {
169 name: "libprofile-extras",
170 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500171 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900172 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400173 recovery_available: true,
174 native_coverage: false,
175 system_shared_libs: [],
176 stl: "none",
177 notice: "custom_notice",
178 }
179 cc_library {
180 name: "libprofile-clang-extras",
181 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500182 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900183 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400184 recovery_available: true,
185 native_coverage: false,
186 system_shared_libs: [],
187 stl: "none",
188 notice: "custom_notice",
189 }
190 cc_library {
191 name: "libprofile-extras_ndk",
192 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900193 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400194 native_coverage: false,
195 system_shared_libs: [],
196 stl: "none",
197 notice: "custom_notice",
198 sdk_version: "current",
199 }
200 cc_library {
201 name: "libprofile-clang-extras_ndk",
202 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900203 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400204 native_coverage: false,
205 system_shared_libs: [],
206 stl: "none",
207 notice: "custom_notice",
208 sdk_version: "current",
209 }
210
Inseob Kimc0907f12019-02-08 21:00:45 +0900211 cc_library {
212 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100213 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700214 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900215 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800216 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900217 system_shared_libs: [],
218 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800219 stubs: {
220 versions: ["27", "28", "29"],
221 },
222 apex_available: [
223 "//apex_available:platform",
224 "myapex"
225 ],
Colin Cross203b4212021-04-26 17:19:41 -0700226 llndk: {
227 symbol_file: "libdl.map.txt",
228 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900229 }
230 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900231 name: "libft2",
232 no_libcrt: true,
233 nocrt: true,
234 system_shared_libs: [],
235 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700236 llndk: {
237 symbol_file: "libft2.map.txt",
238 private: true,
239 }
Jooyung Han097087b2019-10-22 19:32:18 +0900240 }
241 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900242 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700243 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900244 nocrt: true,
245 system_shared_libs: [],
246 stl: "none",
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,
Inseob Kimc0907f12019-02-08 21:00:45 +0900250 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900251 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900252 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900253 apex_available: [
254 "//apex_available:platform",
255 "//apex_available:anyapex",
256 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900257 }
258 cc_library {
259 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700260 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900261 nocrt: true,
262 system_shared_libs: [],
263 stl: "none",
264 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900265 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900266 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900267 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900268 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900269 vndk: {
270 enabled: true,
271 support_system_process: true,
272 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800273 apex_available: [
274 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500275 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800276 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900277 }
278 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700279 name: "libc++demangle",
280 no_libcrt: true,
281 nocrt: true,
282 system_shared_libs: [],
283 stl: "none",
284 host_supported: false,
285 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500286 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900287 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700288 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900289 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900290 apex_available: [
291 "//apex_available:platform",
292 "//apex_available:anyapex",
293 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700294 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900295
Jiyong Park541142c2020-03-07 16:35:46 +0900296 cc_defaults {
297 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100298 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900299 recovery_available: true,
300 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500301 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900302 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900303 native_bridge_supported: true,
304 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700305 min_sdk_version: "16",
306 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700307 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900308 apex_available: [
309 "//apex_available:platform",
310 "//apex_available:anyapex",
311 ],
312 }
313
Inseob Kimc0907f12019-02-08 21:00:45 +0900314 cc_object {
315 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900316 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900317 srcs: ["crtbegin_so.c"],
318 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900319 }
320
321 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700322 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900323 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900324 srcs: ["crtbegin.c"],
325 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700326 }
327
328 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900329 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900330 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900331 srcs: ["crtbegin.c"],
332 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900333 }
334
335 cc_object {
336 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900337 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900338 srcs: ["crtend_so.c"],
339 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900340 }
341
342 cc_object {
343 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900344 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900345 srcs: ["crtend.c"],
346 objs: ["crtbrand"],
347 }
348
349 cc_object {
350 name: "crtbrand",
351 defaults: ["crt_defaults"],
352 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900353 }
354
355 cc_library {
356 name: "libprotobuf-cpp-lite",
357 }
Colin Crossf28329d2020-02-15 11:00:10 -0800358
359 cc_library {
360 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700361 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800362 stl: "none",
363 system_shared_libs: [],
364 }
365
Dan Albertde5aade2020-06-30 12:32:51 -0700366 ndk_library {
367 name: "libc",
368 first_version: "minimum",
369 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800370 }
371
Dan Albertde5aade2020-06-30 12:32:51 -0700372 ndk_library {
373 name: "libm",
374 first_version: "minimum",
375 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800376 }
377
Dan Albertde5aade2020-06-30 12:32:51 -0700378 ndk_library {
379 name: "libdl",
380 first_version: "minimum",
381 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800382 }
383
Colin Crossf28329d2020-02-15 11:00:10 -0800384 ndk_prebuilt_shared_stl {
385 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700386 export_include_dirs: ["ndk_libc++_shared"],
387 }
388
389 ndk_prebuilt_static_stl {
390 name: "ndk_libandroid_support",
391 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800392 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900393
394 cc_library_static {
395 name: "libgoogle-benchmark",
396 sdk_version: "current",
397 stl: "none",
398 system_shared_libs: [],
399 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700400
401 cc_library_static {
402 name: "note_memtag_heap_async",
403 }
404
405 cc_library_static {
406 name: "note_memtag_heap_sync",
407 }
Colin Cross528d67e2021-07-23 22:23:07 +0000408
Colin Cross528d67e2021-07-23 22:23:07 +0000409 cc_library {
410 name: "libc_musl",
411 host_supported: true,
412 no_libcrt: true,
413 nocrt: true,
414 system_shared_libs: [],
415 stl: "none",
416 }
Colin Crossf28329d2020-02-15 11:00:10 -0800417 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000418}
Colin Crossf28329d2020-02-15 11:00:10 -0800419
Paul Duffin02a3d652021-02-24 18:51:54 +0000420func withWindowsModules() string {
421 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500422 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000423 name: "libwinpthread",
424 host_supported: true,
425 enabled: false,
426 target: {
427 windows: {
428 enabled: true,
429 },
430 },
Liz Kammer718eb272022-01-07 10:53:37 -0500431 stl: "none",
432 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000433 }
434 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000435}
436
Paul Duffin02a3d652021-02-24 18:51:54 +0000437func withLinuxBionic() string {
438 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100439 cc_binary {
440 name: "linker",
441 defaults: ["linux_bionic_supported"],
442 recovery_available: true,
443 stl: "none",
444 nocrt: true,
445 static_executable: true,
446 native_coverage: false,
447 system_shared_libs: [],
448 }
449
450 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700451 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100452 host_supported: true,
453 device_supported: false,
454 target: {
455 host: {
456 enabled: false,
457 },
458 linux_bionic: {
459 enabled: true,
460 },
461 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700462 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100463 }
464
465 cc_defaults {
466 name: "linux_bionic_supported",
467 host_supported: true,
468 target: {
469 host: {
470 enabled: false,
471 },
472 linux_bionic: {
473 enabled: true,
474 },
475 },
476 }
477 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000478}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100479
Paul Duffin02a3d652021-02-24 18:51:54 +0000480func withoutLinuxBionic() string {
481 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100482 cc_defaults {
483 name: "linux_bionic_supported",
484 }
485 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900486}
Colin Cross9a942872019-05-14 15:44:26 -0700487
Colin Crossf28329d2020-02-15 11:00:10 -0800488func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800489}
490
Paul Duffin02a3d652021-02-24 18:51:54 +0000491// The directory in which cc linux bionic default modules will be defined.
492//
493// Placing them here ensures that their location does not conflict with default test modules
494// defined by other packages.
495const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
496
497// The directory in which the default cc common test modules will be defined.
498//
499// Placing them here ensures that their location does not conflict with default test modules
500// defined by other packages.
501const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
502
503// Test fixture preparer that will register most cc build components.
504//
505// Singletons and mutators should only be added here if they are needed for a majority of cc
506// module types, otherwise they should be added under a separate preparer to allow them to be
507// selected only when needed to reduce test execution time.
508//
509// Module types do not have much of an overhead unless they are used so this should include as many
510// module types as possible. The exceptions are those module types that require mutators and/or
511// singletons in order to function in which case they should be kept together in a separate
512// preparer.
513var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
514 android.PrepareForTestWithAndroidBuildComponents,
515 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
516 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
517 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
518 ctx.RegisterModuleType("cc_test", TestFactory)
519 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000520 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
521
522 RegisterVndkLibraryTxtTypes(ctx)
523 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000524
525 // Additional files needed in tests that disallow non-existent source files.
526 // This includes files that are needed by all, or at least most, instances of a cc module type.
527 android.MockFS{
528 // Needed for ndk_prebuilt_(shared|static)_stl.
529 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
530 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000531)
532
533// Preparer that will define default cc modules, e.g. standard prebuilt modules.
534var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
535 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000536
537 // Additional files needed in tests that disallow non-existent source.
538 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700539 "defaults/cc/common/libc.map.txt": nil,
540 "defaults/cc/common/libdl.map.txt": nil,
541 "defaults/cc/common/libm.map.txt": nil,
542 "defaults/cc/common/ndk_libandroid_support": nil,
543 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900544 "defaults/cc/common/crtbegin_so.c": nil,
545 "defaults/cc/common/crtbegin.c": nil,
546 "defaults/cc/common/crtend_so.c": nil,
547 "defaults/cc/common/crtend.c": nil,
548 "defaults/cc/common/crtbrand.c": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000549 }.AddToFixture(),
550
Paul Duffin02a3d652021-02-24 18:51:54 +0000551 // Place the default cc test modules that are common to all platforms in a location that will not
552 // conflict with default test modules defined by other packages.
553 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
554 // Disable linux bionic by default.
555 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
556)
557
558// Prepare a fixture to use all cc module types, mutators and singletons fully.
559//
560// This should only be used by tests that want to run with as much of the build enabled as possible.
561var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
562 android.PrepareForIntegrationTestWithAndroid,
563 genrule.PrepareForIntegrationTestWithGenrule,
564 PrepareForTestWithCcDefaultModules,
565)
566
567// The preparer to include if running a cc related test for windows.
568var PrepareForTestOnWindows = android.GroupFixturePreparers(
569 // Place the default cc test modules for windows platforms in a location that will not conflict
570 // with default test modules defined by other packages.
571 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
572)
573
574// The preparer to include if running a cc related test for linux bionic.
575var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000576 // Enable linux bionic
577 //
578 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
579 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
580 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000581)
582
583// This adds some additional modules and singletons which might negatively impact the performance
584// of tests so they are not included in the PrepareForIntegrationTestWithCc.
585var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
586 PrepareForIntegrationTestWithCc,
587 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900588 snapshot.VendorSnapshotImageSingleton.Init(ctx)
589 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
590 RegisterVendorSnapshotModules(ctx)
591 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000592 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
593 }),
594)
595
596// TestConfig is the legacy way of creating a test Config for testing cc modules.
597//
598// See testCc for an explanation as to how to stop using this deprecated method.
599//
600// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800601func TestConfig(buildDir string, os android.OsType, env map[string]string,
602 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700603
Colin Cross98be1bb2019-12-13 20:41:13 -0800604 // add some modules that are required by the compiler and/or linker
605 bp = bp + GatherRequiredDepsForTest(os)
606
Colin Cross2fce23a2020-06-07 17:02:48 -0700607 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800608
Colin Crossf28329d2020-02-15 11:00:10 -0800609 GatherRequiredFilesForTest(mockFS)
610
Colin Cross98be1bb2019-12-13 20:41:13 -0800611 for k, v := range fs {
612 mockFS[k] = v
613 }
614
Colin Crosscb0ac952021-07-20 13:17:15 -0700615 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800616}
617
Paul Duffin02a3d652021-02-24 18:51:54 +0000618// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
619//
620// See testCc for an explanation as to how to stop using this deprecated method.
621//
622// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700623func CreateTestContext(config android.Config) *android.TestContext {
624 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000625 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800626 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800627 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400628 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800629 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
630 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000631
Kiyoung Kim48f37782021-07-07 12:42:39 +0900632 snapshot.VendorSnapshotImageSingleton.Init(ctx)
633 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
634 RegisterVendorSnapshotModules(ctx)
635 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000636 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800637 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000638
Colin Crosse1bb5d02019-09-24 14:55:04 -0700639 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100640 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100641 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700642
Colin Cross9a942872019-05-14 15:44:26 -0700643 return ctx
644}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400645
646func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
647 t.Helper()
648 mod := ctx.ModuleForTests(moduleName, variant)
649 outputFiles := mod.OutputFiles(t, "")
650 if len(outputFiles) != 1 {
651 t.Errorf("%q must have single output\n", moduleName)
652 return
653 }
654 snapshotPath := filepath.Join(subDir, snapshotFilename)
655
656 if include {
657 out := singleton.Output(snapshotPath)
658 if fake {
659 if out.Rule == nil {
660 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
661 }
662 } else {
663 if out.Input.String() != outputFiles[0].String() {
664 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
665 }
666 }
667 } else {
668 out := singleton.MaybeOutput(snapshotPath)
669 if out.Rule != nil {
670 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
671 }
672 }
673}
674
675func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
676 t.Helper()
677 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
678}
679
680func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
681 t.Helper()
682 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
683}
684
685func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
686 t.Helper()
687 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
688}
689
690func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
691 t.Helper()
692 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
693 if m.ExcludeFromVendorSnapshot() != expected {
694 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
695 }
696}
697
698func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
699 for _, moduleName := range moduleNames {
700 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
701 output := module.outputFile.Path().RelativeToTop()
702 paths = append(paths, output)
703 }
704 return paths
705}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500706
707func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
708 t.Helper()
709 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
710 if m.ExcludeFromRecoverySnapshot() != expected {
711 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
712 }
713}