blob: 245325bed0e9db177b068349033ce9fd72f7bf4b [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 Duffin77980a82019-12-19 16:01:36 +000023 ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
24 ctx.RegisterModuleType("cc_library", LibraryFactory)
25 ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)
26 ctx.RegisterModuleType("cc_object", ObjectFactory)
27
Paul Duffind6867912019-12-19 14:38:36 +000028 android.RegisterPrebuiltMutators(ctx)
Paul Duffin77980a82019-12-19 16:01:36 +000029 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
30 ctx.BottomUp("vndk", VndkMutator).Parallel()
31 ctx.BottomUp("link", LinkageMutator).Parallel()
32 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
33 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
34 ctx.BottomUp("version", VersionMutator).Parallel()
35 ctx.BottomUp("begin", BeginMutator).Parallel()
36 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
37 })
Paul Duffind6867912019-12-19 14:38:36 +000038 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
39 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
40 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
41 })
Paul Duffin77980a82019-12-19 16:01:36 +000042}
43
Inseob Kimc0907f12019-02-08 21:00:45 +090044func GatherRequiredDepsForTest(os android.OsType) string {
45 ret := `
46 toolchain_library {
47 name: "libatomic",
48 vendor_available: true,
49 recovery_available: true,
50 src: "",
51 }
52
53 toolchain_library {
54 name: "libcompiler_rt-extras",
55 vendor_available: true,
56 recovery_available: true,
57 src: "",
58 }
59
60 toolchain_library {
61 name: "libclang_rt.builtins-arm-android",
62 vendor_available: true,
63 recovery_available: true,
64 src: "",
65 }
66
67 toolchain_library {
68 name: "libclang_rt.builtins-aarch64-android",
69 vendor_available: true,
70 recovery_available: true,
71 src: "",
72 }
73
74 toolchain_library {
75 name: "libclang_rt.builtins-i686-android",
76 vendor_available: true,
77 recovery_available: true,
78 src: "",
79 }
80
81 toolchain_library {
82 name: "libclang_rt.builtins-x86_64-android",
83 vendor_available: true,
84 recovery_available: true,
85 src: "",
86 }
87
88 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -070089 name: "libclang_rt.fuzzer-arm-android",
90 vendor_available: true,
91 recovery_available: true,
92 src: "",
93 }
94
95 toolchain_library {
96 name: "libclang_rt.fuzzer-aarch64-android",
97 vendor_available: true,
98 recovery_available: true,
99 src: "",
100 }
101
102 toolchain_library {
103 name: "libclang_rt.fuzzer-i686-android",
104 vendor_available: true,
105 recovery_available: true,
106 src: "",
107 }
108
109 toolchain_library {
110 name: "libclang_rt.fuzzer-x86_64-android",
111 vendor_available: true,
112 recovery_available: true,
113 src: "",
114 }
115
116 toolchain_library {
117 name: "libclang_rt.fuzzer-x86_64",
118 vendor_available: true,
119 recovery_available: true,
120 src: "",
121 }
122
Paul Duffind6867912019-12-19 14:38:36 +0000123 // Needed for sanitizer
124 cc_prebuilt_library_shared {
125 name: "libclang_rt.ubsan_standalone-aarch64-android",
126 vendor_available: true,
127 recovery_available: true,
128 srcs: [""],
129 }
130
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700131 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900132 name: "libgcc",
133 vendor_available: true,
134 recovery_available: true,
135 src: "",
136 }
137
Yi Kongacee27c2019-03-29 20:05:14 -0700138 toolchain_library {
139 name: "libgcc_stripped",
140 vendor_available: true,
141 recovery_available: true,
142 src: "",
143 }
144
Inseob Kimc0907f12019-02-08 21:00:45 +0900145 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900146 name: "libc",
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: "libc",
154 symbol_file: "",
155 }
156 cc_library {
157 name: "libm",
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: "libm",
165 symbol_file: "",
166 }
167 cc_library {
168 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700169 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900170 nocrt: true,
171 system_shared_libs: [],
172 recovery_available: true,
173 }
174 llndk_library {
175 name: "libdl",
176 symbol_file: "",
177 }
178 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900179 name: "libft2",
180 no_libcrt: true,
181 nocrt: true,
182 system_shared_libs: [],
183 recovery_available: true,
184 }
185 llndk_library {
186 name: "libft2",
187 symbol_file: "",
188 vendor_available: false,
189 }
190 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900191 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700192 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900193 nocrt: true,
194 system_shared_libs: [],
195 stl: "none",
196 vendor_available: true,
197 recovery_available: true,
198 }
199 cc_library {
200 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700201 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900202 nocrt: true,
203 system_shared_libs: [],
204 stl: "none",
205 vendor_available: true,
206 recovery_available: true,
207 vndk: {
208 enabled: true,
209 support_system_process: true,
210 },
211 }
212 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700213 name: "libc++demangle",
214 no_libcrt: true,
215 nocrt: true,
216 system_shared_libs: [],
217 stl: "none",
218 host_supported: false,
219 vendor_available: true,
220 recovery_available: true,
221 }
222 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900223 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700224 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900225 nocrt: true,
226 system_shared_libs: [],
227 stl: "none",
228 vendor_available: true,
229 recovery_available: true,
230 }
231
232 cc_object {
233 name: "crtbegin_so",
234 recovery_available: true,
235 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900236 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900237 }
238
239 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700240 name: "crtbegin_dynamic",
241 recovery_available: true,
242 vendor_available: true,
243 }
244
245 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900246 name: "crtbegin_static",
247 recovery_available: true,
248 vendor_available: true,
249 }
250
251 cc_object {
252 name: "crtend_so",
253 recovery_available: true,
254 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900255 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900256 }
257
258 cc_object {
259 name: "crtend_android",
260 recovery_available: true,
261 vendor_available: true,
262 }
263
264 cc_library {
265 name: "libprotobuf-cpp-lite",
266 }
267 `
268 if os == android.Fuchsia {
269 ret += `
270 cc_library {
271 name: "libbioniccompat",
272 stl: "none",
273 }
274 cc_library {
275 name: "libcompiler_rt",
276 stl: "none",
277 }
278 `
279 }
280 return ret
281}
Colin Cross9a942872019-05-14 15:44:26 -0700282
Colin Cross98be1bb2019-12-13 20:41:13 -0800283func TestConfig(buildDir string, os android.OsType, env map[string]string,
284 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700285
Colin Cross98be1bb2019-12-13 20:41:13 -0800286 // add some modules that are required by the compiler and/or linker
287 bp = bp + GatherRequiredDepsForTest(os)
288
289 mockFS := map[string][]byte{
290 "foo.c": nil,
291 "foo.lds": nil,
292 "bar.c": nil,
293 "baz.c": nil,
294 "baz.o": nil,
295 "a.proto": nil,
296 "b.aidl": nil,
297 "sub/c.aidl": nil,
298 "my_include": nil,
299 "foo.map.txt": nil,
300 "liba.so": nil,
301 }
302
303 for k, v := range fs {
304 mockFS[k] = v
305 }
306
307 var config android.Config
308 if os == android.Fuchsia {
309 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
310 } else {
311 config = android.TestArchConfig(buildDir, env, bp, mockFS)
312 }
313
314 return config
315}
316
317func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700318 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800319 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
320 ctx.RegisterModuleType("cc_binary", BinaryFactory)
321 ctx.RegisterModuleType("cc_binary_host", binaryHostFactory)
322 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800323 ctx.RegisterModuleType("cc_library_shared", LibrarySharedFactory)
324 ctx.RegisterModuleType("cc_library_static", LibraryStaticFactory)
325 ctx.RegisterModuleType("cc_library_headers", LibraryHeaderFactory)
326 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800327 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900328 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800329 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800330 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
331 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
332 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000333 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700334 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
335 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
336 })
Colin Crosse1bb5d02019-09-24 14:55:04 -0700337 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800338 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700339
Colin Cross9a942872019-05-14 15:44:26 -0700340 return ctx
341}