blob: 4aacc05b76727d55790c6f9dacb523b96da745f4 [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)
28
29 ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
30 ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)
31 ctx.RegisterModuleType("cc_object", ObjectFactory)
Colin Crossf28329d2020-02-15 11:00:10 -080032 ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
33 ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000034}
35
Inseob Kimc0907f12019-02-08 21:00:45 +090036func GatherRequiredDepsForTest(os android.OsType) string {
37 ret := `
38 toolchain_library {
39 name: "libatomic",
40 vendor_available: true,
41 recovery_available: true,
42 src: "",
43 }
44
45 toolchain_library {
46 name: "libcompiler_rt-extras",
47 vendor_available: true,
48 recovery_available: true,
49 src: "",
50 }
51
52 toolchain_library {
53 name: "libclang_rt.builtins-arm-android",
54 vendor_available: true,
55 recovery_available: true,
56 src: "",
57 }
58
59 toolchain_library {
60 name: "libclang_rt.builtins-aarch64-android",
61 vendor_available: true,
62 recovery_available: true,
63 src: "",
64 }
65
66 toolchain_library {
67 name: "libclang_rt.builtins-i686-android",
68 vendor_available: true,
69 recovery_available: true,
70 src: "",
71 }
72
73 toolchain_library {
74 name: "libclang_rt.builtins-x86_64-android",
75 vendor_available: true,
76 recovery_available: true,
77 src: "",
78 }
79
80 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -070081 name: "libclang_rt.fuzzer-arm-android",
82 vendor_available: true,
83 recovery_available: true,
84 src: "",
85 }
86
87 toolchain_library {
88 name: "libclang_rt.fuzzer-aarch64-android",
89 vendor_available: true,
90 recovery_available: true,
91 src: "",
92 }
93
94 toolchain_library {
95 name: "libclang_rt.fuzzer-i686-android",
96 vendor_available: true,
97 recovery_available: true,
98 src: "",
99 }
100
101 toolchain_library {
102 name: "libclang_rt.fuzzer-x86_64-android",
103 vendor_available: true,
104 recovery_available: true,
105 src: "",
106 }
107
108 toolchain_library {
109 name: "libclang_rt.fuzzer-x86_64",
110 vendor_available: true,
111 recovery_available: true,
112 src: "",
113 }
114
Paul Duffind6867912019-12-19 14:38:36 +0000115 // Needed for sanitizer
116 cc_prebuilt_library_shared {
117 name: "libclang_rt.ubsan_standalone-aarch64-android",
118 vendor_available: true,
119 recovery_available: true,
120 srcs: [""],
121 }
122
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700123 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900124 name: "libgcc",
125 vendor_available: true,
126 recovery_available: true,
127 src: "",
128 }
129
Yi Kongacee27c2019-03-29 20:05:14 -0700130 toolchain_library {
131 name: "libgcc_stripped",
132 vendor_available: true,
133 recovery_available: true,
134 src: "",
135 }
136
Inseob Kimc0907f12019-02-08 21:00:45 +0900137 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900138 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700139 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900140 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800141 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900142 system_shared_libs: [],
143 recovery_available: true,
144 }
145 llndk_library {
146 name: "libc",
147 symbol_file: "",
148 }
149 cc_library {
150 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700151 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900152 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800153 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900154 system_shared_libs: [],
155 recovery_available: true,
156 }
157 llndk_library {
158 name: "libm",
159 symbol_file: "",
160 }
161 cc_library {
162 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700163 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900164 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800165 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900166 system_shared_libs: [],
167 recovery_available: true,
168 }
169 llndk_library {
170 name: "libdl",
171 symbol_file: "",
172 }
173 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900174 name: "libft2",
175 no_libcrt: true,
176 nocrt: true,
177 system_shared_libs: [],
178 recovery_available: true,
179 }
180 llndk_library {
181 name: "libft2",
182 symbol_file: "",
183 vendor_available: false,
184 }
185 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900186 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700187 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900188 nocrt: true,
189 system_shared_libs: [],
190 stl: "none",
191 vendor_available: true,
192 recovery_available: true,
193 }
194 cc_library {
195 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700196 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900197 nocrt: true,
198 system_shared_libs: [],
199 stl: "none",
200 vendor_available: true,
201 recovery_available: true,
202 vndk: {
203 enabled: true,
204 support_system_process: true,
205 },
206 }
207 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700208 name: "libc++demangle",
209 no_libcrt: true,
210 nocrt: true,
211 system_shared_libs: [],
212 stl: "none",
213 host_supported: false,
214 vendor_available: true,
215 recovery_available: true,
216 }
217 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900218 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700219 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900220 nocrt: true,
221 system_shared_libs: [],
222 stl: "none",
223 vendor_available: true,
224 recovery_available: true,
225 }
226
227 cc_object {
228 name: "crtbegin_so",
229 recovery_available: true,
230 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900231 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900232 }
233
234 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700235 name: "crtbegin_dynamic",
236 recovery_available: true,
237 vendor_available: true,
238 }
239
240 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900241 name: "crtbegin_static",
242 recovery_available: true,
243 vendor_available: true,
244 }
245
246 cc_object {
247 name: "crtend_so",
248 recovery_available: true,
249 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900250 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900251 }
252
253 cc_object {
254 name: "crtend_android",
255 recovery_available: true,
256 vendor_available: true,
257 }
258
259 cc_library {
260 name: "libprotobuf-cpp-lite",
261 }
Colin Crossf28329d2020-02-15 11:00:10 -0800262
263 cc_library {
264 name: "ndk_libunwind",
265 sdk_version: "current",
266 stl: "none",
267 system_shared_libs: [],
268 }
269
270 cc_library {
271 name: "libc.ndk.current",
272 sdk_version: "current",
273 stl: "none",
274 system_shared_libs: [],
275 }
276
277 cc_library {
278 name: "libm.ndk.current",
279 sdk_version: "current",
280 stl: "none",
281 system_shared_libs: [],
282 }
283
284 cc_library {
285 name: "libdl.ndk.current",
286 sdk_version: "current",
287 stl: "none",
288 system_shared_libs: [],
289 }
290
291 ndk_prebuilt_object {
292 name: "ndk_crtbegin_so.27",
293 sdk_version: "27",
294 }
295
296 ndk_prebuilt_object {
297 name: "ndk_crtend_so.27",
298 sdk_version: "27",
299 }
300
301 ndk_prebuilt_shared_stl {
302 name: "ndk_libc++_shared",
303 }
304 `
305
Inseob Kimc0907f12019-02-08 21:00:45 +0900306 if os == android.Fuchsia {
307 ret += `
308 cc_library {
309 name: "libbioniccompat",
310 stl: "none",
311 }
312 cc_library {
313 name: "libcompiler_rt",
314 stl: "none",
315 }
316 `
317 }
318 return ret
319}
Colin Cross9a942872019-05-14 15:44:26 -0700320
Colin Crossf28329d2020-02-15 11:00:10 -0800321func GatherRequiredFilesForTest(fs map[string][]byte) {
322 fs["prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so"] = nil
323 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtbegin_so.o"] = nil
324 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtend_so.o"] = nil
325 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtbegin_so.o"] = nil
326 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtend_so.o"] = nil
327 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtbegin_so.o"] = nil
328 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtend_so.o"] = nil
329 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtbegin_so.o"] = nil
330 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtend_so.o"] = nil
331}
332
Colin Cross98be1bb2019-12-13 20:41:13 -0800333func TestConfig(buildDir string, os android.OsType, env map[string]string,
334 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700335
Colin Cross98be1bb2019-12-13 20:41:13 -0800336 // add some modules that are required by the compiler and/or linker
337 bp = bp + GatherRequiredDepsForTest(os)
338
339 mockFS := map[string][]byte{
340 "foo.c": nil,
341 "foo.lds": nil,
342 "bar.c": nil,
343 "baz.c": nil,
344 "baz.o": nil,
345 "a.proto": nil,
346 "b.aidl": nil,
347 "sub/c.aidl": nil,
348 "my_include": nil,
349 "foo.map.txt": nil,
350 "liba.so": nil,
351 }
352
Colin Crossf28329d2020-02-15 11:00:10 -0800353 GatherRequiredFilesForTest(mockFS)
354
Colin Cross98be1bb2019-12-13 20:41:13 -0800355 for k, v := range fs {
356 mockFS[k] = v
357 }
358
359 var config android.Config
360 if os == android.Fuchsia {
361 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
362 } else {
363 config = android.TestArchConfig(buildDir, env, bp, mockFS)
364 }
365
366 return config
367}
368
369func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700370 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800371 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800372 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800373 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900374 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800375 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800376 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
377 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
378 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000379 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700380 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800381 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900382 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700383
Colin Cross9a942872019-05-14 15:44:26 -0700384 return ctx
385}