blob: b8a7eab34800c470fd9e47e2bc09ca1d24879cd7 [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,
Inseob Kimc0907f12019-02-08 21:00:45 +0900218 }
219 cc_library {
220 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700221 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900222 nocrt: true,
223 system_shared_libs: [],
224 stl: "none",
225 vendor_available: true,
226 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900227 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900228 vndk: {
229 enabled: true,
230 support_system_process: true,
231 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800232 apex_available: [
233 "//apex_available:platform",
234 "myapex"
235 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900236 }
237 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700238 name: "libc++demangle",
239 no_libcrt: true,
240 nocrt: true,
241 system_shared_libs: [],
242 stl: "none",
243 host_supported: false,
244 vendor_available: true,
245 recovery_available: true,
246 }
247 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900248 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700249 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900250 nocrt: true,
251 system_shared_libs: [],
252 stl: "none",
253 vendor_available: true,
254 recovery_available: true,
255 }
256
257 cc_object {
258 name: "crtbegin_so",
259 recovery_available: true,
260 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800261 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900262 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900263 }
264
265 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700266 name: "crtbegin_dynamic",
267 recovery_available: true,
268 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800269 native_bridge_supported: true,
270 stl: "none",
Colin Cross815daf92019-05-14 16:05:20 -0700271 }
272
273 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900274 name: "crtbegin_static",
275 recovery_available: true,
276 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800277 native_bridge_supported: true,
278 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900279 }
280
281 cc_object {
282 name: "crtend_so",
283 recovery_available: true,
284 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800285 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900286 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900287 }
288
289 cc_object {
290 name: "crtend_android",
291 recovery_available: true,
292 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800293 native_bridge_supported: true,
294 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900295 }
296
297 cc_library {
298 name: "libprotobuf-cpp-lite",
299 }
Colin Crossf28329d2020-02-15 11:00:10 -0800300
301 cc_library {
302 name: "ndk_libunwind",
303 sdk_version: "current",
304 stl: "none",
305 system_shared_libs: [],
306 }
307
308 cc_library {
309 name: "libc.ndk.current",
310 sdk_version: "current",
311 stl: "none",
312 system_shared_libs: [],
313 }
314
315 cc_library {
316 name: "libm.ndk.current",
317 sdk_version: "current",
318 stl: "none",
319 system_shared_libs: [],
320 }
321
322 cc_library {
323 name: "libdl.ndk.current",
324 sdk_version: "current",
325 stl: "none",
326 system_shared_libs: [],
327 }
328
329 ndk_prebuilt_object {
330 name: "ndk_crtbegin_so.27",
331 sdk_version: "27",
332 }
333
334 ndk_prebuilt_object {
335 name: "ndk_crtend_so.27",
336 sdk_version: "27",
337 }
338
339 ndk_prebuilt_shared_stl {
340 name: "ndk_libc++_shared",
341 }
342 `
343
Paul Duffina04c1072020-03-02 10:16:35 +0000344 for _, os := range oses {
345 if os == android.Fuchsia {
346 ret += `
Inseob Kimc0907f12019-02-08 21:00:45 +0900347 cc_library {
348 name: "libbioniccompat",
349 stl: "none",
350 }
351 cc_library {
352 name: "libcompiler_rt",
353 stl: "none",
354 }
355 `
Paul Duffina04c1072020-03-02 10:16:35 +0000356 }
357 if os == android.Windows {
358 ret += `
359 toolchain_library {
360 name: "libwinpthread",
361 host_supported: true,
362 enabled: false,
363 target: {
364 windows: {
365 enabled: true,
366 },
367 },
368 src: "",
369 }
370 `
371 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900372 }
373 return ret
374}
Colin Cross9a942872019-05-14 15:44:26 -0700375
Colin Crossf28329d2020-02-15 11:00:10 -0800376func GatherRequiredFilesForTest(fs map[string][]byte) {
377 fs["prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so"] = nil
378 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtbegin_so.o"] = nil
379 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtend_so.o"] = nil
380 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtbegin_so.o"] = nil
381 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtend_so.o"] = nil
382 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtbegin_so.o"] = nil
383 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtend_so.o"] = nil
384 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtbegin_so.o"] = nil
385 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtend_so.o"] = nil
386}
387
Colin Cross98be1bb2019-12-13 20:41:13 -0800388func TestConfig(buildDir string, os android.OsType, env map[string]string,
389 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700390
Colin Cross98be1bb2019-12-13 20:41:13 -0800391 // add some modules that are required by the compiler and/or linker
392 bp = bp + GatherRequiredDepsForTest(os)
393
394 mockFS := map[string][]byte{
395 "foo.c": nil,
396 "foo.lds": nil,
397 "bar.c": nil,
398 "baz.c": nil,
399 "baz.o": nil,
400 "a.proto": nil,
401 "b.aidl": nil,
402 "sub/c.aidl": nil,
403 "my_include": nil,
404 "foo.map.txt": nil,
405 "liba.so": nil,
406 }
407
Colin Crossf28329d2020-02-15 11:00:10 -0800408 GatherRequiredFilesForTest(mockFS)
409
Colin Cross98be1bb2019-12-13 20:41:13 -0800410 for k, v := range fs {
411 mockFS[k] = v
412 }
413
414 var config android.Config
415 if os == android.Fuchsia {
416 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
417 } else {
418 config = android.TestArchConfig(buildDir, env, bp, mockFS)
419 }
420
421 return config
422}
423
424func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700425 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800426 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800427 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800428 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900429 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800430 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800431 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
432 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
433 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000434 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700435 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800436 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900437 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700438
Colin Cross9a942872019-05-14 15:44:26 -0700439 return ctx
440}