blob: b0c3c162a44014d2a851a896afa1a2bd6cc0218e [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)
Dan Albertde5aade2020-06-30 12:32:51 -070035 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000036}
37
Paul Duffina04c1072020-03-02 10:16:35 +000038func GatherRequiredDepsForTest(oses ...android.OsType) string {
Inseob Kimc0907f12019-02-08 21:00:45 +090039 ret := `
40 toolchain_library {
41 name: "libatomic",
42 vendor_available: true,
43 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080044 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090045 src: "",
46 }
47
48 toolchain_library {
49 name: "libcompiler_rt-extras",
50 vendor_available: true,
51 recovery_available: true,
52 src: "",
53 }
54
55 toolchain_library {
56 name: "libclang_rt.builtins-arm-android",
57 vendor_available: true,
58 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080059 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090060 src: "",
61 }
62
63 toolchain_library {
64 name: "libclang_rt.builtins-aarch64-android",
65 vendor_available: true,
66 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080067 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090068 src: "",
69 }
70
Jooyung Han75568392020-03-20 04:29:24 +090071 cc_prebuilt_library_shared {
72 name: "libclang_rt.hwasan-aarch64-android",
73 nocrt: true,
74 vendor_available: true,
75 recovery_available: true,
76 system_shared_libs: [],
77 stl: "none",
78 srcs: [""],
79 check_elf_files: false,
80 sanitize: {
81 never: true,
82 },
83 }
84
Inseob Kimc0907f12019-02-08 21:00:45 +090085 toolchain_library {
86 name: "libclang_rt.builtins-i686-android",
87 vendor_available: true,
88 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080089 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090090 src: "",
91 }
92
93 toolchain_library {
94 name: "libclang_rt.builtins-x86_64-android",
95 vendor_available: true,
96 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080097 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090098 src: "",
99 }
100
101 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700102 name: "libclang_rt.fuzzer-arm-android",
103 vendor_available: true,
104 recovery_available: true,
105 src: "",
106 }
107
108 toolchain_library {
109 name: "libclang_rt.fuzzer-aarch64-android",
110 vendor_available: true,
111 recovery_available: true,
112 src: "",
113 }
114
115 toolchain_library {
116 name: "libclang_rt.fuzzer-i686-android",
117 vendor_available: true,
118 recovery_available: true,
119 src: "",
120 }
121
122 toolchain_library {
123 name: "libclang_rt.fuzzer-x86_64-android",
124 vendor_available: true,
125 recovery_available: true,
126 src: "",
127 }
128
129 toolchain_library {
130 name: "libclang_rt.fuzzer-x86_64",
131 vendor_available: true,
132 recovery_available: true,
133 src: "",
134 }
135
Paul Duffind6867912019-12-19 14:38:36 +0000136 // Needed for sanitizer
137 cc_prebuilt_library_shared {
138 name: "libclang_rt.ubsan_standalone-aarch64-android",
139 vendor_available: true,
140 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800141 system_shared_libs: [],
Paul Duffind6867912019-12-19 14:38:36 +0000142 srcs: [""],
143 }
144
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700145 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900146 name: "libgcc",
147 vendor_available: true,
148 recovery_available: true,
149 src: "",
150 }
151
Yi Kongacee27c2019-03-29 20:05:14 -0700152 toolchain_library {
153 name: "libgcc_stripped",
154 vendor_available: true,
155 recovery_available: true,
Colin Crossc511bc52020-04-07 16:50:32 +0000156 sdk_version: "current",
Yi Kongacee27c2019-03-29 20:05:14 -0700157 src: "",
158 }
159
Inseob Kimc0907f12019-02-08 21:00:45 +0900160 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900161 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700162 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900163 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800164 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900165 system_shared_libs: [],
166 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800167 stubs: {
168 versions: ["27", "28", "29"],
169 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900170 }
171 llndk_library {
172 name: "libc",
173 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000174 sdk_version: "current",
Inseob Kimc0907f12019-02-08 21:00:45 +0900175 }
176 cc_library {
177 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700178 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900179 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800180 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900181 system_shared_libs: [],
182 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800183 stubs: {
184 versions: ["27", "28", "29"],
185 },
186 apex_available: [
187 "//apex_available:platform",
188 "myapex"
189 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900190 }
191 llndk_library {
192 name: "libm",
193 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000194 sdk_version: "current",
Inseob Kimc0907f12019-02-08 21:00:45 +0900195 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400196
197 // Coverage libraries
198 cc_library {
199 name: "libprofile-extras",
200 vendor_available: true,
201 recovery_available: true,
202 native_coverage: false,
203 system_shared_libs: [],
204 stl: "none",
205 notice: "custom_notice",
206 }
207 cc_library {
208 name: "libprofile-clang-extras",
209 vendor_available: true,
210 recovery_available: true,
211 native_coverage: false,
212 system_shared_libs: [],
213 stl: "none",
214 notice: "custom_notice",
215 }
216 cc_library {
217 name: "libprofile-extras_ndk",
218 vendor_available: true,
219 native_coverage: false,
220 system_shared_libs: [],
221 stl: "none",
222 notice: "custom_notice",
223 sdk_version: "current",
224 }
225 cc_library {
226 name: "libprofile-clang-extras_ndk",
227 vendor_available: true,
228 native_coverage: false,
229 system_shared_libs: [],
230 stl: "none",
231 notice: "custom_notice",
232 sdk_version: "current",
233 }
234
Inseob Kimc0907f12019-02-08 21:00:45 +0900235 cc_library {
236 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700237 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900238 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800239 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900240 system_shared_libs: [],
241 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800242 stubs: {
243 versions: ["27", "28", "29"],
244 },
245 apex_available: [
246 "//apex_available:platform",
247 "myapex"
248 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900249 }
250 llndk_library {
251 name: "libdl",
252 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000253 sdk_version: "current",
Inseob Kimc0907f12019-02-08 21:00:45 +0900254 }
255 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900256 name: "libft2",
257 no_libcrt: true,
258 nocrt: true,
259 system_shared_libs: [],
260 recovery_available: true,
261 }
262 llndk_library {
263 name: "libft2",
264 symbol_file: "",
265 vendor_available: false,
Colin Crossc511bc52020-04-07 16:50:32 +0000266 sdk_version: "current",
Jooyung Han097087b2019-10-22 19:32:18 +0900267 }
268 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900269 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700270 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900271 nocrt: true,
272 system_shared_libs: [],
273 stl: "none",
274 vendor_available: true,
275 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900276 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900277 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900278 apex_available: [
279 "//apex_available:platform",
280 "//apex_available:anyapex",
281 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900282 }
283 cc_library {
284 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700285 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900286 nocrt: true,
287 system_shared_libs: [],
288 stl: "none",
289 vendor_available: true,
290 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900291 host_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900292 min_sdk_version: "29",
Inseob Kimc0907f12019-02-08 21:00:45 +0900293 vndk: {
294 enabled: true,
295 support_system_process: true,
296 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800297 apex_available: [
298 "//apex_available:platform",
299 "myapex"
300 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900301 }
302 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700303 name: "libc++demangle",
304 no_libcrt: true,
305 nocrt: true,
306 system_shared_libs: [],
307 stl: "none",
308 host_supported: false,
309 vendor_available: true,
310 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900311 min_sdk_version: "29",
Jiyong Park541142c2020-03-07 16:35:46 +0900312 apex_available: [
313 "//apex_available:platform",
314 "//apex_available:anyapex",
315 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700316 }
317 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900318 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700319 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900320 nocrt: true,
321 system_shared_libs: [],
322 stl: "none",
323 vendor_available: true,
324 recovery_available: true,
325 }
326
Jiyong Park541142c2020-03-07 16:35:46 +0900327 cc_defaults {
328 name: "crt_defaults",
329 recovery_available: true,
330 vendor_available: true,
331 native_bridge_supported: true,
332 stl: "none",
333 apex_available: [
334 "//apex_available:platform",
335 "//apex_available:anyapex",
336 ],
337 }
338
Inseob Kimc0907f12019-02-08 21:00:45 +0900339 cc_object {
340 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900341 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900342 recovery_available: true,
343 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800344 native_bridge_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900345 min_sdk_version: "29",
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900346 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900347 }
348
349 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700350 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900351 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700352 recovery_available: true,
353 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800354 native_bridge_supported: true,
355 stl: "none",
Colin Cross815daf92019-05-14 16:05:20 -0700356 }
357
358 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900359 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900360 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900361 recovery_available: true,
362 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800363 native_bridge_supported: true,
364 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900365 }
366
367 cc_object {
368 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900369 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900370 recovery_available: true,
371 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800372 native_bridge_supported: true,
Jooyung Han749dc692020-04-15 11:03:39 +0900373 min_sdk_version: "29",
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900374 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900375 }
376
377 cc_object {
378 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900379 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900380 recovery_available: true,
381 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800382 native_bridge_supported: true,
383 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900384 }
385
386 cc_library {
387 name: "libprotobuf-cpp-lite",
388 }
Colin Crossf28329d2020-02-15 11:00:10 -0800389
390 cc_library {
391 name: "ndk_libunwind",
392 sdk_version: "current",
393 stl: "none",
394 system_shared_libs: [],
395 }
396
Dan Albertde5aade2020-06-30 12:32:51 -0700397 ndk_library {
398 name: "libc",
399 first_version: "minimum",
400 symbol_file: "libc.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800401 }
402
Dan Albertde5aade2020-06-30 12:32:51 -0700403 ndk_library {
404 name: "libm",
405 first_version: "minimum",
406 symbol_file: "libm.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800407 }
408
Dan Albertde5aade2020-06-30 12:32:51 -0700409 ndk_library {
410 name: "libdl",
411 first_version: "minimum",
412 symbol_file: "libdl.map.txt",
Colin Crossf28329d2020-02-15 11:00:10 -0800413 }
414
415 ndk_prebuilt_object {
416 name: "ndk_crtbegin_so.27",
417 sdk_version: "27",
418 }
419
420 ndk_prebuilt_object {
421 name: "ndk_crtend_so.27",
422 sdk_version: "27",
423 }
424
Colin Crossc511bc52020-04-07 16:50:32 +0000425 ndk_prebuilt_object {
426 name: "ndk_crtbegin_dynamic.27",
427 sdk_version: "27",
428 }
429
430 ndk_prebuilt_object {
431 name: "ndk_crtend_android.27",
432 sdk_version: "27",
433 }
434
Colin Crossf28329d2020-02-15 11:00:10 -0800435 ndk_prebuilt_shared_stl {
436 name: "ndk_libc++_shared",
437 }
438 `
439
Paul Duffina04c1072020-03-02 10:16:35 +0000440 for _, os := range oses {
441 if os == android.Fuchsia {
442 ret += `
Inseob Kimc0907f12019-02-08 21:00:45 +0900443 cc_library {
444 name: "libbioniccompat",
445 stl: "none",
446 }
447 cc_library {
448 name: "libcompiler_rt",
449 stl: "none",
450 }
451 `
Paul Duffina04c1072020-03-02 10:16:35 +0000452 }
453 if os == android.Windows {
454 ret += `
455 toolchain_library {
456 name: "libwinpthread",
457 host_supported: true,
458 enabled: false,
459 target: {
460 windows: {
461 enabled: true,
462 },
463 },
464 src: "",
465 }
466 `
467 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900468 }
469 return ret
470}
Colin Cross9a942872019-05-14 15:44:26 -0700471
Colin Crossf28329d2020-02-15 11:00:10 -0800472func GatherRequiredFilesForTest(fs map[string][]byte) {
Colin Crossf28329d2020-02-15 11:00:10 -0800473}
474
Colin Cross98be1bb2019-12-13 20:41:13 -0800475func TestConfig(buildDir string, os android.OsType, env map[string]string,
476 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700477
Colin Cross98be1bb2019-12-13 20:41:13 -0800478 // add some modules that are required by the compiler and/or linker
479 bp = bp + GatherRequiredDepsForTest(os)
480
Colin Cross2fce23a2020-06-07 17:02:48 -0700481 mockFS := map[string][]byte{}
Colin Cross98be1bb2019-12-13 20:41:13 -0800482
Colin Crossf28329d2020-02-15 11:00:10 -0800483 GatherRequiredFilesForTest(mockFS)
484
Colin Cross98be1bb2019-12-13 20:41:13 -0800485 for k, v := range fs {
486 mockFS[k] = v
487 }
488
489 var config android.Config
490 if os == android.Fuchsia {
491 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
492 } else {
493 config = android.TestArchConfig(buildDir, env, bp, mockFS)
494 }
495
496 return config
497}
498
499func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700500 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800501 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800502 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800503 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
504 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800505 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
506 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
507 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700508 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100509 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800510 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900511 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700512
Colin Cross9a942872019-05-14 15:44:26 -0700513 return ctx
514}