blob: a7dde10b9167fa08a4a305e4a9bbd22f5b52eb9c [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,
Jiyong Park541142c2020-03-07 16:35:46 +0900276 apex_available: [
277 "//apex_available:platform",
278 "//apex_available:anyapex",
279 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900280 }
281 cc_library {
282 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700283 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900284 nocrt: true,
285 system_shared_libs: [],
286 stl: "none",
287 vendor_available: true,
288 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900289 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900290 vndk: {
291 enabled: true,
292 support_system_process: true,
293 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800294 apex_available: [
295 "//apex_available:platform",
296 "myapex"
297 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 }
299 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700300 name: "libc++demangle",
301 no_libcrt: true,
302 nocrt: true,
303 system_shared_libs: [],
304 stl: "none",
305 host_supported: false,
306 vendor_available: true,
307 recovery_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900308 apex_available: [
309 "//apex_available:platform",
310 "//apex_available:anyapex",
311 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700312 }
313 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900314 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700315 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900316 nocrt: true,
317 system_shared_libs: [],
318 stl: "none",
319 vendor_available: true,
320 recovery_available: true,
321 }
322
Jiyong Park541142c2020-03-07 16:35:46 +0900323 cc_defaults {
324 name: "crt_defaults",
325 recovery_available: true,
326 vendor_available: true,
327 native_bridge_supported: true,
328 stl: "none",
329 apex_available: [
330 "//apex_available:platform",
331 "//apex_available:anyapex",
332 ],
333 }
334
Inseob Kimc0907f12019-02-08 21:00:45 +0900335 cc_object {
336 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900337 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900338 recovery_available: true,
339 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800340 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900341 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900342 }
343
344 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700345 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900346 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700347 recovery_available: true,
348 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800349 native_bridge_supported: true,
350 stl: "none",
Colin Cross815daf92019-05-14 16:05:20 -0700351 }
352
353 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900354 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900355 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900356 recovery_available: true,
357 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800358 native_bridge_supported: true,
359 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900360 }
361
362 cc_object {
363 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900364 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900365 recovery_available: true,
366 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800367 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900368 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900369 }
370
371 cc_object {
372 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900373 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900374 recovery_available: true,
375 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800376 native_bridge_supported: true,
377 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900378 }
379
380 cc_library {
381 name: "libprotobuf-cpp-lite",
382 }
Colin Crossf28329d2020-02-15 11:00:10 -0800383
384 cc_library {
385 name: "ndk_libunwind",
386 sdk_version: "current",
387 stl: "none",
388 system_shared_libs: [],
389 }
390
391 cc_library {
392 name: "libc.ndk.current",
393 sdk_version: "current",
394 stl: "none",
395 system_shared_libs: [],
396 }
397
398 cc_library {
399 name: "libm.ndk.current",
400 sdk_version: "current",
401 stl: "none",
402 system_shared_libs: [],
403 }
404
405 cc_library {
406 name: "libdl.ndk.current",
407 sdk_version: "current",
408 stl: "none",
409 system_shared_libs: [],
410 }
411
412 ndk_prebuilt_object {
413 name: "ndk_crtbegin_so.27",
414 sdk_version: "27",
415 }
416
417 ndk_prebuilt_object {
418 name: "ndk_crtend_so.27",
419 sdk_version: "27",
420 }
421
Colin Crossc511bc52020-04-07 16:50:32 +0000422 ndk_prebuilt_object {
423 name: "ndk_crtbegin_dynamic.27",
424 sdk_version: "27",
425 }
426
427 ndk_prebuilt_object {
428 name: "ndk_crtend_android.27",
429 sdk_version: "27",
430 }
431
Colin Crossf28329d2020-02-15 11:00:10 -0800432 ndk_prebuilt_shared_stl {
433 name: "ndk_libc++_shared",
434 }
435 `
436
Paul Duffina04c1072020-03-02 10:16:35 +0000437 for _, os := range oses {
438 if os == android.Fuchsia {
439 ret += `
Inseob Kimc0907f12019-02-08 21:00:45 +0900440 cc_library {
441 name: "libbioniccompat",
442 stl: "none",
443 }
444 cc_library {
445 name: "libcompiler_rt",
446 stl: "none",
447 }
448 `
Paul Duffina04c1072020-03-02 10:16:35 +0000449 }
450 if os == android.Windows {
451 ret += `
452 toolchain_library {
453 name: "libwinpthread",
454 host_supported: true,
455 enabled: false,
456 target: {
457 windows: {
458 enabled: true,
459 },
460 },
461 src: "",
462 }
463 `
464 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900465 }
466 return ret
467}
Colin Cross9a942872019-05-14 15:44:26 -0700468
Colin Crossf28329d2020-02-15 11:00:10 -0800469func GatherRequiredFilesForTest(fs map[string][]byte) {
470 fs["prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so"] = nil
471 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtbegin_so.o"] = nil
472 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtend_so.o"] = nil
473 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtbegin_so.o"] = nil
474 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtend_so.o"] = nil
475 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtbegin_so.o"] = nil
476 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtend_so.o"] = nil
477 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtbegin_so.o"] = nil
478 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtend_so.o"] = nil
479}
480
Colin Cross98be1bb2019-12-13 20:41:13 -0800481func TestConfig(buildDir string, os android.OsType, env map[string]string,
482 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700483
Colin Cross98be1bb2019-12-13 20:41:13 -0800484 // add some modules that are required by the compiler and/or linker
485 bp = bp + GatherRequiredDepsForTest(os)
486
487 mockFS := map[string][]byte{
488 "foo.c": nil,
489 "foo.lds": nil,
490 "bar.c": nil,
491 "baz.c": nil,
492 "baz.o": nil,
493 "a.proto": nil,
494 "b.aidl": nil,
495 "sub/c.aidl": nil,
496 "my_include": nil,
497 "foo.map.txt": nil,
498 "liba.so": nil,
499 }
500
Colin Crossf28329d2020-02-15 11:00:10 -0800501 GatherRequiredFilesForTest(mockFS)
502
Colin Cross98be1bb2019-12-13 20:41:13 -0800503 for k, v := range fs {
504 mockFS[k] = v
505 }
506
507 var config android.Config
508 if os == android.Fuchsia {
509 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
510 } else {
511 config = android.TestArchConfig(buildDir, env, bp, mockFS)
512 }
513
514 return config
515}
516
517func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700518 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800519 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800520 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800521 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900522 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800523 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800524 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
525 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
526 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000527 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700528 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800529 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900530 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700531
Colin Cross9a942872019-05-14 15:44:26 -0700532 return ctx
533}