blob: 077fcda3cae8283e932e46fd58c9b19d030f118d [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",
197 notice: "custom_notice",
198 }
199 cc_library {
200 name: "libprofile-clang-extras",
201 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500202 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900203 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400204 recovery_available: true,
205 native_coverage: false,
206 system_shared_libs: [],
207 stl: "none",
208 notice: "custom_notice",
209 }
210 cc_library {
211 name: "libprofile-extras_ndk",
212 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900213 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400214 native_coverage: false,
215 system_shared_libs: [],
216 stl: "none",
217 notice: "custom_notice",
218 sdk_version: "current",
219 }
220 cc_library {
221 name: "libprofile-clang-extras_ndk",
222 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900223 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400224 native_coverage: false,
225 system_shared_libs: [],
226 stl: "none",
227 notice: "custom_notice",
228 sdk_version: "current",
229 }
230
Inseob Kimc0907f12019-02-08 21:00:45 +0900231 cc_library {
232 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100233 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700234 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900235 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800236 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900237 system_shared_libs: [],
238 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800239 stubs: {
240 versions: ["27", "28", "29"],
241 },
242 apex_available: [
243 "//apex_available:platform",
244 "myapex"
245 ],
Colin Cross203b4212021-04-26 17:19:41 -0700246 llndk: {
247 symbol_file: "libdl.map.txt",
248 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900249 }
250 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900251 name: "libft2",
252 no_libcrt: true,
253 nocrt: true,
254 system_shared_libs: [],
255 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700256 llndk: {
257 symbol_file: "libft2.map.txt",
258 private: true,
259 }
Jooyung Han097087b2019-10-22 19:32:18 +0900260 }
261 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900262 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700263 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900264 nocrt: true,
265 system_shared_libs: [],
266 stl: "none",
267 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500268 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900269 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900270 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900271 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900272 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900273 apex_available: [
274 "//apex_available:platform",
275 "//apex_available:anyapex",
276 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900277 }
278 cc_library {
279 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700280 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900281 nocrt: true,
282 system_shared_libs: [],
283 stl: "none",
284 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900285 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900286 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900287 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900288 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900289 vndk: {
290 enabled: true,
291 support_system_process: true,
292 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800293 apex_available: [
294 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500295 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800296 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900297 }
298 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700299 name: "libc++demangle",
300 no_libcrt: true,
301 nocrt: true,
302 system_shared_libs: [],
303 stl: "none",
304 host_supported: false,
305 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500306 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900307 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700308 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900309 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900310 apex_available: [
311 "//apex_available:platform",
312 "//apex_available:anyapex",
313 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700314 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900315
Jiyong Park541142c2020-03-07 16:35:46 +0900316 cc_defaults {
317 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100318 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900319 recovery_available: true,
320 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500321 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900322 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900323 native_bridge_supported: true,
324 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700325 min_sdk_version: "16",
326 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700327 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900328 apex_available: [
329 "//apex_available:platform",
330 "//apex_available:anyapex",
331 ],
332 }
333
Inseob Kimc0907f12019-02-08 21:00:45 +0900334 cc_object {
335 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900336 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900337 srcs: ["crtbegin_so.c"],
338 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900339 }
340
341 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700342 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900343 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900344 srcs: ["crtbegin.c"],
345 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700346 }
347
348 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900349 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900350 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900351 srcs: ["crtbegin.c"],
352 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900353 }
354
355 cc_object {
356 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900357 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900358 srcs: ["crtend_so.c"],
359 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900360 }
361
362 cc_object {
363 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900364 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900365 srcs: ["crtend.c"],
366 objs: ["crtbrand"],
367 }
368
369 cc_object {
370 name: "crtbrand",
371 defaults: ["crt_defaults"],
372 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900373 }
374
375 cc_library {
376 name: "libprotobuf-cpp-lite",
377 }
Colin Crossf28329d2020-02-15 11:00:10 -0800378
379 cc_library {
380 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700381 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800382 stl: "none",
383 system_shared_libs: [],
384 }
385
Dan Albertde5aade2020-06-30 12:32:51 -0700386 ndk_library {
387 name: "libc",
388 first_version: "minimum",
389 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800390 }
391
Dan Albertde5aade2020-06-30 12:32:51 -0700392 ndk_library {
393 name: "libm",
394 first_version: "minimum",
395 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800396 }
397
Dan Albertde5aade2020-06-30 12:32:51 -0700398 ndk_library {
399 name: "libdl",
400 first_version: "minimum",
401 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800402 }
403
Colin Crossf28329d2020-02-15 11:00:10 -0800404 ndk_prebuilt_shared_stl {
405 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700406 export_include_dirs: ["ndk_libc++_shared"],
407 }
408
409 ndk_prebuilt_static_stl {
410 name: "ndk_libandroid_support",
411 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800412 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900413
414 cc_library_static {
415 name: "libgoogle-benchmark",
416 sdk_version: "current",
417 stl: "none",
418 system_shared_libs: [],
419 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700420
421 cc_library_static {
422 name: "note_memtag_heap_async",
423 }
424
425 cc_library_static {
426 name: "note_memtag_heap_sync",
427 }
Colin Cross528d67e2021-07-23 22:23:07 +0000428
Colin Cross528d67e2021-07-23 22:23:07 +0000429 cc_library {
430 name: "libc_musl",
431 host_supported: true,
432 no_libcrt: true,
433 nocrt: true,
434 system_shared_libs: [],
435 stl: "none",
436 }
Colin Crossf28329d2020-02-15 11:00:10 -0800437 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000438}
Colin Crossf28329d2020-02-15 11:00:10 -0800439
Paul Duffin02a3d652021-02-24 18:51:54 +0000440func withWindowsModules() string {
441 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500442 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000443 name: "libwinpthread",
444 host_supported: true,
445 enabled: false,
446 target: {
447 windows: {
448 enabled: true,
449 },
450 },
Liz Kammer718eb272022-01-07 10:53:37 -0500451 stl: "none",
452 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000453 }
454 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000455}
456
Paul Duffin02a3d652021-02-24 18:51:54 +0000457func withLinuxBionic() string {
458 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100459 cc_binary {
460 name: "linker",
461 defaults: ["linux_bionic_supported"],
462 recovery_available: true,
463 stl: "none",
464 nocrt: true,
465 static_executable: true,
466 native_coverage: false,
467 system_shared_libs: [],
468 }
469
470 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700471 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100472 host_supported: true,
473 device_supported: false,
474 target: {
475 host: {
476 enabled: false,
477 },
478 linux_bionic: {
479 enabled: true,
480 },
481 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700482 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100483 }
484
485 cc_defaults {
486 name: "linux_bionic_supported",
487 host_supported: true,
488 target: {
489 host: {
490 enabled: false,
491 },
492 linux_bionic: {
493 enabled: true,
494 },
495 },
496 }
497 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000498}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100499
Paul Duffin02a3d652021-02-24 18:51:54 +0000500func withoutLinuxBionic() string {
501 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100502 cc_defaults {
503 name: "linux_bionic_supported",
504 }
505 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900506}
Colin Cross9a942872019-05-14 15:44:26 -0700507
Colin Crossf28329d2020-02-15 11:00:10 -0800508func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800509}
510
Paul Duffin02a3d652021-02-24 18:51:54 +0000511// The directory in which cc linux bionic default modules will be defined.
512//
513// Placing them here ensures that their location does not conflict with default test modules
514// defined by other packages.
515const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
516
517// The directory in which the default cc common test modules will be defined.
518//
519// Placing them here ensures that their location does not conflict with default test modules
520// defined by other packages.
521const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
522
523// Test fixture preparer that will register most cc build components.
524//
525// Singletons and mutators should only be added here if they are needed for a majority of cc
526// module types, otherwise they should be added under a separate preparer to allow them to be
527// selected only when needed to reduce test execution time.
528//
529// Module types do not have much of an overhead unless they are used so this should include as many
530// module types as possible. The exceptions are those module types that require mutators and/or
531// singletons in order to function in which case they should be kept together in a separate
532// preparer.
533var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
534 android.PrepareForTestWithAndroidBuildComponents,
535 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
536 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
537 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
538 ctx.RegisterModuleType("cc_test", TestFactory)
539 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000540 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
541
542 RegisterVndkLibraryTxtTypes(ctx)
543 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000544
545 // Additional files needed in tests that disallow non-existent source files.
546 // This includes files that are needed by all, or at least most, instances of a cc module type.
547 android.MockFS{
548 // Needed for ndk_prebuilt_(shared|static)_stl.
549 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
550 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000551)
552
553// Preparer that will define default cc modules, e.g. standard prebuilt modules.
554var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
555 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000556
557 // Additional files needed in tests that disallow non-existent source.
558 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700559 "defaults/cc/common/libc.map.txt": nil,
560 "defaults/cc/common/libdl.map.txt": nil,
561 "defaults/cc/common/libm.map.txt": nil,
562 "defaults/cc/common/ndk_libandroid_support": nil,
563 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900564 "defaults/cc/common/crtbegin_so.c": nil,
565 "defaults/cc/common/crtbegin.c": nil,
566 "defaults/cc/common/crtend_so.c": nil,
567 "defaults/cc/common/crtend.c": nil,
568 "defaults/cc/common/crtbrand.c": nil,
Colin Cross3e5e7782022-06-17 22:17:05 +0000569
570 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
571 "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
572 "defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
573 "defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000574 }.AddToFixture(),
575
Paul Duffin02a3d652021-02-24 18:51:54 +0000576 // Place the default cc test modules that are common to all platforms in a location that will not
577 // conflict with default test modules defined by other packages.
578 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
579 // Disable linux bionic by default.
580 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
581)
582
583// Prepare a fixture to use all cc module types, mutators and singletons fully.
584//
585// This should only be used by tests that want to run with as much of the build enabled as possible.
586var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
587 android.PrepareForIntegrationTestWithAndroid,
588 genrule.PrepareForIntegrationTestWithGenrule,
589 PrepareForTestWithCcDefaultModules,
590)
591
592// The preparer to include if running a cc related test for windows.
593var PrepareForTestOnWindows = android.GroupFixturePreparers(
594 // Place the default cc test modules for windows platforms in a location that will not conflict
595 // with default test modules defined by other packages.
596 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
597)
598
599// The preparer to include if running a cc related test for linux bionic.
600var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000601 // Enable linux bionic
602 //
603 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
604 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
605 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000606)
607
608// This adds some additional modules and singletons which might negatively impact the performance
609// of tests so they are not included in the PrepareForIntegrationTestWithCc.
610var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
611 PrepareForIntegrationTestWithCc,
612 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900613 snapshot.VendorSnapshotImageSingleton.Init(ctx)
614 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
615 RegisterVendorSnapshotModules(ctx)
616 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000617 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
618 }),
619)
620
621// TestConfig is the legacy way of creating a test Config for testing cc modules.
622//
623// See testCc for an explanation as to how to stop using this deprecated method.
624//
625// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800626func TestConfig(buildDir string, os android.OsType, env map[string]string,
627 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700628
Colin Cross98be1bb2019-12-13 20:41:13 -0800629 // add some modules that are required by the compiler and/or linker
630 bp = bp + GatherRequiredDepsForTest(os)
631
Colin Cross2fce23a2020-06-07 17:02:48 -0700632 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800633
Colin Crossf28329d2020-02-15 11:00:10 -0800634 GatherRequiredFilesForTest(mockFS)
635
Colin Cross98be1bb2019-12-13 20:41:13 -0800636 for k, v := range fs {
637 mockFS[k] = v
638 }
639
Colin Crosscb0ac952021-07-20 13:17:15 -0700640 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800641}
642
Paul Duffin02a3d652021-02-24 18:51:54 +0000643// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
644//
645// See testCc for an explanation as to how to stop using this deprecated method.
646//
647// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700648func CreateTestContext(config android.Config) *android.TestContext {
649 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000650 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800651 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800652 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400653 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800654 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
655 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000656
Kiyoung Kim48f37782021-07-07 12:42:39 +0900657 snapshot.VendorSnapshotImageSingleton.Init(ctx)
658 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
659 RegisterVendorSnapshotModules(ctx)
660 RegisterRecoverySnapshotModules(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}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500731
732func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
733 t.Helper()
734 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
735 if m.ExcludeFromRecoverySnapshot() != expected {
736 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
737 }
738}