blob: d6f23913a597ba5cbea790b703825fb03f29bccd [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 Duffin6c26dc72019-12-19 15:02:40 +000026 RegisterLibraryBuildComponents(ctx)
27
28 ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
29 ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)
30 ctx.RegisterModuleType("cc_object", ObjectFactory)
Paul Duffin77980a82019-12-19 16:01:36 +000031}
32
Inseob Kimc0907f12019-02-08 21:00:45 +090033func GatherRequiredDepsForTest(os android.OsType) string {
34 ret := `
35 toolchain_library {
36 name: "libatomic",
37 vendor_available: true,
38 recovery_available: true,
39 src: "",
40 }
41
42 toolchain_library {
43 name: "libcompiler_rt-extras",
44 vendor_available: true,
45 recovery_available: true,
46 src: "",
47 }
48
49 toolchain_library {
50 name: "libclang_rt.builtins-arm-android",
51 vendor_available: true,
52 recovery_available: true,
53 src: "",
54 }
55
56 toolchain_library {
57 name: "libclang_rt.builtins-aarch64-android",
58 vendor_available: true,
59 recovery_available: true,
60 src: "",
61 }
62
63 toolchain_library {
64 name: "libclang_rt.builtins-i686-android",
65 vendor_available: true,
66 recovery_available: true,
67 src: "",
68 }
69
70 toolchain_library {
71 name: "libclang_rt.builtins-x86_64-android",
72 vendor_available: true,
73 recovery_available: true,
74 src: "",
75 }
76
77 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -070078 name: "libclang_rt.fuzzer-arm-android",
79 vendor_available: true,
80 recovery_available: true,
81 src: "",
82 }
83
84 toolchain_library {
85 name: "libclang_rt.fuzzer-aarch64-android",
86 vendor_available: true,
87 recovery_available: true,
88 src: "",
89 }
90
91 toolchain_library {
92 name: "libclang_rt.fuzzer-i686-android",
93 vendor_available: true,
94 recovery_available: true,
95 src: "",
96 }
97
98 toolchain_library {
99 name: "libclang_rt.fuzzer-x86_64-android",
100 vendor_available: true,
101 recovery_available: true,
102 src: "",
103 }
104
105 toolchain_library {
106 name: "libclang_rt.fuzzer-x86_64",
107 vendor_available: true,
108 recovery_available: true,
109 src: "",
110 }
111
Paul Duffind6867912019-12-19 14:38:36 +0000112 // Needed for sanitizer
113 cc_prebuilt_library_shared {
114 name: "libclang_rt.ubsan_standalone-aarch64-android",
115 vendor_available: true,
116 recovery_available: true,
117 srcs: [""],
118 }
119
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700120 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900121 name: "libgcc",
122 vendor_available: true,
123 recovery_available: true,
124 src: "",
125 }
126
Yi Kongacee27c2019-03-29 20:05:14 -0700127 toolchain_library {
128 name: "libgcc_stripped",
129 vendor_available: true,
130 recovery_available: true,
131 src: "",
132 }
133
Inseob Kimc0907f12019-02-08 21:00:45 +0900134 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900135 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700136 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900137 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800138 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900139 system_shared_libs: [],
140 recovery_available: true,
141 }
142 llndk_library {
143 name: "libc",
144 symbol_file: "",
145 }
146 cc_library {
147 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700148 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900149 nocrt: true,
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800150 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900151 system_shared_libs: [],
152 recovery_available: true,
153 }
154 llndk_library {
155 name: "libm",
156 symbol_file: "",
157 }
158 cc_library {
159 name: "libdl",
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,
165 }
166 llndk_library {
167 name: "libdl",
168 symbol_file: "",
169 }
170 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900171 name: "libft2",
172 no_libcrt: true,
173 nocrt: true,
174 system_shared_libs: [],
175 recovery_available: true,
176 }
177 llndk_library {
178 name: "libft2",
179 symbol_file: "",
180 vendor_available: false,
181 }
182 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900183 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700184 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900185 nocrt: true,
186 system_shared_libs: [],
187 stl: "none",
188 vendor_available: true,
189 recovery_available: true,
190 }
191 cc_library {
192 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700193 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 nocrt: true,
195 system_shared_libs: [],
196 stl: "none",
197 vendor_available: true,
198 recovery_available: true,
199 vndk: {
200 enabled: true,
201 support_system_process: true,
202 },
203 }
204 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700205 name: "libc++demangle",
206 no_libcrt: true,
207 nocrt: true,
208 system_shared_libs: [],
209 stl: "none",
210 host_supported: false,
211 vendor_available: true,
212 recovery_available: true,
213 }
214 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900215 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700216 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900217 nocrt: true,
218 system_shared_libs: [],
219 stl: "none",
220 vendor_available: true,
221 recovery_available: true,
222 }
223
224 cc_object {
225 name: "crtbegin_so",
226 recovery_available: true,
227 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900228 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900229 }
230
231 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700232 name: "crtbegin_dynamic",
233 recovery_available: true,
234 vendor_available: true,
235 }
236
237 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900238 name: "crtbegin_static",
239 recovery_available: true,
240 vendor_available: true,
241 }
242
243 cc_object {
244 name: "crtend_so",
245 recovery_available: true,
246 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900247 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900248 }
249
250 cc_object {
251 name: "crtend_android",
252 recovery_available: true,
253 vendor_available: true,
254 }
255
256 cc_library {
257 name: "libprotobuf-cpp-lite",
258 }
259 `
260 if os == android.Fuchsia {
261 ret += `
262 cc_library {
263 name: "libbioniccompat",
264 stl: "none",
265 }
266 cc_library {
267 name: "libcompiler_rt",
268 stl: "none",
269 }
270 `
271 }
272 return ret
273}
Colin Cross9a942872019-05-14 15:44:26 -0700274
Colin Cross98be1bb2019-12-13 20:41:13 -0800275func TestConfig(buildDir string, os android.OsType, env map[string]string,
276 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700277
Colin Cross98be1bb2019-12-13 20:41:13 -0800278 // add some modules that are required by the compiler and/or linker
279 bp = bp + GatherRequiredDepsForTest(os)
280
281 mockFS := map[string][]byte{
282 "foo.c": nil,
283 "foo.lds": nil,
284 "bar.c": nil,
285 "baz.c": nil,
286 "baz.o": nil,
287 "a.proto": nil,
288 "b.aidl": nil,
289 "sub/c.aidl": nil,
290 "my_include": nil,
291 "foo.map.txt": nil,
292 "liba.so": nil,
293 }
294
295 for k, v := range fs {
296 mockFS[k] = v
297 }
298
299 var config android.Config
300 if os == android.Fuchsia {
301 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
302 } else {
303 config = android.TestArchConfig(buildDir, env, bp, mockFS)
304 }
305
306 return config
307}
308
309func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700310 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800311 ctx.RegisterModuleType("cc_binary", BinaryFactory)
312 ctx.RegisterModuleType("cc_binary_host", binaryHostFactory)
313 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800314 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800315 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900316 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800317 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800318 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
319 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
320 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000321 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700322 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800323 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700324
Colin Cross9a942872019-05-14 15:44:26 -0700325 return ctx
326}