blob: e9739ff23da9ebaa6b3ada06d06052b90660a2c7 [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
70 toolchain_library {
71 name: "libclang_rt.builtins-i686-android",
72 vendor_available: true,
73 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080074 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090075 src: "",
76 }
77
78 toolchain_library {
79 name: "libclang_rt.builtins-x86_64-android",
80 vendor_available: true,
81 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080082 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090083 src: "",
84 }
85
86 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -070087 name: "libclang_rt.fuzzer-arm-android",
88 vendor_available: true,
89 recovery_available: true,
90 src: "",
91 }
92
93 toolchain_library {
94 name: "libclang_rt.fuzzer-aarch64-android",
95 vendor_available: true,
96 recovery_available: true,
97 src: "",
98 }
99
100 toolchain_library {
101 name: "libclang_rt.fuzzer-i686-android",
102 vendor_available: true,
103 recovery_available: true,
104 src: "",
105 }
106
107 toolchain_library {
108 name: "libclang_rt.fuzzer-x86_64-android",
109 vendor_available: true,
110 recovery_available: true,
111 src: "",
112 }
113
114 toolchain_library {
115 name: "libclang_rt.fuzzer-x86_64",
116 vendor_available: true,
117 recovery_available: true,
118 src: "",
119 }
120
Paul Duffind6867912019-12-19 14:38:36 +0000121 // Needed for sanitizer
122 cc_prebuilt_library_shared {
123 name: "libclang_rt.ubsan_standalone-aarch64-android",
124 vendor_available: true,
125 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800126 system_shared_libs: [],
Paul Duffind6867912019-12-19 14:38:36 +0000127 srcs: [""],
128 }
129
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700130 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900131 name: "libgcc",
132 vendor_available: true,
133 recovery_available: true,
134 src: "",
135 }
136
Yi Kongacee27c2019-03-29 20:05:14 -0700137 toolchain_library {
138 name: "libgcc_stripped",
139 vendor_available: true,
140 recovery_available: true,
141 src: "",
142 }
143
Inseob Kimc0907f12019-02-08 21:00:45 +0900144 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900145 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700146 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900147 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800148 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900149 system_shared_libs: [],
150 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800151 stubs: {
152 versions: ["27", "28", "29"],
153 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900154 }
155 llndk_library {
156 name: "libc",
157 symbol_file: "",
158 }
159 cc_library {
160 name: "libm",
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 },
169 apex_available: [
170 "//apex_available:platform",
171 "myapex"
172 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900173 }
174 llndk_library {
175 name: "libm",
176 symbol_file: "",
177 }
178 cc_library {
179 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700180 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900181 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800182 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900183 system_shared_libs: [],
184 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800185 stubs: {
186 versions: ["27", "28", "29"],
187 },
188 apex_available: [
189 "//apex_available:platform",
190 "myapex"
191 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900192 }
193 llndk_library {
194 name: "libdl",
195 symbol_file: "",
196 }
197 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900198 name: "libft2",
199 no_libcrt: true,
200 nocrt: true,
201 system_shared_libs: [],
202 recovery_available: true,
203 }
204 llndk_library {
205 name: "libft2",
206 symbol_file: "",
207 vendor_available: false,
208 }
209 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900210 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700211 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900212 nocrt: true,
213 system_shared_libs: [],
214 stl: "none",
215 vendor_available: true,
216 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900217 host_supported: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900218 apex_available: [
219 "//apex_available:platform",
220 "//apex_available:anyapex",
221 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900222 }
223 cc_library {
224 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700225 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900226 nocrt: true,
227 system_shared_libs: [],
228 stl: "none",
229 vendor_available: true,
230 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900231 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900232 vndk: {
233 enabled: true,
234 support_system_process: true,
235 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800236 apex_available: [
237 "//apex_available:platform",
238 "myapex"
239 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900240 }
241 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700242 name: "libc++demangle",
243 no_libcrt: true,
244 nocrt: true,
245 system_shared_libs: [],
246 stl: "none",
247 host_supported: false,
248 vendor_available: true,
249 recovery_available: true,
Jiyong Park541142c2020-03-07 16:35:46 +0900250 apex_available: [
251 "//apex_available:platform",
252 "//apex_available:anyapex",
253 ],
Dan Albert2da19cb2019-07-24 12:17:40 -0700254 }
255 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900256 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700257 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900258 nocrt: true,
259 system_shared_libs: [],
260 stl: "none",
261 vendor_available: true,
262 recovery_available: true,
263 }
264
Jiyong Park541142c2020-03-07 16:35:46 +0900265 cc_defaults {
266 name: "crt_defaults",
267 recovery_available: true,
268 vendor_available: true,
269 native_bridge_supported: true,
270 stl: "none",
271 apex_available: [
272 "//apex_available:platform",
273 "//apex_available:anyapex",
274 ],
275 }
276
Inseob Kimc0907f12019-02-08 21:00:45 +0900277 cc_object {
278 name: "crtbegin_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900279 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900280 recovery_available: true,
281 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800282 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900283 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900284 }
285
286 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700287 name: "crtbegin_dynamic",
Jiyong Park541142c2020-03-07 16:35:46 +0900288 defaults: ["crt_defaults"],
Colin Cross815daf92019-05-14 16:05:20 -0700289 recovery_available: true,
290 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800291 native_bridge_supported: true,
292 stl: "none",
Colin Cross815daf92019-05-14 16:05:20 -0700293 }
294
295 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900296 name: "crtbegin_static",
Jiyong Park541142c2020-03-07 16:35:46 +0900297 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 recovery_available: true,
299 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800300 native_bridge_supported: true,
301 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900302 }
303
304 cc_object {
305 name: "crtend_so",
Jiyong Park541142c2020-03-07 16:35:46 +0900306 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 recovery_available: true,
308 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800309 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900310 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900311 }
312
313 cc_object {
314 name: "crtend_android",
Jiyong Park541142c2020-03-07 16:35:46 +0900315 defaults: ["crt_defaults"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900316 recovery_available: true,
317 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800318 native_bridge_supported: true,
319 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900320 }
321
322 cc_library {
323 name: "libprotobuf-cpp-lite",
324 }
Colin Crossf28329d2020-02-15 11:00:10 -0800325
326 cc_library {
327 name: "ndk_libunwind",
328 sdk_version: "current",
329 stl: "none",
330 system_shared_libs: [],
331 }
332
333 cc_library {
334 name: "libc.ndk.current",
335 sdk_version: "current",
336 stl: "none",
337 system_shared_libs: [],
338 }
339
340 cc_library {
341 name: "libm.ndk.current",
342 sdk_version: "current",
343 stl: "none",
344 system_shared_libs: [],
345 }
346
347 cc_library {
348 name: "libdl.ndk.current",
349 sdk_version: "current",
350 stl: "none",
351 system_shared_libs: [],
352 }
353
354 ndk_prebuilt_object {
355 name: "ndk_crtbegin_so.27",
356 sdk_version: "27",
357 }
358
359 ndk_prebuilt_object {
360 name: "ndk_crtend_so.27",
361 sdk_version: "27",
362 }
363
364 ndk_prebuilt_shared_stl {
365 name: "ndk_libc++_shared",
366 }
367 `
368
Paul Duffina04c1072020-03-02 10:16:35 +0000369 for _, os := range oses {
370 if os == android.Fuchsia {
371 ret += `
Inseob Kimc0907f12019-02-08 21:00:45 +0900372 cc_library {
373 name: "libbioniccompat",
374 stl: "none",
375 }
376 cc_library {
377 name: "libcompiler_rt",
378 stl: "none",
379 }
380 `
Paul Duffina04c1072020-03-02 10:16:35 +0000381 }
382 if os == android.Windows {
383 ret += `
384 toolchain_library {
385 name: "libwinpthread",
386 host_supported: true,
387 enabled: false,
388 target: {
389 windows: {
390 enabled: true,
391 },
392 },
393 src: "",
394 }
395 `
396 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900397 }
398 return ret
399}
Colin Cross9a942872019-05-14 15:44:26 -0700400
Colin Crossf28329d2020-02-15 11:00:10 -0800401func GatherRequiredFilesForTest(fs map[string][]byte) {
402 fs["prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so"] = nil
403 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtbegin_so.o"] = nil
404 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtend_so.o"] = nil
405 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtbegin_so.o"] = nil
406 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtend_so.o"] = nil
407 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtbegin_so.o"] = nil
408 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtend_so.o"] = nil
409 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtbegin_so.o"] = nil
410 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtend_so.o"] = nil
411}
412
Colin Cross98be1bb2019-12-13 20:41:13 -0800413func TestConfig(buildDir string, os android.OsType, env map[string]string,
414 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700415
Colin Cross98be1bb2019-12-13 20:41:13 -0800416 // add some modules that are required by the compiler and/or linker
417 bp = bp + GatherRequiredDepsForTest(os)
418
419 mockFS := map[string][]byte{
420 "foo.c": nil,
421 "foo.lds": nil,
422 "bar.c": nil,
423 "baz.c": nil,
424 "baz.o": nil,
425 "a.proto": nil,
426 "b.aidl": nil,
427 "sub/c.aidl": nil,
428 "my_include": nil,
429 "foo.map.txt": nil,
430 "liba.so": nil,
431 }
432
Colin Crossf28329d2020-02-15 11:00:10 -0800433 GatherRequiredFilesForTest(mockFS)
434
Colin Cross98be1bb2019-12-13 20:41:13 -0800435 for k, v := range fs {
436 mockFS[k] = v
437 }
438
439 var config android.Config
440 if os == android.Fuchsia {
441 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
442 } else {
443 config = android.TestArchConfig(buildDir, env, bp, mockFS)
444 }
445
446 return config
447}
448
449func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700450 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800451 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800452 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800453 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900454 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800455 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800456 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
457 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
458 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000459 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700460 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800461 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900462 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700463
Colin Cross9a942872019-05-14 15:44:26 -0700464 return ctx
465}