blob: 5fcad29d19901be3468141bc3d4210e92c041ced [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) {
Paul Duffin075c4172019-12-19 19:06:13 +000039 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
40 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
41
Paul Duffind6867912019-12-19 14:38:36 +000042 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
43 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
44 })
Paul Duffin77980a82019-12-19 16:01:36 +000045}
46
Inseob Kimc0907f12019-02-08 21:00:45 +090047func GatherRequiredDepsForTest(os android.OsType) string {
48 ret := `
49 toolchain_library {
50 name: "libatomic",
51 vendor_available: true,
52 recovery_available: true,
53 src: "",
54 }
55
56 toolchain_library {
57 name: "libcompiler_rt-extras",
58 vendor_available: true,
59 recovery_available: true,
60 src: "",
61 }
62
63 toolchain_library {
64 name: "libclang_rt.builtins-arm-android",
65 vendor_available: true,
66 recovery_available: true,
67 src: "",
68 }
69
70 toolchain_library {
71 name: "libclang_rt.builtins-aarch64-android",
72 vendor_available: true,
73 recovery_available: true,
74 src: "",
75 }
76
77 toolchain_library {
78 name: "libclang_rt.builtins-i686-android",
79 vendor_available: true,
80 recovery_available: true,
81 src: "",
82 }
83
84 toolchain_library {
85 name: "libclang_rt.builtins-x86_64-android",
86 vendor_available: true,
87 recovery_available: true,
88 src: "",
89 }
90
91 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -070092 name: "libclang_rt.fuzzer-arm-android",
93 vendor_available: true,
94 recovery_available: true,
95 src: "",
96 }
97
98 toolchain_library {
99 name: "libclang_rt.fuzzer-aarch64-android",
100 vendor_available: true,
101 recovery_available: true,
102 src: "",
103 }
104
105 toolchain_library {
106 name: "libclang_rt.fuzzer-i686-android",
107 vendor_available: true,
108 recovery_available: true,
109 src: "",
110 }
111
112 toolchain_library {
113 name: "libclang_rt.fuzzer-x86_64-android",
114 vendor_available: true,
115 recovery_available: true,
116 src: "",
117 }
118
119 toolchain_library {
120 name: "libclang_rt.fuzzer-x86_64",
121 vendor_available: true,
122 recovery_available: true,
123 src: "",
124 }
125
Paul Duffind6867912019-12-19 14:38:36 +0000126 // Needed for sanitizer
127 cc_prebuilt_library_shared {
128 name: "libclang_rt.ubsan_standalone-aarch64-android",
129 vendor_available: true,
130 recovery_available: true,
131 srcs: [""],
132 }
133
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700134 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900135 name: "libgcc",
136 vendor_available: true,
137 recovery_available: true,
138 src: "",
139 }
140
Yi Kongacee27c2019-03-29 20:05:14 -0700141 toolchain_library {
142 name: "libgcc_stripped",
143 vendor_available: true,
144 recovery_available: true,
145 src: "",
146 }
147
Inseob Kimc0907f12019-02-08 21:00:45 +0900148 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900149 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700150 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900151 nocrt: true,
152 system_shared_libs: [],
153 recovery_available: true,
154 }
155 llndk_library {
156 name: "libc",
157 symbol_file: "",
158 }
159 cc_library {
160 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700161 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900162 nocrt: true,
163 system_shared_libs: [],
164 recovery_available: true,
165 }
166 llndk_library {
167 name: "libm",
168 symbol_file: "",
169 }
170 cc_library {
171 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700172 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900173 nocrt: true,
174 system_shared_libs: [],
175 recovery_available: true,
176 }
177 llndk_library {
178 name: "libdl",
179 symbol_file: "",
180 }
181 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900182 name: "libft2",
183 no_libcrt: true,
184 nocrt: true,
185 system_shared_libs: [],
186 recovery_available: true,
187 }
188 llndk_library {
189 name: "libft2",
190 symbol_file: "",
191 vendor_available: false,
192 }
193 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 name: "libc++_static",
Yi Konge7fe9912019-06-02 00:53:50 -0700195 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900196 nocrt: true,
197 system_shared_libs: [],
198 stl: "none",
199 vendor_available: true,
200 recovery_available: true,
201 }
202 cc_library {
203 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700204 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900205 nocrt: true,
206 system_shared_libs: [],
207 stl: "none",
208 vendor_available: true,
209 recovery_available: true,
210 vndk: {
211 enabled: true,
212 support_system_process: true,
213 },
214 }
215 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700216 name: "libc++demangle",
217 no_libcrt: true,
218 nocrt: true,
219 system_shared_libs: [],
220 stl: "none",
221 host_supported: false,
222 vendor_available: true,
223 recovery_available: true,
224 }
225 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900226 name: "libunwind_llvm",
Yi Konge7fe9912019-06-02 00:53:50 -0700227 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900228 nocrt: true,
229 system_shared_libs: [],
230 stl: "none",
231 vendor_available: true,
232 recovery_available: true,
233 }
234
235 cc_object {
236 name: "crtbegin_so",
237 recovery_available: true,
238 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900239 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900240 }
241
242 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700243 name: "crtbegin_dynamic",
244 recovery_available: true,
245 vendor_available: true,
246 }
247
248 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900249 name: "crtbegin_static",
250 recovery_available: true,
251 vendor_available: true,
252 }
253
254 cc_object {
255 name: "crtend_so",
256 recovery_available: true,
257 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900258 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900259 }
260
261 cc_object {
262 name: "crtend_android",
263 recovery_available: true,
264 vendor_available: true,
265 }
266
267 cc_library {
268 name: "libprotobuf-cpp-lite",
269 }
270 `
271 if os == android.Fuchsia {
272 ret += `
273 cc_library {
274 name: "libbioniccompat",
275 stl: "none",
276 }
277 cc_library {
278 name: "libcompiler_rt",
279 stl: "none",
280 }
281 `
282 }
283 return ret
284}
Colin Cross9a942872019-05-14 15:44:26 -0700285
Colin Cross98be1bb2019-12-13 20:41:13 -0800286func TestConfig(buildDir string, os android.OsType, env map[string]string,
287 bp string, fs map[string][]byte) android.Config {
Colin Cross9a942872019-05-14 15:44:26 -0700288
Colin Cross98be1bb2019-12-13 20:41:13 -0800289 // add some modules that are required by the compiler and/or linker
290 bp = bp + GatherRequiredDepsForTest(os)
291
292 mockFS := map[string][]byte{
293 "foo.c": nil,
294 "foo.lds": nil,
295 "bar.c": nil,
296 "baz.c": nil,
297 "baz.o": nil,
298 "a.proto": nil,
299 "b.aidl": nil,
300 "sub/c.aidl": nil,
301 "my_include": nil,
302 "foo.map.txt": nil,
303 "liba.so": nil,
304 }
305
306 for k, v := range fs {
307 mockFS[k] = v
308 }
309
310 var config android.Config
311 if os == android.Fuchsia {
312 config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
313 } else {
314 config = android.TestArchConfig(buildDir, env, bp, mockFS)
315 }
316
317 return config
318}
319
320func CreateTestContext() *android.TestContext {
Colin Cross9a942872019-05-14 15:44:26 -0700321 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -0800322 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
323 ctx.RegisterModuleType("cc_binary", BinaryFactory)
324 ctx.RegisterModuleType("cc_binary_host", binaryHostFactory)
325 ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800326 ctx.RegisterModuleType("cc_library_shared", LibrarySharedFactory)
327 ctx.RegisterModuleType("cc_library_static", LibraryStaticFactory)
328 ctx.RegisterModuleType("cc_library_headers", LibraryHeaderFactory)
329 ctx.RegisterModuleType("cc_test", TestFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800330 ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Jooyung Hanb90e4912019-12-09 18:21:48 +0900331 ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800332 ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800333 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
334 ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
335 ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Paul Duffin77980a82019-12-19 16:01:36 +0000336 RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross9a942872019-05-14 15:44:26 -0700337 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
338 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
339 })
Colin Crosse1bb5d02019-09-24 14:55:04 -0700340 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross4b49b762019-11-22 15:25:03 -0800341 ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Colin Cross9a942872019-05-14 15:44:26 -0700342
Colin Cross9a942872019-05-14 15:44:26 -0700343 return ctx
344}