blob: 60e5cf5968f31c4c121faef1b661e72837147b41 [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,
191 }
192 cc_library {
193 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700194 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900195 nocrt: true,
196 system_shared_libs: [],
197 stl: "none",
198 vendor_available: true,
199 recovery_available: true,
200 vndk: {
201 enabled: true,
202 support_system_process: true,
203 },
204 }
205 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700206 name: "libc++demangle",
207 no_libcrt: true,
208 nocrt: true,
209 system_shared_libs: [],
210 stl: "none",
211 host_supported: false,
212 vendor_available: true,
213 recovery_available: true,
214 }
215 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900216 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700217 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900218 nocrt: true,
219 system_shared_libs: [],
220 stl: "none",
221 vendor_available: true,
222 recovery_available: true,
223 }
224
225 cc_object {
226 name: "crtbegin_so",
227 recovery_available: true,
228 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900229 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900230 }
231
232 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700233 name: "crtbegin_dynamic",
234 recovery_available: true,
235 vendor_available: true,
236 }
237
238 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900239 name: "crtbegin_static",
240 recovery_available: true,
241 vendor_available: true,
242 }
243
244 cc_object {
245 name: "crtend_so",
246 recovery_available: true,
247 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900248 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900249 }
250
251 cc_object {
252 name: "crtend_android",
253 recovery_available: true,
254 vendor_available: true,
255 }
256
257 cc_library {
258 name: "libprotobuf-cpp-lite",
259 }
260 `
261 if os == android.Fuchsia {
262 ret += `
263 cc_library {
264 name: "libbioniccompat",
265 stl: "none",
266 }
267 cc_library {
268 name: "libcompiler_rt",
269 stl: "none",
270 }
271 `
272 }
273 return ret
274}
Colin Cross9a942872019-05-14 15:44:26 -0700275
Colin Cross98be1bb2019-12-13 20:41:13 -0800276func TestConfig(buildDir string, os android.OsType, env map[string]string,
277 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700278
Colin Cross98be1bb2019-12-13 20:41:13 -0800279 // add some modules that are required by the compiler and/or linker
280 bp = bp + GatherRequiredDepsForTest(os)
281
282 mockFS := map[string][]byte{
283 "foo.c": nil,
284 "foo.lds": nil,
285 "bar.c": nil,
286 "baz.c": nil,
287 "baz.o": nil,
288 "a.proto": nil,
289 "b.aidl": nil,
290 "sub/c.aidl": nil,
291 "my_include": nil,
292 "foo.map.txt": nil,
293 "liba.so": nil,
294 }
295
296 for k, v := range fs {
297 mockFS[k] = v
298 }
299
300 var config android.Config
301 if os == android.Fuchsia {
302 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
303 } else {
304 config = android.TestArchConfig(buildDir, env, bp, mockFS)
305 }
306
307 return config
308}
309
310func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700311 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800312 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800313 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800314 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900315 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800316 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800317 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
318 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
319 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000320 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700321 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800322 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim8471cda2019-11-15 09:59:12 +0900323 ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700324
Colin Cross9a942872019-05-14 15:44:26 -0700325 return ctx
326}