blob: b5cf45c55b793e11bb4641ac6dffded28dd6f0f8 [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 (
18 "android/soong/android"
19)
20
Paul Duffin77980a82019-12-19 16:01:36 +000021func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Paul Duffind6867912019-12-19 14:38:36 +000022 RegisterPrebuiltBuildComponents(ctx)
Paul Duffind6867912019-12-19 14:38:36 +000023 android.RegisterPrebuiltMutators(ctx)
Paul Duffin075c4172019-12-19 19:06:13 +000024
Paul Duffin036e7002019-12-19 19:16:28 +000025 RegisterCCBuildComponents(ctx)
Paul Duffin2ee69792020-01-16 12:14:42 +000026 RegisterBinaryBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000027 RegisterLibraryBuildComponents(ctx)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000028 RegisterLibraryHeadersBuildComponents(ctx)
Paul Duffin6c26dc72019-12-19 15:02:40 +000029
30 ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
31 ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)
32 ctx.RegisterModuleType("cc_object", ObjectFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080033 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
34 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000035}
36
Paul Duffina04c1072020-03-02 10:16:35 +000037func GatherRequiredDepsForTest(oses ...android.OsType) string {
Inseob Kimc0907f12019-02-08 21:00:45 +090038 ret := `
39 toolchain_library {
40 name: "libatomic",
41 vendor_available: true,
42 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080043 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090044 src: "",
45 }
46
47 toolchain_library {
48 name: "libcompiler_rt-extras",
49 vendor_available: true,
50 recovery_available: true,
51 src: "",
52 }
53
54 toolchain_library {
55 name: "libclang_rt.builtins-arm-android",
56 vendor_available: true,
57 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080058 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090059 src: "",
60 }
61
62 toolchain_library {
63 name: "libclang_rt.builtins-aarch64-android",
64 vendor_available: true,
65 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080066 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090067 src: "",
68 }
69
Jooyung Han75568392020-03-20 04:29:24 +090070 cc_prebuilt_library_shared {
71 name: "libclang_rt.hwasan-aarch64-android",
72 nocrt: true,
73 vendor_available: true,
74 recovery_available: true,
75 system_shared_libs: [],
76 stl: "none",
77 srcs: [""],
78 check_elf_files: false,
79 sanitize: {
80 never: true,
81 },
82 }
83
Inseob Kimc0907f12019-02-08 21:00:45 +090084 toolchain_library {
85 name: "libclang_rt.builtins-i686-android",
86 vendor_available: true,
87 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080088 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090089 src: "",
90 }
91
92 toolchain_library {
93 name: "libclang_rt.builtins-x86_64-android",
94 vendor_available: true,
95 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080096 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090097 src: "",
98 }
99
100 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700101 name: "libclang_rt.fuzzer-arm-android",
102 vendor_available: true,
103 recovery_available: true,
104 src: "",
105 }
106
107 toolchain_library {
108 name: "libclang_rt.fuzzer-aarch64-android",
109 vendor_available: true,
110 recovery_available: true,
111 src: "",
112 }
113
114 toolchain_library {
115 name: "libclang_rt.fuzzer-i686-android",
116 vendor_available: true,
117 recovery_available: true,
118 src: "",
119 }
120
121 toolchain_library {
122 name: "libclang_rt.fuzzer-x86_64-android",
123 vendor_available: true,
124 recovery_available: true,
125 src: "",
126 }
127
128 toolchain_library {
129 name: "libclang_rt.fuzzer-x86_64",
130 vendor_available: true,
131 recovery_available: true,
132 src: "",
133 }
134
Paul Duffind6867912019-12-19 14:38:36 +0000135 // Needed for sanitizer
136 cc_prebuilt_library_shared {
137 name: "libclang_rt.ubsan_standalone-aarch64-android",
138 vendor_available: true,
139 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800140 system_shared_libs: [],
Paul Duffind6867912019-12-19 14:38:36 +0000141 srcs: [""],
142 }
143
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700144 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900145 name: "libgcc",
146 vendor_available: true,
147 recovery_available: true,
148 src: "",
149 }
150
Yi Kongacee27c2019-03-29 20:05:14 -0700151 toolchain_library {
152 name: "libgcc_stripped",
153 vendor_available: true,
154 recovery_available: true,
Colin Crossc511bc52020-04-07 16:50:32 +0000155 sdk_version: "current",
Yi Kongacee27c2019-03-29 20:05:14 -0700156 src: "",
157 }
158
Inseob Kimc0907f12019-02-08 21:00:45 +0900159 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900160 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700161 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900162 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800163 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900164 system_shared_libs: [],
165 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800166 stubs: {
167 versions: ["27", "28", "29"],
168 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900169 }
170 llndk_library {
171 name: "libc",
172 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000173 sdk_version: "current",
Inseob Kimc0907f12019-02-08 21:00:45 +0900174 }
175 cc_library {
176 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700177 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900178 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800179 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900180 system_shared_libs: [],
181 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800182 stubs: {
183 versions: ["27", "28", "29"],
184 },
185 apex_available: [
186 "//apex_available:platform",
187 "myapex"
188 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900189 }
190 llndk_library {
191 name: "libm",
192 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000193 sdk_version: "current",
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400195
196 // Coverage libraries
197 cc_library {
198 name: "libprofile-extras",
199 vendor_available: true,
200 recovery_available: true,
201 native_coverage: false,
202 system_shared_libs: [],
203 stl: "none",
204 notice: "custom_notice",
205 }
206 cc_library {
207 name: "libprofile-clang-extras",
208 vendor_available: true,
209 recovery_available: true,
210 native_coverage: false,
211 system_shared_libs: [],
212 stl: "none",
213 notice: "custom_notice",
214 }
215 cc_library {
216 name: "libprofile-extras_ndk",
217 vendor_available: true,
218 native_coverage: false,
219 system_shared_libs: [],
220 stl: "none",
221 notice: "custom_notice",
222 sdk_version: "current",
223 }
224 cc_library {
225 name: "libprofile-clang-extras_ndk",
226 vendor_available: true,
227 native_coverage: false,
228 system_shared_libs: [],
229 stl: "none",
230 notice: "custom_notice",
231 sdk_version: "current",
232 }
233
Inseob Kimc0907f12019-02-08 21:00:45 +0900234 cc_library {
235 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700236 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900237 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800238 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900239 system_shared_libs: [],
240 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800241 stubs: {
242 versions: ["27", "28", "29"],
243 },
244 apex_available: [
245 "//apex_available:platform",
246 "myapex"
247 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900248 }
249 llndk_library {
250 name: "libdl",
251 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000252 sdk_version: "current",
Inseob Kimc0907f12019-02-08 21:00:45 +0900253 }
254 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900255 name: "libft2",
256 no_libcrt: true,
257 nocrt: true,
258 system_shared_libs: [],
259 recovery_available: true,
260 }
261 llndk_library {
262 name: "libft2",
263 symbol_file: "",
264 vendor_available: false,
Colin Crossc511bc52020-04-07 16:50:32 +0000265 sdk_version: "current",
Jooyung Han097087b2019-10-22 19:32:18 +0900266 }
267 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900268 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700269 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900270 nocrt: true,
271 system_shared_libs: [],
272 stl: "none",
273 vendor_available: true,
274 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900275 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900276 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900277 apex_available: [
278 "//apex_available:platform",
279 "//apex_available:anyapex",
280 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900281 }
282 cc_library {
283 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700284 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900285 nocrt: true,
286 system_shared_libs: [],
287 stl: "none",
288 vendor_available: true,
289 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900290 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900291 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900292 vndk: {
293 enabled: true,
294 support_system_process: true,
295 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800296 apex_available: [
297 "//apex_available:platform",
298 "myapex"
299 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 }
301 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700302 name: "libc++demangle",
303 no_libcrt: true,
304 nocrt: true,
305 system_shared_libs: [],
306 stl: "none",
307 host_supported: false,
308 vendor_available: true,
309 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900310 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900311 apex_available: [
312 "//apex_available:platform",
313 "//apex_available:anyapex",
314 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700315 }
316 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900317 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700318 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900319 nocrt: true,
320 system_shared_libs: [],
321 stl: "none",
322 vendor_available: true,
323 recovery_available: true,
324 }
325
Jiyong Park541142c2020-03-07 16:35:46 +0900326 cc_defaults {
327 name: "crt_defaults",
328 recovery_available: true,
329 vendor_available: true,
330 native_bridge_supported: true,
331 stl: "none",
332 apex_available: [
333 "//apex_available:platform",
334 "//apex_available:anyapex",
335 ],
336 }
337
Inseob Kimc0907f12019-02-08 21:00:45 +0900338 cc_object {
339 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900340 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900341 recovery_available: true,
342 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800343 native_bridge_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900344 min_sdk_version: "29",
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900345 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900346 }
347
348 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700349 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900350 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700351 recovery_available: true,
352 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800353 native_bridge_supported: true,
354 stl: "none",
Colin Cross815daf92019-05-14 16:05:20 -0700355 }
356
357 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900358 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900359 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900360 recovery_available: true,
361 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800362 native_bridge_supported: true,
363 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900364 }
365
366 cc_object {
367 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900368 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900369 recovery_available: true,
370 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800371 native_bridge_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900372 min_sdk_version: "29",
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900373 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900374 }
375
376 cc_object {
377 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900378 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900379 recovery_available: true,
380 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800381 native_bridge_supported: true,
382 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900383 }
384
385 cc_library {
386 name: "libprotobuf-cpp-lite",
387 }
Colin Crossf28329d2020-02-15 11:00:10 -0800388
389 cc_library {
390 name: "ndk_libunwind",
391 sdk_version: "current",
392 stl: "none",
393 system_shared_libs: [],
394 }
395
396 cc_library {
397 name: "libc.ndk.current",
398 sdk_version: "current",
399 stl: "none",
400 system_shared_libs: [],
401 }
402
403 cc_library {
404 name: "libm.ndk.current",
405 sdk_version: "current",
406 stl: "none",
407 system_shared_libs: [],
408 }
409
410 cc_library {
411 name: "libdl.ndk.current",
412 sdk_version: "current",
413 stl: "none",
414 system_shared_libs: [],
415 }
416
417 ndk_prebuilt_object {
418 name: "ndk_crtbegin_so.27",
419 sdk_version: "27",
420 }
421
422 ndk_prebuilt_object {
423 name: "ndk_crtend_so.27",
424 sdk_version: "27",
425 }
426
Colin Crossc511bc52020-04-07 16:50:32 +0000427 ndk_prebuilt_object {
428 name: "ndk_crtbegin_dynamic.27",
429 sdk_version: "27",
430 }
431
432 ndk_prebuilt_object {
433 name: "ndk_crtend_android.27",
434 sdk_version: "27",
435 }
436
Colin Crossf28329d2020-02-15 11:00:10 -0800437 ndk_prebuilt_shared_stl {
438 name: "ndk_libc++_shared",
439 }
440 `
441
Paul Duffina04c1072020-03-02 10:16:35 +0000442 for _, os := range oses {
443 if os == android.Fuchsia {
444 ret += `
Inseob Kimc0907f12019-02-08 21:00:45 +0900445 cc_library {
446 name: "libbioniccompat",
447 stl: "none",
448 }
449 cc_library {
450 name: "libcompiler_rt",
451 stl: "none",
452 }
453 `
Paul Duffina04c1072020-03-02 10:16:35 +0000454 }
455 if os == android.Windows {
456 ret += `
457 toolchain_library {
458 name: "libwinpthread",
459 host_supported: true,
460 enabled: false,
461 target: {
462 windows: {
463 enabled: true,
464 },
465 },
466 src: "",
467 }
468 `
469 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900470 }
471 return ret
472}
Colin Cross9a942872019-05-14 15:44:26 -0700473
Colin Crossf28329d2020-02-15 11:00:10 -0800474func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800475}
476
Colin Cross98be1bb2019-12-13 20:41:13 -0800477func TestConfig(buildDir string, os android.OsType, env map[string]string,
478 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700479
Colin Cross98be1bb2019-12-13 20:41:13 -0800480 // add some modules that are required by the compiler and/or linker
481 bp = bp + GatherRequiredDepsForTest(os)
482
Colin Cross2fce23a2020-06-07 17:02:48 -0700483 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800484
Colin Crossf28329d2020-02-15 11:00:10 -0800485 GatherRequiredFilesForTest(mockFS)
486
Colin Cross98be1bb2019-12-13 20:41:13 -0800487 for k, v := range fs {
488 mockFS[k] = v
489 }
490
491 var config android.Config
492 if os == android.Fuchsia {
493 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
494 } else {
495 config = android.TestArchConfig(buildDir, env, bp, mockFS)
496 }
497
498 return config
499}
500
501func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700502 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800503 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800504 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800505 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900506 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800507 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800508 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
509 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
510 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700511 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100512 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800513 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900514 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700515
Colin Cross9a942872019-05-14 15:44:26 -0700516 return ctx
517}