blob: bc310772125524d1eb0f9685306ad8ccab7aef36 [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,
138 system_shared_libs: [],
139 recovery_available: true,
140 }
141 llndk_library {
142 name: "libc",
143 symbol_file: "",
144 }
145 cc_library {
146 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700147 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900148 nocrt: true,
149 system_shared_libs: [],
150 recovery_available: true,
151 }
152 llndk_library {
153 name: "libm",
154 symbol_file: "",
155 }
156 cc_library {
157 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700158 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900159 nocrt: true,
160 system_shared_libs: [],
161 recovery_available: true,
162 }
163 llndk_library {
164 name: "libdl",
165 symbol_file: "",
166 }
167 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900168 name: "libft2",
169 no_libcrt: true,
170 nocrt: true,
171 system_shared_libs: [],
172 recovery_available: true,
173 }
174 llndk_library {
175 name: "libft2",
176 symbol_file: "",
177 vendor_available: false,
178 }
179 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900180 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700181 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900182 nocrt: true,
183 system_shared_libs: [],
184 stl: "none",
185 vendor_available: true,
186 recovery_available: true,
187 }
188 cc_library {
189 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700190 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900191 nocrt: true,
192 system_shared_libs: [],
193 stl: "none",
194 vendor_available: true,
195 recovery_available: true,
196 vndk: {
197 enabled: true,
198 support_system_process: true,
199 },
200 }
201 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700202 name: "libc++demangle",
203 no_libcrt: true,
204 nocrt: true,
205 system_shared_libs: [],
206 stl: "none",
207 host_supported: false,
208 vendor_available: true,
209 recovery_available: true,
210 }
211 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900212 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700213 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900214 nocrt: true,
215 system_shared_libs: [],
216 stl: "none",
217 vendor_available: true,
218 recovery_available: true,
219 }
220
221 cc_object {
222 name: "crtbegin_so",
223 recovery_available: true,
224 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900225 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900226 }
227
228 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700229 name: "crtbegin_dynamic",
230 recovery_available: true,
231 vendor_available: true,
232 }
233
234 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900235 name: "crtbegin_static",
236 recovery_available: true,
237 vendor_available: true,
238 }
239
240 cc_object {
241 name: "crtend_so",
242 recovery_available: true,
243 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900244 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900245 }
246
247 cc_object {
248 name: "crtend_android",
249 recovery_available: true,
250 vendor_available: true,
251 }
252
253 cc_library {
254 name: "libprotobuf-cpp-lite",
255 }
256 `
257 if os == android.Fuchsia {
258 ret += `
259 cc_library {
260 name: "libbioniccompat",
261 stl: "none",
262 }
263 cc_library {
264 name: "libcompiler_rt",
265 stl: "none",
266 }
267 `
268 }
269 return ret
270}
Colin Cross9a942872019-05-14 15:44:26 -0700271
Colin Cross98be1bb2019-12-13 20:41:13 -0800272func TestConfig(buildDir string, os android.OsType, env map[string]string,
273 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700274
Colin Cross98be1bb2019-12-13 20:41:13 -0800275 // add some modules that are required by the compiler and/or linker
276 bp = bp + GatherRequiredDepsForTest(os)
277
278 mockFS := map[string][]byte{
279 "foo.c": nil,
280 "foo.lds": nil,
281 "bar.c": nil,
282 "baz.c": nil,
283 "baz.o": nil,
284 "a.proto": nil,
285 "b.aidl": nil,
286 "sub/c.aidl": nil,
287 "my_include": nil,
288 "foo.map.txt": nil,
289 "liba.so": nil,
290 }
291
292 for k, v := range fs {
293 mockFS[k] = v
294 }
295
296 var config android.Config
297 if os == android.Fuchsia {
298 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
299 } else {
300 config = android.TestArchConfig(buildDir, env, bp, mockFS)
301 }
302
303 return config
304}
305
306func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700307 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800308 ctx.RegisterModuleType("cc_binary", BinaryFactory)
309 ctx.RegisterModuleType("cc_binary_host", binaryHostFactory)
310 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800311 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800312 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900313 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800314 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800315 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
316 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
317 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000318 RegisterRequiredBuildComponentsForTest(ctx)
Colin Crosse1bb5d02019-09-24 14:55:04 -0700319 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800320 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700321
Colin Cross9a942872019-05-14 15:44:26 -0700322 return ctx
323}