blob: 611992070bf935a4e620219f8fd1b2088845582c [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 }
195 cc_library {
196 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700197 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900198 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800199 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900200 system_shared_libs: [],
201 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800202 stubs: {
203 versions: ["27", "28", "29"],
204 },
205 apex_available: [
206 "//apex_available:platform",
207 "myapex"
208 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900209 }
210 llndk_library {
211 name: "libdl",
212 symbol_file: "",
Colin Crossc511bc52020-04-07 16:50:32 +0000213 sdk_version: "current",
Inseob Kimc0907f12019-02-08 21:00:45 +0900214 }
215 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900216 name: "libft2",
217 no_libcrt: true,
218 nocrt: true,
219 system_shared_libs: [],
220 recovery_available: true,
221 }
222 llndk_library {
223 name: "libft2",
224 symbol_file: "",
225 vendor_available: false,
Colin Crossc511bc52020-04-07 16:50:32 +0000226 sdk_version: "current",
Jooyung Han097087b2019-10-22 19:32:18 +0900227 }
228 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900229 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700230 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900231 nocrt: true,
232 system_shared_libs: [],
233 stl: "none",
234 vendor_available: true,
235 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900236 host_supported: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900237 apex_available: [
238 "//apex_available:platform",
239 "//apex_available:anyapex",
240 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900241 }
242 cc_library {
243 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700244 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900245 nocrt: true,
246 system_shared_libs: [],
247 stl: "none",
248 vendor_available: true,
249 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900250 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900251 vndk: {
252 enabled: true,
253 support_system_process: true,
254 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800255 apex_available: [
256 "//apex_available:platform",
257 "myapex"
258 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900259 }
260 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700261 name: "libc++demangle",
262 no_libcrt: true,
263 nocrt: true,
264 system_shared_libs: [],
265 stl: "none",
266 host_supported: false,
267 vendor_available: true,
268 recovery_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900269 apex_available: [
270 "//apex_available:platform",
271 "//apex_available:anyapex",
272 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700273 }
274 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900275 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700276 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900277 nocrt: true,
278 system_shared_libs: [],
279 stl: "none",
280 vendor_available: true,
281 recovery_available: true,
282 }
283
Jiyong Park541142c2020-03-07 16:35:46 +0900284 cc_defaults {
285 name: "crt_defaults",
286 recovery_available: true,
287 vendor_available: true,
288 native_bridge_supported: true,
289 stl: "none",
290 apex_available: [
291 "//apex_available:platform",
292 "//apex_available:anyapex",
293 ],
294 }
295
Inseob Kimc0907f12019-02-08 21:00:45 +0900296 cc_object {
297 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900298 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900299 recovery_available: true,
300 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800301 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900302 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900303 }
304
305 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700306 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900307 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700308 recovery_available: true,
309 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800310 native_bridge_supported: true,
311 stl: "none",
Colin Cross815daf92019-05-14 16:05:20 -0700312 }
313
314 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900315 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900316 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900317 recovery_available: true,
318 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800319 native_bridge_supported: true,
320 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900321 }
322
323 cc_object {
324 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900325 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900326 recovery_available: true,
327 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800328 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900329 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900330 }
331
332 cc_object {
333 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900334 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900335 recovery_available: true,
336 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800337 native_bridge_supported: true,
338 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900339 }
340
341 cc_library {
342 name: "libprotobuf-cpp-lite",
343 }
Colin Crossf28329d2020-02-15 11:00:10 -0800344
345 cc_library {
346 name: "ndk_libunwind",
347 sdk_version: "current",
348 stl: "none",
349 system_shared_libs: [],
350 }
351
352 cc_library {
353 name: "libc.ndk.current",
354 sdk_version: "current",
355 stl: "none",
356 system_shared_libs: [],
357 }
358
359 cc_library {
360 name: "libm.ndk.current",
361 sdk_version: "current",
362 stl: "none",
363 system_shared_libs: [],
364 }
365
366 cc_library {
367 name: "libdl.ndk.current",
368 sdk_version: "current",
369 stl: "none",
370 system_shared_libs: [],
371 }
372
373 ndk_prebuilt_object {
374 name: "ndk_crtbegin_so.27",
375 sdk_version: "27",
376 }
377
378 ndk_prebuilt_object {
379 name: "ndk_crtend_so.27",
380 sdk_version: "27",
381 }
382
Colin Crossc511bc52020-04-07 16:50:32 +0000383 ndk_prebuilt_object {
384 name: "ndk_crtbegin_dynamic.27",
385 sdk_version: "27",
386 }
387
388 ndk_prebuilt_object {
389 name: "ndk_crtend_android.27",
390 sdk_version: "27",
391 }
392
Colin Crossf28329d2020-02-15 11:00:10 -0800393 ndk_prebuilt_shared_stl {
394 name: "ndk_libc++_shared",
395 }
396 `
397
Paul Duffina04c1072020-03-02 10:16:35 +0000398 for _, os := range oses {
399 if os == android.Fuchsia {
400 ret += `
Inseob Kimc0907f12019-02-08 21:00:45 +0900401 cc_library {
402 name: "libbioniccompat",
403 stl: "none",
404 }
405 cc_library {
406 name: "libcompiler_rt",
407 stl: "none",
408 }
409 `
Paul Duffina04c1072020-03-02 10:16:35 +0000410 }
411 if os == android.Windows {
412 ret += `
413 toolchain_library {
414 name: "libwinpthread",
415 host_supported: true,
416 enabled: false,
417 target: {
418 windows: {
419 enabled: true,
420 },
421 },
422 src: "",
423 }
424 `
425 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900426 }
427 return ret
428}
Colin Cross9a942872019-05-14 15:44:26 -0700429
Colin Crossf28329d2020-02-15 11:00:10 -0800430func GatherRequiredFilesForTest(fs map[string][]byte) {
431 fs["prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so"] = nil
432 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtbegin_so.o"] = nil
433 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtend_so.o"] = nil
434 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtbegin_so.o"] = nil
435 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtend_so.o"] = nil
436 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtbegin_so.o"] = nil
437 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtend_so.o"] = nil
438 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtbegin_so.o"] = nil
439 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtend_so.o"] = nil
440}
441
Colin Cross98be1bb2019-12-13 20:41:13 -0800442func TestConfig(buildDir string, os android.OsType, env map[string]string,
443 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700444
Colin Cross98be1bb2019-12-13 20:41:13 -0800445 // add some modules that are required by the compiler and/or linker
446 bp = bp + GatherRequiredDepsForTest(os)
447
448 mockFS := map[string][]byte{
449 "foo.c": nil,
450 "foo.lds": nil,
451 "bar.c": nil,
452 "baz.c": nil,
453 "baz.o": nil,
454 "a.proto": nil,
455 "b.aidl": nil,
456 "sub/c.aidl": nil,
457 "my_include": nil,
458 "foo.map.txt": nil,
459 "liba.so": nil,
460 }
461
Colin Crossf28329d2020-02-15 11:00:10 -0800462 GatherRequiredFilesForTest(mockFS)
463
Colin Cross98be1bb2019-12-13 20:41:13 -0800464 for k, v := range fs {
465 mockFS[k] = v
466 }
467
468 var config android.Config
469 if os == android.Fuchsia {
470 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
471 } else {
472 config = android.TestArchConfig(buildDir, env, bp, mockFS)
473 }
474
475 return config
476}
477
478func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700479 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800480 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800481 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800482 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900483 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800484 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800485 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
486 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
487 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700488 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffinc988c8e2020-04-29 18:27:14 +0100489 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -0800490 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900491 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700492
Colin Cross9a942872019-05-14 15:44:26 -0700493 return ctx
494}