Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | func 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 Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 66 | 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 Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 101 | name: "libgcc", |
| 102 | vendor_available: true, |
| 103 | recovery_available: true, |
| 104 | src: "", |
| 105 | } |
| 106 | |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 107 | toolchain_library { |
| 108 | name: "libgcc_stripped", |
| 109 | vendor_available: true, |
| 110 | recovery_available: true, |
| 111 | src: "", |
| 112 | } |
| 113 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 114 | cc_library { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 115 | name: "libc", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 116 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 117 | 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 Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 127 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 128 | 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 Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 138 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 139 | 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 Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame^] | 148 | 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 Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 160 | name: "libc++_static", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 161 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 162 | 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 Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 170 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 171 | 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 Albert | 2da19cb | 2019-07-24 12:17:40 -0700 | [diff] [blame] | 182 | 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 Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 192 | name: "libunwind_llvm", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 193 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 194 | 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 Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 205 | stl: "none", |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | cc_object { |
Colin Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame] | 209 | name: "crtbegin_dynamic", |
| 210 | recovery_available: true, |
| 211 | vendor_available: true, |
| 212 | } |
| 213 | |
| 214 | cc_object { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 215 | 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 Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 224 | stl: "none", |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 225 | } |
| 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 Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 251 | |
| 252 | func CreateTestContext(bp string, fs map[string][]byte, |
| 253 | os android.OsType) *android.TestContext { |
| 254 | |
| 255 | ctx := android.NewTestArchContext() |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 256 | ctx.RegisterModuleType("cc_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 257 | ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory)) |
| 258 | ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory)) |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 259 | ctx.RegisterModuleType("cc_fuzz", android.ModuleFactoryAdaptor(FuzzFactory)) |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 260 | 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 Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame] | 264 | ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(TestFactory)) |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 265 | 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 Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 271 | ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(VndkPrebuiltSharedFactory)) |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 272 | 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 Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 282 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 283 | 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 Bentley | 74c9bba | 2019-08-16 20:25:06 +0100 | [diff] [blame] | 291 | "foo.lds": nil, |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 292 | "bar.c": nil, |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 293 | "baz.c": nil, |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 294 | "baz.o": nil, |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 295 | "a.proto": nil, |
| 296 | "b.aidl": nil, |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 297 | "sub/c.aidl": nil, |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 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 | ctx.MockFileSystem(mockFS) |
| 308 | |
| 309 | return ctx |
| 310 | } |