blob: 32f7c608074626816044eeddf8f3ce5eb7f14f67 [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)
Paul Duffin6c26dc72019-12-19 15:02:40 +000032
Jiyong Park46a512f2020-12-04 18:02:13 +090033 ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
Paul Duffin6c26dc72019-12-19 15:02:40 +000034 ctx.RegisterModuleType("cc_object", ObjectFactory)
Wei Libcd39942021-09-16 23:57:28 +000035 ctx.RegisterModuleType("cc_genrule", GenRuleFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080036 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Crossae628182021-06-14 16:52:28 -070037 ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080038 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Dan Albertde5aade2020-06-30 12:32:51 -070039 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000040}
41
Paul Duffina04c1072020-03-02 10:16:35 +000042func GatherRequiredDepsForTest(oses ...android.OsType) string {
Paul Duffin02a3d652021-02-24 18:51:54 +000043 ret := commonDefaultModules()
44
45 supportLinuxBionic := false
46 for _, os := range oses {
Paul Duffin02a3d652021-02-24 18:51:54 +000047 if os == android.Windows {
48 ret += withWindowsModules()
49 }
50 if os == android.LinuxBionic {
51 supportLinuxBionic = true
52 ret += withLinuxBionic()
53 }
54 }
55
56 if !supportLinuxBionic {
57 ret += withoutLinuxBionic()
58 }
59
60 return ret
61}
62
63func commonDefaultModules() string {
64 return `
Liz Kammer718eb272022-01-07 10:53:37 -050065 cc_defaults {
66 name: "toolchain_libs_defaults",
Inseob Kimc0907f12019-02-08 21:00:45 +090067 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090068 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090069 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050070 no_libcrt: true,
71 sdk_version: "minimum",
Jooyung Han75568392020-03-20 04:29:24 +090072 nocrt: true,
Jooyung Han75568392020-03-20 04:29:24 +090073 system_shared_libs: [],
74 stl: "none",
75 srcs: [""],
76 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,
86 }
87
88 cc_prebuilt_library_static {
Colin Crossfc0df952022-02-10 11:41:18 -080089 name: "libclang_rt.builtins",
Colin Cross06c80eb2022-02-10 10:34:19 -080090 defaults: ["toolchain_libs_defaults"],
91 host_supported: true,
Colin Crossfc0df952022-02-10 11:41:18 -080092 vendor_available: true,
93 vendor_ramdisk_available: true,
94 native_bridge_supported: true,
Colin Cross06c80eb2022-02-10 10:34:19 -080095 }
96
Liz Kammer718eb272022-01-07 10:53:37 -050097 cc_prebuilt_library_shared {
Colin Crossfc0df952022-02-10 11:41:18 -080098 name: "libclang_rt.hwasan",
Liz Kammer718eb272022-01-07 10:53:37 -050099 defaults: ["toolchain_libs_defaults"],
100 }
101
102 cc_prebuilt_library_static {
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800103 name: "libunwind",
Liz Kammer718eb272022-01-07 10:53:37 -0500104 defaults: [
105 "linux_bionic_supported",
106 "toolchain_libs_defaults",
107 ],
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500108 vendor_ramdisk_available: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800109 native_bridge_supported: true,
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800110 }
111
Liz Kammer718eb272022-01-07 10:53:37 -0500112 cc_prebuilt_library_static {
Colin Crossfc0df952022-02-10 11:41:18 -0800113 name: "libclang_rt.fuzzer",
Liz Kammer718eb272022-01-07 10:53:37 -0500114 defaults: [
115 "linux_bionic_supported",
116 "toolchain_libs_defaults",
117 ],
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700118 }
119
Paul Duffind6867912019-12-19 14:38:36 +0000120 // Needed for sanitizer
121 cc_prebuilt_library_shared {
Colin Crossfc0df952022-02-10 11:41:18 -0800122 name: "libclang_rt.ubsan_standalone",
Liz Kammer718eb272022-01-07 10:53:37 -0500123 defaults: ["toolchain_libs_defaults"],
Paul Duffind6867912019-12-19 14:38:36 +0000124 }
125
Colin Cross06c80eb2022-02-10 10:34:19 -0800126 cc_prebuilt_library_static {
Colin Crossfc0df952022-02-10 11:41:18 -0800127 name: "libclang_rt.ubsan_minimal",
Colin Cross06c80eb2022-02-10 10:34:19 -0800128 defaults: ["toolchain_libs_defaults"],
129 }
130
Inseob Kimc0907f12019-02-08 21:00:45 +0900131 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900132 name: "libc",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100133 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700134 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900135 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800136 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900137 system_shared_libs: [],
138 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800139 stubs: {
140 versions: ["27", "28", "29"],
141 },
Colin Cross203b4212021-04-26 17:19:41 -0700142 llndk: {
143 symbol_file: "libc.map.txt",
144 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900145 }
146 cc_library {
147 name: "libm",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100148 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700149 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900150 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800151 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900152 system_shared_libs: [],
153 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800154 stubs: {
155 versions: ["27", "28", "29"],
156 },
157 apex_available: [
158 "//apex_available:platform",
159 "myapex"
160 ],
Colin Cross203b4212021-04-26 17:19:41 -0700161 llndk: {
162 symbol_file: "libm.map.txt",
163 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900164 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400165
166 // Coverage libraries
167 cc_library {
168 name: "libprofile-extras",
169 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500170 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900171 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400172 recovery_available: true,
173 native_coverage: false,
174 system_shared_libs: [],
175 stl: "none",
176 notice: "custom_notice",
177 }
178 cc_library {
179 name: "libprofile-clang-extras",
180 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500181 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900182 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400183 recovery_available: true,
184 native_coverage: false,
185 system_shared_libs: [],
186 stl: "none",
187 notice: "custom_notice",
188 }
189 cc_library {
190 name: "libprofile-extras_ndk",
191 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900192 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400193 native_coverage: false,
194 system_shared_libs: [],
195 stl: "none",
196 notice: "custom_notice",
197 sdk_version: "current",
198 }
199 cc_library {
200 name: "libprofile-clang-extras_ndk",
201 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900202 product_available: true,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400203 native_coverage: false,
204 system_shared_libs: [],
205 stl: "none",
206 notice: "custom_notice",
207 sdk_version: "current",
208 }
209
Inseob Kimc0907f12019-02-08 21:00:45 +0900210 cc_library {
211 name: "libdl",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100212 defaults: ["linux_bionic_supported"],
Yi Konge7fe9912019-06-02 00:53:50 -0700213 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900214 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800215 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900216 system_shared_libs: [],
217 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800218 stubs: {
219 versions: ["27", "28", "29"],
220 },
221 apex_available: [
222 "//apex_available:platform",
223 "myapex"
224 ],
Colin Cross203b4212021-04-26 17:19:41 -0700225 llndk: {
226 symbol_file: "libdl.map.txt",
227 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900228 }
229 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900230 name: "libft2",
231 no_libcrt: true,
232 nocrt: true,
233 system_shared_libs: [],
234 recovery_available: true,
Colin Cross203b4212021-04-26 17:19:41 -0700235 llndk: {
236 symbol_file: "libft2.map.txt",
237 private: true,
238 }
Jooyung Han097087b2019-10-22 19:32:18 +0900239 }
240 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900241 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700242 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900243 nocrt: true,
244 system_shared_libs: [],
245 stl: "none",
246 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500247 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900248 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900249 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900250 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900251 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900252 apex_available: [
253 "//apex_available:platform",
254 "//apex_available:anyapex",
255 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900256 }
257 cc_library {
258 name: "libc++",
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,
Justin Yun63e9ec72020-10-29 16:49:43 +0900264 product_available: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900265 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900266 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900267 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900268 vndk: {
269 enabled: true,
270 support_system_process: true,
271 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800272 apex_available: [
273 "//apex_available:platform",
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500274 "//apex_available:anyapex",
Colin Crossf9aabd72020-02-15 11:29:50 -0800275 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900276 }
277 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700278 name: "libc++demangle",
279 no_libcrt: true,
280 nocrt: true,
281 system_shared_libs: [],
282 stl: "none",
283 host_supported: false,
284 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500285 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900286 product_available: true,
Dan Albert2da19cb2019-07-24 12:17:40 -0700287 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900288 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900289 apex_available: [
290 "//apex_available:platform",
291 "//apex_available:anyapex",
292 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700293 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900294
Jiyong Park541142c2020-03-07 16:35:46 +0900295 cc_defaults {
296 name: "crt_defaults",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100297 defaults: ["linux_bionic_supported"],
Jiyong Park541142c2020-03-07 16:35:46 +0900298 recovery_available: true,
299 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500300 vendor_ramdisk_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900301 product_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900302 native_bridge_supported: true,
303 stl: "none",
Dan Albert92fe7402020-07-15 13:33:30 -0700304 min_sdk_version: "16",
305 crt: true,
Colin Cross6b8f4252021-07-22 11:39:44 -0700306 system_shared_libs: [],
Jiyong Park541142c2020-03-07 16:35:46 +0900307 apex_available: [
308 "//apex_available:platform",
309 "//apex_available:anyapex",
310 ],
311 }
312
Inseob Kimc0907f12019-02-08 21:00:45 +0900313 cc_object {
314 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900315 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900316 srcs: ["crtbegin_so.c"],
317 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900318 }
319
320 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700321 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900322 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900323 srcs: ["crtbegin.c"],
324 objs: ["crtbrand"],
Colin Cross815daf92019-05-14 16:05:20 -0700325 }
326
327 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900328 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900329 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900330 srcs: ["crtbegin.c"],
331 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900332 }
333
334 cc_object {
335 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900336 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900337 srcs: ["crtend_so.c"],
338 objs: ["crtbrand"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900339 }
340
341 cc_object {
342 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900343 defaults: ["crt_defaults"],
Jiyong Park7549d462021-08-25 16:16:03 +0900344 srcs: ["crtend.c"],
345 objs: ["crtbrand"],
346 }
347
348 cc_object {
349 name: "crtbrand",
350 defaults: ["crt_defaults"],
351 srcs: ["crtbrand.c"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900352 }
353
354 cc_library {
355 name: "libprotobuf-cpp-lite",
356 }
Colin Crossf28329d2020-02-15 11:00:10 -0800357
358 cc_library {
359 name: "ndk_libunwind",
Colin Crossae628182021-06-14 16:52:28 -0700360 sdk_version: "minimum",
Colin Crossf28329d2020-02-15 11:00:10 -0800361 stl: "none",
362 system_shared_libs: [],
363 }
364
Dan Albertde5aade2020-06-30 12:32:51 -0700365 ndk_library {
366 name: "libc",
367 first_version: "minimum",
368 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800369 }
370
Dan Albertde5aade2020-06-30 12:32:51 -0700371 ndk_library {
372 name: "libm",
373 first_version: "minimum",
374 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800375 }
376
Dan Albertde5aade2020-06-30 12:32:51 -0700377 ndk_library {
378 name: "libdl",
379 first_version: "minimum",
380 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800381 }
382
Colin Crossf28329d2020-02-15 11:00:10 -0800383 ndk_prebuilt_shared_stl {
384 name: "ndk_libc++_shared",
Colin Crossae628182021-06-14 16:52:28 -0700385 export_include_dirs: ["ndk_libc++_shared"],
386 }
387
388 ndk_prebuilt_static_stl {
389 name: "ndk_libandroid_support",
390 export_include_dirs: ["ndk_libandroid_support"],
Colin Crossf28329d2020-02-15 11:00:10 -0800391 }
Jiyong Park46a512f2020-12-04 18:02:13 +0900392
393 cc_library_static {
394 name: "libgoogle-benchmark",
395 sdk_version: "current",
396 stl: "none",
397 system_shared_libs: [],
398 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700399
400 cc_library_static {
401 name: "note_memtag_heap_async",
402 }
403
404 cc_library_static {
405 name: "note_memtag_heap_sync",
406 }
Colin Cross528d67e2021-07-23 22:23:07 +0000407
Colin Cross528d67e2021-07-23 22:23:07 +0000408 cc_library {
409 name: "libc_musl",
410 host_supported: true,
411 no_libcrt: true,
412 nocrt: true,
413 system_shared_libs: [],
414 stl: "none",
415 }
Colin Crossf28329d2020-02-15 11:00:10 -0800416 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000417}
Colin Crossf28329d2020-02-15 11:00:10 -0800418
Paul Duffin02a3d652021-02-24 18:51:54 +0000419func withWindowsModules() string {
420 return `
Liz Kammer718eb272022-01-07 10:53:37 -0500421 cc_prebuilt_library_static {
Paul Duffina04c1072020-03-02 10:16:35 +0000422 name: "libwinpthread",
423 host_supported: true,
424 enabled: false,
425 target: {
426 windows: {
427 enabled: true,
428 },
429 },
Liz Kammer718eb272022-01-07 10:53:37 -0500430 stl: "none",
431 srcs:[""],
Paul Duffina04c1072020-03-02 10:16:35 +0000432 }
433 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000434}
435
Paul Duffin02a3d652021-02-24 18:51:54 +0000436func withLinuxBionic() string {
437 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100438 cc_binary {
439 name: "linker",
440 defaults: ["linux_bionic_supported"],
441 recovery_available: true,
442 stl: "none",
443 nocrt: true,
444 static_executable: true,
445 native_coverage: false,
446 system_shared_libs: [],
447 }
448
449 cc_genrule {
Colin Cross9cfe6112021-06-11 18:02:22 -0700450 name: "host_bionic_linker_script",
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100451 host_supported: true,
452 device_supported: false,
453 target: {
454 host: {
455 enabled: false,
456 },
457 linux_bionic: {
458 enabled: true,
459 },
460 },
Colin Cross9cfe6112021-06-11 18:02:22 -0700461 out: ["linker.script"],
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100462 }
463
464 cc_defaults {
465 name: "linux_bionic_supported",
466 host_supported: true,
467 target: {
468 host: {
469 enabled: false,
470 },
471 linux_bionic: {
472 enabled: true,
473 },
474 },
475 }
476 `
Paul Duffin02a3d652021-02-24 18:51:54 +0000477}
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100478
Paul Duffin02a3d652021-02-24 18:51:54 +0000479func withoutLinuxBionic() string {
480 return `
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100481 cc_defaults {
482 name: "linux_bionic_supported",
483 }
484 `
Inseob Kimc0907f12019-02-08 21:00:45 +0900485}
Colin Cross9a942872019-05-14 15:44:26 -0700486
Colin Crossf28329d2020-02-15 11:00:10 -0800487func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800488}
489
Paul Duffin02a3d652021-02-24 18:51:54 +0000490// The directory in which cc linux bionic default modules will be defined.
491//
492// Placing them here ensures that their location does not conflict with default test modules
493// defined by other packages.
494const linuxBionicDefaultsPath = "defaults/cc/linux-bionic/Android.bp"
495
496// The directory in which the default cc common test modules will be defined.
497//
498// Placing them here ensures that their location does not conflict with default test modules
499// defined by other packages.
500const DefaultCcCommonTestModulesDir = "defaults/cc/common/"
501
502// Test fixture preparer that will register most cc build components.
503//
504// Singletons and mutators should only be added here if they are needed for a majority of cc
505// module types, otherwise they should be added under a separate preparer to allow them to be
506// selected only when needed to reduce test execution time.
507//
508// Module types do not have much of an overhead unless they are used so this should include as many
509// module types as possible. The exceptions are those module types that require mutators and/or
510// singletons in order to function in which case they should be kept together in a separate
511// preparer.
512var PrepareForTestWithCcBuildComponents = android.GroupFixturePreparers(
513 android.PrepareForTestWithAndroidBuildComponents,
514 android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
515 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
516 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
517 ctx.RegisterModuleType("cc_test", TestFactory)
518 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000519 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
520
521 RegisterVndkLibraryTxtTypes(ctx)
522 }),
Paul Duffindb462dd2021-03-21 22:01:55 +0000523
524 // Additional files needed in tests that disallow non-existent source files.
525 // This includes files that are needed by all, or at least most, instances of a cc module type.
526 android.MockFS{
527 // Needed for ndk_prebuilt_(shared|static)_stl.
528 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs": nil,
529 }.AddToFixture(),
Paul Duffin02a3d652021-02-24 18:51:54 +0000530)
531
532// Preparer that will define default cc modules, e.g. standard prebuilt modules.
533var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
534 PrepareForTestWithCcBuildComponents,
Paul Duffindb462dd2021-03-21 22:01:55 +0000535
536 // Additional files needed in tests that disallow non-existent source.
537 android.MockFS{
Colin Crossae628182021-06-14 16:52:28 -0700538 "defaults/cc/common/libc.map.txt": nil,
539 "defaults/cc/common/libdl.map.txt": nil,
540 "defaults/cc/common/libm.map.txt": nil,
541 "defaults/cc/common/ndk_libandroid_support": nil,
542 "defaults/cc/common/ndk_libc++_shared": nil,
Jiyong Park7549d462021-08-25 16:16:03 +0900543 "defaults/cc/common/crtbegin_so.c": nil,
544 "defaults/cc/common/crtbegin.c": nil,
545 "defaults/cc/common/crtend_so.c": nil,
546 "defaults/cc/common/crtend.c": nil,
547 "defaults/cc/common/crtbrand.c": nil,
Paul Duffindb462dd2021-03-21 22:01:55 +0000548 }.AddToFixture(),
549
Paul Duffin02a3d652021-02-24 18:51:54 +0000550 // Place the default cc test modules that are common to all platforms in a location that will not
551 // conflict with default test modules defined by other packages.
552 android.FixtureAddTextFile(DefaultCcCommonTestModulesDir+"Android.bp", commonDefaultModules()),
553 // Disable linux bionic by default.
554 android.FixtureAddTextFile(linuxBionicDefaultsPath, withoutLinuxBionic()),
555)
556
557// Prepare a fixture to use all cc module types, mutators and singletons fully.
558//
559// This should only be used by tests that want to run with as much of the build enabled as possible.
560var PrepareForIntegrationTestWithCc = android.GroupFixturePreparers(
561 android.PrepareForIntegrationTestWithAndroid,
562 genrule.PrepareForIntegrationTestWithGenrule,
563 PrepareForTestWithCcDefaultModules,
564)
565
566// The preparer to include if running a cc related test for windows.
567var PrepareForTestOnWindows = android.GroupFixturePreparers(
568 // Place the default cc test modules for windows platforms in a location that will not conflict
569 // with default test modules defined by other packages.
570 android.FixtureAddTextFile("defaults/cc/windows/Android.bp", withWindowsModules()),
571)
572
573// The preparer to include if running a cc related test for linux bionic.
574var PrepareForTestOnLinuxBionic = android.GroupFixturePreparers(
Paul Duffin6e9a4002021-03-11 19:01:26 +0000575 // Enable linux bionic
576 //
577 // Can be used after PrepareForTestWithCcDefaultModules to override its default behavior of
578 // disabling linux bionic, hence why this uses FixtureOverrideTextFile.
579 android.FixtureOverrideTextFile(linuxBionicDefaultsPath, withLinuxBionic()),
Paul Duffin02a3d652021-02-24 18:51:54 +0000580)
581
582// This adds some additional modules and singletons which might negatively impact the performance
583// of tests so they are not included in the PrepareForIntegrationTestWithCc.
584var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers(
585 PrepareForIntegrationTestWithCc,
586 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900587 snapshot.VendorSnapshotImageSingleton.Init(ctx)
588 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
589 RegisterVendorSnapshotModules(ctx)
590 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000591 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
592 }),
593)
594
595// TestConfig is the legacy way of creating a test Config for testing cc modules.
596//
597// See testCc for an explanation as to how to stop using this deprecated method.
598//
599// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -0800600func TestConfig(buildDir string, os android.OsType, env map[string]string,
601 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700602
Colin Cross98be1bb2019-12-13 20:41:13 -0800603 // add some modules that are required by the compiler and/or linker
604 bp = bp + GatherRequiredDepsForTest(os)
605
Colin Cross2fce23a2020-06-07 17:02:48 -0700606 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800607
Colin Crossf28329d2020-02-15 11:00:10 -0800608 GatherRequiredFilesForTest(mockFS)
609
Colin Cross98be1bb2019-12-13 20:41:13 -0800610 for k, v := range fs {
611 mockFS[k] = v
612 }
613
Colin Crosscb0ac952021-07-20 13:17:15 -0700614 return android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Cross98be1bb2019-12-13 20:41:13 -0800615}
616
Paul Duffin02a3d652021-02-24 18:51:54 +0000617// CreateTestContext is the legacy way of creating a TestContext for testing cc modules.
618//
619// See testCc for an explanation as to how to stop using this deprecated method.
620//
621// deprecated
Colin Crossae8600b2020-10-29 17:09:13 -0700622func CreateTestContext(config android.Config) *android.TestContext {
623 ctx := android.NewTestArchContext(config)
Paul Duffind6ceb862021-03-04 23:02:31 +0000624 genrule.RegisterGenruleBuildComponents(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800625 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800626 ctx.RegisterModuleType("cc_test", TestFactory)
Chris Parsons79d66a52020-06-05 17:26:16 -0400627 ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800628 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
629 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Paul Duffin02a3d652021-02-24 18:51:54 +0000630
Kiyoung Kim48f37782021-07-07 12:42:39 +0900631 snapshot.VendorSnapshotImageSingleton.Init(ctx)
632 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
633 RegisterVendorSnapshotModules(ctx)
634 RegisterRecoverySnapshotModules(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000635 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800636 RegisterVndkLibraryTxtTypes(ctx)
Paul Duffin02a3d652021-02-24 18:51:54 +0000637
Colin Crosse1bb5d02019-09-24 14:55:04 -0700638 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin021f4e52020-07-30 16:04:17 +0100639 android.RegisterPrebuiltMutators(ctx)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100640 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700641
Colin Cross9a942872019-05-14 15:44:26 -0700642 return ctx
643}
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400644
645func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
646 t.Helper()
647 mod := ctx.ModuleForTests(moduleName, variant)
648 outputFiles := mod.OutputFiles(t, "")
649 if len(outputFiles) != 1 {
650 t.Errorf("%q must have single output\n", moduleName)
651 return
652 }
653 snapshotPath := filepath.Join(subDir, snapshotFilename)
654
655 if include {
656 out := singleton.Output(snapshotPath)
657 if fake {
658 if out.Rule == nil {
659 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
660 }
661 } else {
662 if out.Input.String() != outputFiles[0].String() {
663 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
664 }
665 }
666 } else {
667 out := singleton.MaybeOutput(snapshotPath)
668 if out.Rule != nil {
669 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
670 }
671 }
672}
673
674func CheckSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
675 t.Helper()
676 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
677}
678
679func CheckSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
680 t.Helper()
681 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
682}
683
684func CheckSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
685 t.Helper()
686 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
687}
688
689func AssertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
690 t.Helper()
691 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
692 if m.ExcludeFromVendorSnapshot() != expected {
693 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
694 }
695}
696
697func GetOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
698 for _, moduleName := range moduleNames {
699 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
700 output := module.outputFile.Path().RelativeToTop()
701 paths = append(paths, output)
702 }
703 return paths
704}
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500705
706func AssertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool, variant string) {
707 t.Helper()
708 m := ctx.ModuleForTests(name, variant).Module().(LinkableInterface)
709 if m.ExcludeFromRecoverySnapshot() != expected {
710 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
711 }
712}