blob: 368580f23d6a073bc58abc4a6b175b5a4d60be7d [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,
Inseob Kim89db15d2020-02-03 18:06:46 +0900216 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900217 }
218 cc_library {
219 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700220 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900221 nocrt: true,
222 system_shared_libs: [],
223 stl: "none",
224 vendor_available: true,
225 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900226 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900227 vndk: {
228 enabled: true,
229 support_system_process: true,
230 },
Colin Crossf9aabd72020-02-15 11:29:50 -0800231 apex_available: [
232 "//apex_available:platform",
233 "myapex"
234 ],
Inseob Kimc0907f12019-02-08 21:00:45 +0900235 }
236 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700237 name: "libc++demangle",
238 no_libcrt: true,
239 nocrt: true,
240 system_shared_libs: [],
241 stl: "none",
242 host_supported: false,
243 vendor_available: true,
244 recovery_available: true,
245 }
246 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900247 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700248 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900249 nocrt: true,
250 system_shared_libs: [],
251 stl: "none",
252 vendor_available: true,
253 recovery_available: true,
254 }
255
256 cc_object {
257 name: "crtbegin_so",
258 recovery_available: true,
259 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800260 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900261 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900262 }
263
264 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700265 name: "crtbegin_dynamic",
266 recovery_available: true,
267 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800268 native_bridge_supported: true,
269 stl: "none",
Colin Cross815daf92019-05-14 16:05:20 -0700270 }
271
272 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900273 name: "crtbegin_static",
274 recovery_available: true,
275 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800276 native_bridge_supported: true,
277 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900278 }
279
280 cc_object {
281 name: "crtend_so",
282 recovery_available: true,
283 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800284 native_bridge_supported: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900285 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900286 }
287
288 cc_object {
289 name: "crtend_android",
290 recovery_available: true,
291 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800292 native_bridge_supported: true,
293 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900294 }
295
296 cc_library {
297 name: "libprotobuf-cpp-lite",
298 }
Colin Crossf28329d2020-02-15 11:00:10 -0800299
300 cc_library {
301 name: "ndk_libunwind",
302 sdk_version: "current",
303 stl: "none",
304 system_shared_libs: [],
305 }
306
307 cc_library {
308 name: "libc.ndk.current",
309 sdk_version: "current",
310 stl: "none",
311 system_shared_libs: [],
312 }
313
314 cc_library {
315 name: "libm.ndk.current",
316 sdk_version: "current",
317 stl: "none",
318 system_shared_libs: [],
319 }
320
321 cc_library {
322 name: "libdl.ndk.current",
323 sdk_version: "current",
324 stl: "none",
325 system_shared_libs: [],
326 }
327
328 ndk_prebuilt_object {
329 name: "ndk_crtbegin_so.27",
330 sdk_version: "27",
331 }
332
333 ndk_prebuilt_object {
334 name: "ndk_crtend_so.27",
335 sdk_version: "27",
336 }
337
338 ndk_prebuilt_shared_stl {
339 name: "ndk_libc++_shared",
340 }
341 `
342
Inseob Kimc0907f12019-02-08 21:00:45 +0900343 if os == android.Fuchsia {
344 ret += `
345 cc_library {
346 name: "libbioniccompat",
347 stl: "none",
348 }
349 cc_library {
350 name: "libcompiler_rt",
351 stl: "none",
352 }
353 `
354 }
355 return ret
356}
Colin Cross9a942872019-05-14 15:44:26 -0700357
Colin Crossf28329d2020-02-15 11:00:10 -0800358func GatherRequiredFilesForTest(fs map[string][]byte) {
359 fs["prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so"] = nil
360 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtbegin_so.o"] = nil
361 fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtend_so.o"] = nil
362 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtbegin_so.o"] = nil
363 fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtend_so.o"] = nil
364 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtbegin_so.o"] = nil
365 fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtend_so.o"] = nil
366 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtbegin_so.o"] = nil
367 fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtend_so.o"] = nil
368}
369
Colin Cross98be1bb2019-12-13 20:41:13 -0800370func TestConfig(buildDir string, os android.OsType, env map[string]string,
371 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700372
Colin Cross98be1bb2019-12-13 20:41:13 -0800373 // add some modules that are required by the compiler and/or linker
374 bp = bp + GatherRequiredDepsForTest(os)
375
376 mockFS := map[string][]byte{
377 "foo.c": nil,
378 "foo.lds": nil,
379 "bar.c": nil,
380 "baz.c": nil,
381 "baz.o": nil,
382 "a.proto": nil,
383 "b.aidl": nil,
384 "sub/c.aidl": nil,
385 "my_include": nil,
386 "foo.map.txt": nil,
387 "liba.so": nil,
388 }
389
Colin Crossf28329d2020-02-15 11:00:10 -0800390 GatherRequiredFilesForTest(mockFS)
391
Colin Cross98be1bb2019-12-13 20:41:13 -0800392 for k, v := range fs {
393 mockFS[k] = v
394 }
395
396 var config android.Config
397 if os == android.Fuchsia {
398 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
399 } else {
400 config = android.TestArchConfig(buildDir, env, bp, mockFS)
401 }
402
403 return config
404}
405
406func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700407 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800408 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800409 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800410 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900411 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800412 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800413 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
414 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
415 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000416 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700417 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800418 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900419 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700420
Colin Cross9a942872019-05-14 15:44:26 -0700421 return ctx
422}