blob: 198a346f541578866738860bf4f8528ec6dc9322 [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,
139 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,
150 system_shared_libs: [],
151 recovery_available: true,
152 }
153 llndk_library {
154 name: "libm",
155 symbol_file: "",
156 }
157 cc_library {
158 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700159 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900160 nocrt: true,
161 system_shared_libs: [],
162 recovery_available: true,
163 }
164 llndk_library {
165 name: "libdl",
166 symbol_file: "",
167 }
168 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900169 name: "libft2",
170 no_libcrt: true,
171 nocrt: true,
172 system_shared_libs: [],
173 recovery_available: true,
174 }
175 llndk_library {
176 name: "libft2",
177 symbol_file: "",
178 vendor_available: false,
179 }
180 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900181 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700182 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900183 nocrt: true,
184 system_shared_libs: [],
185 stl: "none",
186 vendor_available: true,
187 recovery_available: true,
188 }
189 cc_library {
190 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700191 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900192 nocrt: true,
193 system_shared_libs: [],
194 stl: "none",
195 vendor_available: true,
196 recovery_available: true,
197 vndk: {
198 enabled: true,
199 support_system_process: true,
200 },
201 }
202 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700203 name: "libc++demangle",
204 no_libcrt: true,
205 nocrt: true,
206 system_shared_libs: [],
207 stl: "none",
208 host_supported: false,
209 vendor_available: true,
210 recovery_available: true,
211 }
212 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900213 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700214 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900215 nocrt: true,
216 system_shared_libs: [],
217 stl: "none",
218 vendor_available: true,
219 recovery_available: true,
220 }
221
222 cc_object {
223 name: "crtbegin_so",
224 recovery_available: true,
225 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900226 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900227 }
228
229 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700230 name: "crtbegin_dynamic",
231 recovery_available: true,
232 vendor_available: true,
233 }
234
235 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900236 name: "crtbegin_static",
237 recovery_available: true,
238 vendor_available: true,
239 }
240
241 cc_object {
242 name: "crtend_so",
243 recovery_available: true,
244 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900245 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900246 }
247
248 cc_object {
249 name: "crtend_android",
250 recovery_available: true,
251 vendor_available: true,
252 }
253
254 cc_library {
255 name: "libprotobuf-cpp-lite",
256 }
257 `
258 if os == android.Fuchsia {
259 ret += `
260 cc_library {
261 name: "libbioniccompat",
262 stl: "none",
263 }
264 cc_library {
265 name: "libcompiler_rt",
266 stl: "none",
267 }
268 `
269 }
270 return ret
271}
Colin Cross9a942872019-05-14 15:44:26 -0700272
Colin Cross98be1bb2019-12-13 20:41:13 -0800273func TestConfig(buildDir string, os android.OsType, env map[string]string,
274 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700275
Colin Cross98be1bb2019-12-13 20:41:13 -0800276 // add some modules that are required by the compiler and/or linker
277 bp = bp + GatherRequiredDepsForTest(os)
278
279 mockFS := map[string][]byte{
280 "foo.c": nil,
281 "foo.lds": nil,
282 "bar.c": nil,
283 "baz.c": nil,
284 "baz.o": nil,
285 "a.proto": nil,
286 "b.aidl": nil,
287 "sub/c.aidl": nil,
288 "my_include": nil,
289 "foo.map.txt": nil,
290 "liba.so": nil,
291 }
292
293 for k, v := range fs {
294 mockFS[k] = v
295 }
296
297 var config android.Config
298 if os == android.Fuchsia {
299 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
300 } else {
301 config = android.TestArchConfig(buildDir, env, bp, mockFS)
302 }
303
304 return config
305}
306
307func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700308 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800309 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800310 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800311 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900312 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800313 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800314 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
315 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
316 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000317 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700318 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800319 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700320
Colin Cross9a942872019-05-14 15:44:26 -0700321 return ctx
322}