blob: d70ec9bb5e777c1b18861037d025a7fcfa1c2ee4 [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",
Jooyung Han75568392020-03-20 04:29:24 +090076 check_elf_files: false,
77 sanitize: {
78 never: true,
79 },
80 }
81
Liz Kammer718eb272022-01-07 10:53:37 -050082 cc_prebuilt_library_static {
83 name: "libcompiler_rt-extras",
84 defaults: ["toolchain_libs_defaults"],
85 vendor_ramdisk_available: true,
Colin Cross3e5e7782022-06-17 22:17:05 +000086 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -050087 }
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 Cross3e5e7782022-06-17 22:17:05 +000096 srcs: [""],
Colin Cross06c80eb2022-02-10 10:34:19 -080097 }
98
Liz Kammer718eb272022-01-07 10:53:37 -050099 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800100 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -0500101 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000102 srcs: [""],
Liz Kammer718eb272022-01-07 10:53:37 -0500103 }
104
105 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800106 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500107 defaults: [
108 "linux_bionic_supported",
109 "toolchain_libs_defaults",
110 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500111 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800112 native_bridge_supported: true,
Colin Cross3e5e7782022-06-17 22:17:05 +0000113 srcs: [""],
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800114 }
115
Liz Kammer718eb272022-01-07 10:53:37 -0500116 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800117 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500118 defaults: [
119 "linux_bionic_supported",
120 "toolchain_libs_defaults",
121 ],
Colin Cross3e5e7782022-06-17 22:17:05 +0000122 srcs: [""],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700123 }
124
Paul Duffind6867912019-12-19 14:38:36 +0000125 // Needed for sanitizer
126 cc_prebuilt_library_shared {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800127 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500128 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000129 srcs: [""],
Paul Duffind6867912019-12-19 14:38:36 +0000130 }
131
Colin Cross06c80eb2022-02-10 10:34:19 -0800132 cc_prebuilt_library_static {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800133 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800134 defaults: ["toolchain_libs_defaults"],
Colin Cross3e5e7782022-06-17 22:17:05 +0000135 host_supported: true,
136 target: {
137 android_arm64: {
138 srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
139 },
140 android_arm: {
141 srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
142 },
143 linux_glibc_x86_64: {
144 srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
145 },
146 linux_glibc_x86: {
147 srcs: ["libclang_rt.ubsan_minimal.x86.a"],
148 },
149 },
Colin Cross06c80eb2022-02-10 10:34:19 -0800150 }
151
Inseob Kimc0907f12019-02-08 21:00:45 +0900152 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900153 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100154 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700155 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900156 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800157 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900158 system_shared_libs: [],
159 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800160 stubs: {
161 versions: ["27", "28", "29"],
162 },
Colin Cross203b4212021-04-26 17:19:41 -0700163 llndk: {
164 symbol_file: "libc.map.txt",
165 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900166 }
167 cc_library {
168 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100169 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700170 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900171 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800172 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900173 system_shared_libs: [],
174 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800175 stubs: {
176 versions: ["27", "28", "29"],
177 },
178 apex_available: [
179 "//apex_available:platform",
180 "myapex"
181 ],
Colin Cross203b4212021-04-26 17:19:41 -0700182 llndk: {
183 symbol_file: "libm.map.txt",
184 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900185 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400186
187 // Coverage libraries
188 cc_library {
189 name: "libprofile-extras",
190 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500191 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900192 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400193 recovery_available: true,
194 native_coverage: false,
195 system_shared_libs: [],
196 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400197 }
198 cc_library {
199 name: "libprofile-clang-extras",
200 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500201 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900202 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400203 recovery_available: true,
204 native_coverage: false,
205 system_shared_libs: [],
206 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400207 }
208 cc_library {
209 name: "libprofile-extras_ndk",
210 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900211 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400212 native_coverage: false,
213 system_shared_libs: [],
214 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400215 sdk_version: "current",
216 }
217 cc_library {
218 name: "libprofile-clang-extras_ndk",
219 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900220 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400221 native_coverage: false,
222 system_shared_libs: [],
223 stl: "none",
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400224 sdk_version: "current",
225 }
226
Inseob Kimc0907f12019-02-08 21:00:45 +0900227 cc_library {
228 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100229 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700230 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900231 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800232 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900233 system_shared_libs: [],
234 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800235 stubs: {
236 versions: ["27", "28", "29"],
237 },
238 apex_available: [
239 "//apex_available:platform",
240 "myapex"
241 ],
Colin Cross203b4212021-04-26 17:19:41 -0700242 llndk: {
243 symbol_file: "libdl.map.txt",
244 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900245 }
246 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900247 name: "libft2",
248 no_libcrt: true,
249 nocrt: true,
250 system_shared_libs: [],
251 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700252 llndk: {
253 symbol_file: "libft2.map.txt",
254 private: true,
255 }
Jooyung Han097087b2019-10-22 19:32:18 +0900256 }
257 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900258 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700259 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900260 nocrt: true,
261 system_shared_libs: [],
262 stl: "none",
263 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500264 vendor_ramdisk_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",
Jiyong Park541142c2020-03-07 16:35:46 +0900269 apex_available: [
270 "//apex_available:platform",
271 "//apex_available:anyapex",
272 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900273 }
274 cc_library {
275 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700276 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900277 nocrt: true,
278 system_shared_libs: [],
279 stl: "none",
280 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900281 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900282 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900283 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900284 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900285 vndk: {
286 enabled: true,
287 support_system_process: true,
288 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800289 apex_available: [
290 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500291 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800292 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900293 }
294 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700295 name: "libc++demangle",
296 no_libcrt: true,
297 nocrt: true,
298 system_shared_libs: [],
299 stl: "none",
300 host_supported: false,
301 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500302 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900303 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700304 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900305 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900306 apex_available: [
307 "//apex_available:platform",
308 "//apex_available:anyapex",
309 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700310 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900311
Jiyong Park541142c2020-03-07 16:35:46 +0900312 cc_defaults {
313 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100314 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900315 recovery_available: true,
316 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500317 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900318 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900319 native_bridge_supported: true,
320 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700321 min_sdk_version: "16",
322 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700323 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900324 apex_available: [
325 "//apex_available:platform",
326 "//apex_available:anyapex",
327 ],
328 }
329
Inseob Kimc0907f12019-02-08 21:00:45 +0900330 cc_object {
331 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900332 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900333 srcs: ["crtbegin_so.c"],
334 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900335 }
336
337 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700338 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900339 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900340 srcs: ["crtbegin.c"],
341 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700342 }
343
344 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900345 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900346 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900347 srcs: ["crtbegin.c"],
348 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900349 }
350
351 cc_object {
352 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900353 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900354 srcs: ["crtend_so.c"],
355 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900356 }
357
358 cc_object {
359 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900360 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900361 srcs: ["crtend.c"],
362 objs: ["crtbrand"],
363 }
364
365 cc_object {
366 name: "crtbrand",
367 defaults: ["crt_defaults"],
368 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900369 }
370
371 cc_library {
372 name: "libprotobuf-cpp-lite",
373 }
Colin Crossf28329d2020-02-15 11:00:10 -0800374
375 cc_library {
376 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700377 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800378 stl: "none",
379 system_shared_libs: [],
380 }
381
Dan Albertde5aade2020-06-30 12:32:51 -0700382 ndk_library {
383 name: "libc",
384 first_version: "minimum",
385 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800386 }
387
Dan Albertde5aade2020-06-30 12:32:51 -0700388 ndk_library {
389 name: "libm",
390 first_version: "minimum",
391 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800392 }
393
Dan Albertde5aade2020-06-30 12:32:51 -0700394 ndk_library {
395 name: "libdl",
396 first_version: "minimum",
397 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800398 }
399
Colin Crossf28329d2020-02-15 11:00:10 -0800400 ndk_prebuilt_shared_stl {
401 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700402 export_include_dirs: ["ndk_libc++_shared"],
403 }
404
405 ndk_prebuilt_static_stl {
406 name: "ndk_libandroid_support",
407 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800408 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900409
410 cc_library_static {
411 name: "libgoogle-benchmark",
412 sdk_version: "current",
413 stl: "none",
414 system_shared_libs: [],
415 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700416
417 cc_library_static {
418 name: "note_memtag_heap_async",
419 }
420
421 cc_library_static {
422 name: "note_memtag_heap_sync",
423 }
Colin Cross528d67e2021-07-23 22:23:07 +0000424
Colin Cross528d67e2021-07-23 22:23:07 +0000425 cc_library {
426 name: "libc_musl",
427 host_supported: true,
428 no_libcrt: true,
429 nocrt: true,
430 system_shared_libs: [],
431 stl: "none",
432 }
Colin Crossf28329d2020-02-15 11:00:10 -0800433 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000434}
Colin Crossf28329d2020-02-15 11:00:10 -0800435
Paul Duffin02a3d652021-02-24 18:51:54 +0000436func withWindowsModules() string {
437 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500438 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000439 name: "libwinpthread",
440 host_supported: true,
441 enabled: false,
442 target: {
443 windows: {
444 enabled: true,
445 },
446 },
Liz Kammer718eb272022-01-07 10:53:37 -0500447 stl: "none",
448 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000449 }
450 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000451}
452
Paul Duffin02a3d652021-02-24 18:51:54 +0000453func withLinuxBionic() string {
454 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100455 cc_binary {
456 name: "linker",
457 defaults: ["linux_bionic_supported"],
458 recovery_available: true,
459 stl: "none",
460 nocrt: true,
461 static_executable: true,
462 native_coverage: false,
463 system_shared_libs: [],
464 }
465
466 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700467 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100468 host_supported: true,
469 device_supported: false,
470 target: {
471 host: {
472 enabled: false,
473 },
474 linux_bionic: {
475 enabled: true,
476 },
477 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700478 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100479 }
480
481 cc_defaults {
482 name: "linux_bionic_supported",
483 host_supported: true,
484 target: {
485 host: {
486 enabled: false,
487 },
488 linux_bionic: {
489 enabled: true,
490 },
491 },
492 }
493 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000494}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100495
Paul Duffin02a3d652021-02-24 18:51:54 +0000496func withoutLinuxBionic() string {
497 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100498 cc_defaults {
499 name: "linux_bionic_supported",
500 }
501 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900502}
Colin Cross9a942872019-05-14 15:44:26 -0700503
Colin Crossf28329d2020-02-15 11:00:10 -0800504func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800505}
506
Paul Duffin02a3d652021-02-24 18:51:54 +0000507// The directory in which cc linux bionic default modules will be defined.
508//
509// Placing them here ensures that their location does not conflict with default test modules
510// defined by other packages.
511const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
512
513// The directory in which the default cc common test modules will be defined.
514//
515// Placing them here ensures that their location does not conflict with default test modules
516// defined by other packages.
517const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
518
519// Test fixture preparer that will register most cc build components.
520//
521// Singletons and mutators should only be added here if they are needed for a majority of cc
522// module types, otherwise they should be added under a separate preparer to allow them to be
523// selected only when needed to reduce test execution time.
524//
525// Module types do not have much of an overhead unless they are used so this should include as many
526// module types as possible. The exceptions are those module types that require mutators and/or
527// singletons in order to function in which case they should be kept together in a separate
528// preparer.
529var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
530 android.PrepareForTestWithAndroidBuildComponents,
531 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
532 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Cory Barkera1da26f2022-06-07 20:12:06 +0000533 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
534 ctx.RegisterModuleType("cc_afl_fuzz", AFLFuzzFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000535 ctx.RegisterModuleType("cc_test", TestFactory)
536 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000537 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
538
539 RegisterVndkLibraryTxtTypes(ctx)
540 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000541
542 // Additional files needed in tests that disallow non-existent source files.
543 // This includes files that are needed by all, or at least most, instances of a cc module type.
544 android.MockFS{
545 // Needed for ndk_prebuilt_(shared|static)_stl.
546 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
547 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000548)
549
550// Preparer that will define default cc modules, e.g. standard prebuilt modules.
551var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
552 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000553
554 // Additional files needed in tests that disallow non-existent source.
555 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700556 "defaults/cc/common/libc.map.txt": nil,
557 "defaults/cc/common/libdl.map.txt": nil,
558 "defaults/cc/common/libm.map.txt": nil,
559 "defaults/cc/common/ndk_libandroid_support": nil,
560 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900561 "defaults/cc/common/crtbegin_so.c": nil,
562 "defaults/cc/common/crtbegin.c": nil,
563 "defaults/cc/common/crtend_so.c": nil,
564 "defaults/cc/common/crtend.c": nil,
565 "defaults/cc/common/crtbrand.c": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000566
567 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
568 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
569 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
570 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000571 }.AddToFixture(),
572
Paul Duffin02a3d652021-02-24 18:51:54 +0000573 // Place the default cc test modules that are common to all platforms in a location that will not
574 // conflict with default test modules defined by other packages.
575 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
576 // Disable linux bionic by default.
577 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
578)
579
580// Prepare a fixture to use all cc module types, mutators and singletons fully.
581//
582// This should only be used by tests that want to run with as much of the build enabled as possible.
583var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
584 android.PrepareForIntegrationTestWithAndroid,
585 genrule.PrepareForIntegrationTestWithGenrule,
586 PrepareForTestWithCcDefaultModules,
587)
588
589// The preparer to include if running a cc related test for windows.
590var PrepareForTestOnWindows = android.GroupFixturePreparers(
591 // Place the default cc test modules for windows platforms in a location that will not conflict
592 // with default test modules defined by other packages.
593 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
594)
595
596// The preparer to include if running a cc related test for linux bionic.
597var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000598 // Enable linux bionic
599 //
600 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
601 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
602 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000603)
604
605// This adds some additional modules and singletons which might negatively impact the performance
606// of tests so they are not included in the PrepareForIntegrationTestWithCc.
607var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
608 PrepareForIntegrationTestWithCc,
609 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900610 snapshot.VendorSnapshotImageSingleton.Init(ctx)
611 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
612 RegisterVendorSnapshotModules(ctx)
613 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000614 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
615 }),
616)
617
618// TestConfig is the legacy way of creating a test Config for testing cc modules.
619//
620// See testCc for an explanation as to how to stop using this deprecated method.
621//
622// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800623func TestConfig(buildDir string, os android.OsType, env map[string]string,
624 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700625
Colin Cross98be1bb2019-12-13 20:41:13 -0800626 // add some modules that are required by the compiler and/or linker
627 bp = bp + GatherRequiredDepsForTest(os)
628
Colin Cross2fce23a2020-06-07 17:02:48 -0700629 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800630
Colin Crossf28329d2020-02-15 11:00:10 -0800631 GatherRequiredFilesForTest(mockFS)
632
Colin Cross98be1bb2019-12-13 20:41:13 -0800633 for k, v := range fs {
634 mockFS[k] = v
635 }
636
Colin Crosscb0ac952021-07-20 13:17:15 -0700637 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800638}
639
Paul Duffin02a3d652021-02-24 18:51:54 +0000640// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
641//
642// See testCc for an explanation as to how to stop using this deprecated method.
643//
644// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700645func CreateTestContext(config android.Config) *android.TestContext {
646 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000647 genrule.RegisterGenruleBuildComponents(ctx)
Cory Barkera1da26f2022-06-07 20:12:06 +0000648 ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
649 ctx.RegisterModuleType("cc_afl_fuzz", AFLFuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800650 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400651 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800652 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
653 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000654
Kiyoung Kim48f37782021-07-07 12:42:39 +0900655 snapshot.VendorSnapshotImageSingleton.Init(ctx)
656 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
657 RegisterVendorSnapshotModules(ctx)
658 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000659 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800660 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000661
Colin Crosse1bb5d02019-09-24 14:55:04 -0700662 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100663 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100664 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700665
Colin Cross9a942872019-05-14 15:44:26 -0700666 return ctx
667}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400668
669func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
670 t.Helper()
671 mod := ctx.ModuleForTests(moduleName, variant)
672 outputFiles := mod.OutputFiles(t, "")
673 if len(outputFiles) != 1 {
674 t.Errorf("%q must have single output\n", moduleName)
675 return
676 }
677 snapshotPath := filepath.Join(subDir, snapshotFilename)
678
679 if include {
680 out := singleton.Output(snapshotPath)
681 if fake {
682 if out.Rule == nil {
683 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
684 }
685 } else {
686 if out.Input.String() != outputFiles[0].String() {
687 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
688 }
689 }
690 } else {
691 out := singleton.MaybeOutput(snapshotPath)
692 if out.Rule != nil {
693 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
694 }
695 }
696}
697
698func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
699 t.Helper()
700 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
701}
702
703func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
704 t.Helper()
705 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
706}
707
708func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
709 t.Helper()
710 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
711}
712
713func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
714 t.Helper()
715 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
716 if m.ExcludeFromVendorSnapshot() != expected {
717 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
718 }
719}
720
721func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
722 for _, moduleName := range moduleNames {
723 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
724 output := module.outputFile.Path().RelativeToTop()
725 paths = append(paths, output)
726 }
727 return paths
728}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500729
730func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
731 t.Helper()
732 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
733 if m.ExcludeFromRecoverySnapshot() != expected {
734 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
735 }
736}