blob: fafaeb0c925ac13b5249d9f675e25ee33696db32 [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
21func GatherRequiredDepsForTest(os android.OsType) string {
22 ret := `
23 toolchain_library {
24 name: "libatomic",
25 vendor_available: true,
26 recovery_available: true,
27 src: "",
28 }
29
30 toolchain_library {
31 name: "libcompiler_rt-extras",
32 vendor_available: true,
33 recovery_available: true,
34 src: "",
35 }
36
37 toolchain_library {
38 name: "libclang_rt.builtins-arm-android",
39 vendor_available: true,
40 recovery_available: true,
41 src: "",
42 }
43
44 toolchain_library {
45 name: "libclang_rt.builtins-aarch64-android",
46 vendor_available: true,
47 recovery_available: true,
48 src: "",
49 }
50
51 toolchain_library {
52 name: "libclang_rt.builtins-i686-android",
53 vendor_available: true,
54 recovery_available: true,
55 src: "",
56 }
57
58 toolchain_library {
59 name: "libclang_rt.builtins-x86_64-android",
60 vendor_available: true,
61 recovery_available: true,
62 src: "",
63 }
64
65 toolchain_library {
Mitch Phillipsda9a4632019-07-15 09:34:09 -070066 name: "libclang_rt.fuzzer-arm-android",
67 vendor_available: true,
68 recovery_available: true,
69 src: "",
70 }
71
72 toolchain_library {
73 name: "libclang_rt.fuzzer-aarch64-android",
74 vendor_available: true,
75 recovery_available: true,
76 src: "",
77 }
78
79 toolchain_library {
80 name: "libclang_rt.fuzzer-i686-android",
81 vendor_available: true,
82 recovery_available: true,
83 src: "",
84 }
85
86 toolchain_library {
87 name: "libclang_rt.fuzzer-x86_64-android",
88 vendor_available: true,
89 recovery_available: true,
90 src: "",
91 }
92
93 toolchain_library {
94 name: "libclang_rt.fuzzer-x86_64",
95 vendor_available: true,
96 recovery_available: true,
97 src: "",
98 }
99
100 toolchain_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900101 name: "libgcc",
102 vendor_available: true,
103 recovery_available: true,
104 src: "",
105 }
106
Yi Kongacee27c2019-03-29 20:05:14 -0700107 toolchain_library {
108 name: "libgcc_stripped",
109 vendor_available: true,
110 recovery_available: true,
111 src: "",
112 }
113
Inseob Kimc0907f12019-02-08 21:00:45 +0900114 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900115 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700116 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900117 nocrt: true,
118 system_shared_libs: [],
119 recovery_available: true,
120 }
121 llndk_library {
122 name: "libc",
123 symbol_file: "",
124 }
125 cc_library {
126 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700127 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900128 nocrt: true,
129 system_shared_libs: [],
130 recovery_available: true,
131 }
132 llndk_library {
133 name: "libm",
134 symbol_file: "",
135 }
136 cc_library {
137 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700138 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900139 nocrt: true,
140 system_shared_libs: [],
141 recovery_available: true,
142 }
143 llndk_library {
144 name: "libdl",
145 symbol_file: "",
146 }
147 cc_library {
Jooyung Han097087b2019-10-22 19:32:18 +0900148 name: "libft2",
149 no_libcrt: true,
150 nocrt: true,
151 system_shared_libs: [],
152 recovery_available: true,
153 }
154 llndk_library {
155 name: "libft2",
156 symbol_file: "",
157 vendor_available: false,
158 }
159 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900160 name: "libc++_static",
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 stl: "none",
165 vendor_available: true,
166 recovery_available: true,
167 }
168 cc_library {
169 name: "libc++",
Yi Konge7fe9912019-06-02 00:53:50 -0700170 no_libcrt: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900171 nocrt: true,
172 system_shared_libs: [],
173 stl: "none",
174 vendor_available: true,
175 recovery_available: true,
176 vndk: {
177 enabled: true,
178 support_system_process: true,
179 },
180 }
181 cc_library {
Dan Albert2da19cb2019-07-24 12:17:40 -0700182 name: "libc++demangle",
183 no_libcrt: true,
184 nocrt: true,
185 system_shared_libs: [],
186 stl: "none",
187 host_supported: false,
188 vendor_available: true,
189 recovery_available: true,
190 }
191 cc_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900192 name: "libunwind_llvm",
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 }
200
201 cc_object {
202 name: "crtbegin_so",
203 recovery_available: true,
204 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900205 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900206 }
207
208 cc_object {
Colin Cross815daf92019-05-14 16:05:20 -0700209 name: "crtbegin_dynamic",
210 recovery_available: true,
211 vendor_available: true,
212 }
213
214 cc_object {
Inseob Kimc0907f12019-02-08 21:00:45 +0900215 name: "crtbegin_static",
216 recovery_available: true,
217 vendor_available: true,
218 }
219
220 cc_object {
221 name: "crtend_so",
222 recovery_available: true,
223 vendor_available: true,
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900224 stl: "none",
Inseob Kimc0907f12019-02-08 21:00:45 +0900225 }
226
227 cc_object {
228 name: "crtend_android",
229 recovery_available: true,
230 vendor_available: true,
231 }
232
233 cc_library {
234 name: "libprotobuf-cpp-lite",
235 }
236 `
237 if os == android.Fuchsia {
238 ret += `
239 cc_library {
240 name: "libbioniccompat",
241 stl: "none",
242 }
243 cc_library {
244 name: "libcompiler_rt",
245 stl: "none",
246 }
247 `
248 }
249 return ret
250}
Colin Cross9a942872019-05-14 15:44:26 -0700251
252func CreateTestContext(bp string, fs map[string][]byte,
253 os android.OsType) *android.TestContext {
254
255 ctx := android.NewTestArchContext()
Colin Crosse1bb5d02019-09-24 14:55:04 -0700256 ctx.RegisterModuleType("cc_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
Colin Cross9a942872019-05-14 15:44:26 -0700257 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory))
258 ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory))
Mitch Phillipsda9a4632019-07-15 09:34:09 -0700259 ctx.RegisterModuleType("cc_fuzz", android.ModuleFactoryAdaptor(FuzzFactory))
Colin Cross9a942872019-05-14 15:44:26 -0700260 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory))
261 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory))
262 ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(LibraryStaticFactory))
263 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory))
Colin Cross815daf92019-05-14 16:05:20 -0700264 ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(TestFactory))
Colin Cross9a942872019-05-14 15:44:26 -0700265 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(ToolchainLibraryFactory))
266 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(LlndkLibraryFactory))
267 ctx.RegisterModuleType("llndk_headers", android.ModuleFactoryAdaptor(llndkHeadersFactory))
268 ctx.RegisterModuleType("vendor_public_library", android.ModuleFactoryAdaptor(vendorPublicLibraryFactory))
269 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(ObjectFactory))
270 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900271 ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(VndkPrebuiltSharedFactory))
Colin Cross9a942872019-05-14 15:44:26 -0700272 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
273 ctx.BottomUp("image", ImageMutator).Parallel()
274 ctx.BottomUp("link", LinkageMutator).Parallel()
275 ctx.BottomUp("vndk", VndkMutator).Parallel()
276 ctx.BottomUp("version", VersionMutator).Parallel()
277 ctx.BottomUp("begin", BeginMutator).Parallel()
278 })
279 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
280 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
281 })
Colin Crosse1bb5d02019-09-24 14:55:04 -0700282 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross9a942872019-05-14 15:44:26 -0700283 ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton))
284
285 // add some modules that are required by the compiler and/or linker
286 bp = bp + GatherRequiredDepsForTest(os)
287
288 mockFS := map[string][]byte{
289 "Android.bp": []byte(bp),
290 "foo.c": nil,
Pete Bentley74c9bba2019-08-16 20:25:06 +0100291 "foo.lds": nil,
Colin Cross9a942872019-05-14 15:44:26 -0700292 "bar.c": nil,
Colin Crosse1bb5d02019-09-24 14:55:04 -0700293 "baz.c": nil,
Pete Bentleyfcf55bf2019-08-16 20:14:32 +0100294 "baz.o": nil,
Colin Cross9a942872019-05-14 15:44:26 -0700295 "a.proto": nil,
296 "b.aidl": nil,
Jiyong Park29074592019-07-07 16:27:47 +0900297 "sub/c.aidl": nil,
Colin Cross9a942872019-05-14 15:44:26 -0700298 "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 ctx.MockFileSystem(mockFS)
308
309 return ctx
310}