blob: aceb8c8b47cf058f094ca51bc259db8f2f66c7c9 [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)
Paul Duffin77980a82019-12-19 16:01:36 +000032}
33
Inseob Kimc0907f12019-02-08 21:00:45 +090034func GatherRequiredDepsForTest(os android.OsType) string {
35 ret := `
36 toolchain_library {
37 name: "libatomic",
38 vendor_available: true,
39 recovery_available: true,
40 src: "",
41 }
42
43 toolchain_library {
44 name: "libcompiler_rt-extras",
45 vendor_available: true,
46 recovery_available: true,
47 src: "",
48 }
49
50 toolchain_library {
51 name: "libclang_rt.builtins-arm-android",
52 vendor_available: true,
53 recovery_available: true,
54 src: "",
55 }
56
57 toolchain_library {
58 name: "libclang_rt.builtins-aarch64-android",
59 vendor_available: true,
60 recovery_available: true,
61 src: "",
62 }
63
64 toolchain_library {
65 name: "libclang_rt.builtins-i686-android",
66 vendor_available: true,
67 recovery_available: true,
68 src: "",
69 }
70
71 toolchain_library {
72 name: "libclang_rt.builtins-x86_64-android",
73 vendor_available: true,
74 recovery_available: true,
75 src: "",
76 }
77
78 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -070079 name: "libclang_rt.fuzzer-arm-android",
80 vendor_available: true,
81 recovery_available: true,
82 src: "",
83 }
84
85 toolchain_library {
86 name: "libclang_rt.fuzzer-aarch64-android",
87 vendor_available: true,
88 recovery_available: true,
89 src: "",
90 }
91
92 toolchain_library {
93 name: "libclang_rt.fuzzer-i686-android",
94 vendor_available: true,
95 recovery_available: true,
96 src: "",
97 }
98
99 toolchain_library {
100 name: "libclang_rt.fuzzer-x86_64-android",
101 vendor_available: true,
102 recovery_available: true,
103 src: "",
104 }
105
106 toolchain_library {
107 name: "libclang_rt.fuzzer-x86_64",
108 vendor_available: true,
109 recovery_available: true,
110 src: "",
111 }
112
Paul Duffind6867912019-12-19 14:38:36 +0000113 // Needed for sanitizer
114 cc_prebuilt_library_shared {
115 name: "libclang_rt.ubsan_standalone-aarch64-android",
116 vendor_available: true,
117 recovery_available: true,
118 srcs: [""],
119 }
120
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700121 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900122 name: "libgcc",
123 vendor_available: true,
124 recovery_available: true,
125 src: "",
126 }
127
Yi Kongacee27c2019-03-29 20:05:14 -0700128 toolchain_library {
129 name: "libgcc_stripped",
130 vendor_available: true,
131 recovery_available: true,
132 src: "",
133 }
134
Inseob Kimc0907f12019-02-08 21:00:45 +0900135 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900136 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700137 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900138 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800139 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900140 system_shared_libs: [],
141 recovery_available: true,
142 }
143 llndk_library {
144 name: "libc",
145 symbol_file: "",
146 }
147 cc_library {
148 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700149 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900150 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800151 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900152 system_shared_libs: [],
153 recovery_available: true,
154 }
155 llndk_library {
156 name: "libm",
157 symbol_file: "",
158 }
159 cc_library {
160 name: "libdl",
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,
166 }
167 llndk_library {
168 name: "libdl",
169 symbol_file: "",
170 }
171 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900172 name: "libft2",
173 no_libcrt: true,
174 nocrt: true,
175 system_shared_libs: [],
176 recovery_available: true,
177 }
178 llndk_library {
179 name: "libft2",
180 symbol_file: "",
181 vendor_available: false,
182 }
183 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900184 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700185 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900186 nocrt: true,
187 system_shared_libs: [],
188 stl: "none",
189 vendor_available: true,
190 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900191 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900192 }
193 cc_library {
194 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700195 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900196 nocrt: true,
197 system_shared_libs: [],
198 stl: "none",
199 vendor_available: true,
200 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900201 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900202 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 }
262 `
263 if os == android.Fuchsia {
264 ret += `
265 cc_library {
266 name: "libbioniccompat",
267 stl: "none",
268 }
269 cc_library {
270 name: "libcompiler_rt",
271 stl: "none",
272 }
273 `
274 }
275 return ret
276}
Colin Cross9a942872019-05-14 15:44:26 -0700277
Colin Cross98be1bb2019-12-13 20:41:13 -0800278func TestConfig(buildDir string, os android.OsType, env map[string]string,
279 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700280
Colin Cross98be1bb2019-12-13 20:41:13 -0800281 // add some modules that are required by the compiler and/or linker
282 bp = bp + GatherRequiredDepsForTest(os)
283
284 mockFS := map[string][]byte{
285 "foo.c": nil,
286 "foo.lds": nil,
287 "bar.c": nil,
288 "baz.c": nil,
289 "baz.o": nil,
290 "a.proto": nil,
291 "b.aidl": nil,
292 "sub/c.aidl": nil,
293 "my_include": nil,
294 "foo.map.txt": nil,
295 "liba.so": nil,
296 }
297
298 for k, v := range fs {
299 mockFS[k] = v
300 }
301
302 var config android.Config
303 if os == android.Fuchsia {
304 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
305 } else {
306 config = android.TestArchConfig(buildDir, env, bp, mockFS)
307 }
308
309 return config
310}
311
312func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700313 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800314 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800315 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800316 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900317 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800318 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800319 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
320 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
321 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000322 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700323 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800324 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900325 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700326
Colin Cross9a942872019-05-14 15:44:26 -0700327 return ctx
328}