blob: 7b0305f64cb2b7af694f34a2c09661168b94357f [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,
Colin Crossf9aabd72020-02-15 11:29:50 -080042 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090043 src: "",
44 }
45
46 toolchain_library {
47 name: "libcompiler_rt-extras",
48 vendor_available: true,
49 recovery_available: true,
50 src: "",
51 }
52
53 toolchain_library {
54 name: "libclang_rt.builtins-arm-android",
55 vendor_available: true,
56 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080057 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090058 src: "",
59 }
60
61 toolchain_library {
62 name: "libclang_rt.builtins-aarch64-android",
63 vendor_available: true,
64 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080065 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090066 src: "",
67 }
68
69 toolchain_library {
70 name: "libclang_rt.builtins-i686-android",
71 vendor_available: true,
72 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080073 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090074 src: "",
75 }
76
77 toolchain_library {
78 name: "libclang_rt.builtins-x86_64-android",
79 vendor_available: true,
80 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -080081 native_bridge_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +090082 src: "",
83 }
84
85 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -070086 name: "libclang_rt.fuzzer-arm-android",
87 vendor_available: true,
88 recovery_available: true,
89 src: "",
90 }
91
92 toolchain_library {
93 name: "libclang_rt.fuzzer-aarch64-android",
94 vendor_available: true,
95 recovery_available: true,
96 src: "",
97 }
98
99 toolchain_library {
100 name: "libclang_rt.fuzzer-i686-android",
101 vendor_available: true,
102 recovery_available: true,
103 src: "",
104 }
105
106 toolchain_library {
107 name: "libclang_rt.fuzzer-x86_64-android",
108 vendor_available: true,
109 recovery_available: true,
110 src: "",
111 }
112
113 toolchain_library {
114 name: "libclang_rt.fuzzer-x86_64",
115 vendor_available: true,
116 recovery_available: true,
117 src: "",
118 }
119
Paul Duffind6867912019-12-19 14:38:36 +0000120 // Needed for sanitizer
121 cc_prebuilt_library_shared {
122 name: "libclang_rt.ubsan_standalone-aarch64-android",
123 vendor_available: true,
124 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800125 system_shared_libs: [],
Paul Duffind6867912019-12-19 14:38:36 +0000126 srcs: [""],
127 }
128
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700129 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900130 name: "libgcc",
131 vendor_available: true,
132 recovery_available: true,
133 src: "",
134 }
135
Yi Kongacee27c2019-03-29 20:05:14 -0700136 toolchain_library {
137 name: "libgcc_stripped",
138 vendor_available: true,
139 recovery_available: true,
140 src: "",
141 }
142
Inseob Kimc0907f12019-02-08 21:00:45 +0900143 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900144 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700145 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900146 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800147 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900148 system_shared_libs: [],
149 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800150 stubs: {
151 versions: ["27", "28", "29"],
152 },
Inseob Kimc0907f12019-02-08 21:00:45 +0900153 }
154 llndk_library {
155 name: "libc",
156 symbol_file: "",
157 }
158 cc_library {
159 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700160 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900161 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800162 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900163 system_shared_libs: [],
164 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800165 stubs: {
166 versions: ["27", "28", "29"],
167 },
168 apex_available: [
169 "//apex_available:platform",
170 "myapex"
171 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900172 }
173 llndk_library {
174 name: "libm",
175 symbol_file: "",
176 }
177 cc_library {
178 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700179 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900180 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800181 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900182 system_shared_libs: [],
183 recovery_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800184 stubs: {
185 versions: ["27", "28", "29"],
186 },
187 apex_available: [
188 "//apex_available:platform",
189 "myapex"
190 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900191 }
192 llndk_library {
193 name: "libdl",
194 symbol_file: "",
195 }
196 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900197 name: "libft2",
198 no_libcrt: true,
199 nocrt: true,
200 system_shared_libs: [],
201 recovery_available: true,
202 }
203 llndk_library {
204 name: "libft2",
205 symbol_file: "",
206 vendor_available: false,
207 }
208 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900209 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700210 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900211 nocrt: true,
212 system_shared_libs: [],
213 stl: "none",
214 vendor_available: true,
215 recovery_available: true,
216 }
217 cc_library {
218 name: "libc++",
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 vndk: {
226 enabled: true,
227 support_system_process: true,
228 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800229 apex_available: [
230 "//apex_available:platform",
231 "myapex"
232 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900233 }
234 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700235 name: "libc++demangle",
236 no_libcrt: true,
237 nocrt: true,
238 system_shared_libs: [],
239 stl: "none",
240 host_supported: false,
241 vendor_available: true,
242 recovery_available: true,
243 }
244 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900245 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700246 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900247 nocrt: true,
248 system_shared_libs: [],
249 stl: "none",
250 vendor_available: true,
251 recovery_available: true,
252 }
253
254 cc_object {
255 name: "crtbegin_so",
256 recovery_available: true,
257 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800258 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900259 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900260 }
261
262 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700263 name: "crtbegin_dynamic",
264 recovery_available: true,
265 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800266 native_bridge_supported: true,
267 stl: "none",
Colin Cross815daf92019-05-14 16:05:20 -0700268 }
269
270 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900271 name: "crtbegin_static",
272 recovery_available: true,
273 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800274 native_bridge_supported: true,
275 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900276 }
277
278 cc_object {
279 name: "crtend_so",
280 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 {
287 name: "crtend_android",
288 recovery_available: true,
289 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800290 native_bridge_supported: true,
291 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900292 }
293
294 cc_library {
295 name: "libprotobuf-cpp-lite",
296 }
Colin Crossf28329d2020-02-15 11:00:10 -0800297
298 cc_library {
299 name: "ndk_libunwind",
300 sdk_version: "current",
301 stl: "none",
302 system_shared_libs: [],
303 }
304
305 cc_library {
306 name: "libc.ndk.current",
307 sdk_version: "current",
308 stl: "none",
309 system_shared_libs: [],
310 }
311
312 cc_library {
313 name: "libm.ndk.current",
314 sdk_version: "current",
315 stl: "none",
316 system_shared_libs: [],
317 }
318
319 cc_library {
320 name: "libdl.ndk.current",
321 sdk_version: "current",
322 stl: "none",
323 system_shared_libs: [],
324 }
325
326 ndk_prebuilt_object {
327 name: "ndk_crtbegin_so.27",
328 sdk_version: "27",
329 }
330
331 ndk_prebuilt_object {
332 name: "ndk_crtend_so.27",
333 sdk_version: "27",
334 }
335
336 ndk_prebuilt_shared_stl {
337 name: "ndk_libc++_shared",
338 }
339 `
340
Inseob Kimc0907f12019-02-08 21:00:45 +0900341 if os == android.Fuchsia {
342 ret += `
343 cc_library {
344 name: "libbioniccompat",
345 stl: "none",
346 }
347 cc_library {
348 name: "libcompiler_rt",
349 stl: "none",
350 }
351 `
352 }
353 return ret
354}
Colin Cross9a942872019-05-14 15:44:26 -0700355
Colin Crossf28329d2020-02-15 11:00:10 -0800356func GatherRequiredFilesForTest(fs map[string][]byte) {
357 fs["prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so"] = nil
358 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtbegin_so.o"] = nil
359 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtend_so.o"] = nil
360 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtbegin_so.o"] = nil
361 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtend_so.o"] = nil
362 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtbegin_so.o"] = nil
363 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtend_so.o"] = nil
364 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtbegin_so.o"] = nil
365 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtend_so.o"] = nil
366}
367
Colin Cross98be1bb2019-12-13 20:41:13 -0800368func TestConfig(buildDir string, os android.OsType, env map[string]string,
369 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700370
Colin Cross98be1bb2019-12-13 20:41:13 -0800371 // add some modules that are required by the compiler and/or linker
372 bp = bp + GatherRequiredDepsForTest(os)
373
374 mockFS := map[string][]byte{
375 "foo.c": nil,
376 "foo.lds": nil,
377 "bar.c": nil,
378 "baz.c": nil,
379 "baz.o": nil,
380 "a.proto": nil,
381 "b.aidl": nil,
382 "sub/c.aidl": nil,
383 "my_include": nil,
384 "foo.map.txt": nil,
385 "liba.so": nil,
386 }
387
Colin Crossf28329d2020-02-15 11:00:10 -0800388 GatherRequiredFilesForTest(mockFS)
389
Colin Cross98be1bb2019-12-13 20:41:13 -0800390 for k, v := range fs {
391 mockFS[k] = v
392 }
393
394 var config android.Config
395 if os == android.Fuchsia {
396 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
397 } else {
398 config = android.TestArchConfig(buildDir, env, bp, mockFS)
399 }
400
401 return config
402}
403
404func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700405 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800406 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800407 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800408 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900409 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800410 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800411 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
412 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
413 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000414 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700415 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800416 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900417 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700418
Colin Cross9a942872019-05-14 15:44:26 -0700419 return ctx
420}