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 { |
| 66 | name: "libgcc", |
| 67 | vendor_available: true, |
| 68 | recovery_available: true, |
| 69 | src: "", |
| 70 | } |
| 71 | |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 72 | toolchain_library { |
| 73 | name: "libgcc_stripped", |
| 74 | vendor_available: true, |
| 75 | recovery_available: true, |
| 76 | src: "", |
| 77 | } |
| 78 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 79 | cc_library { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 80 | name: "libc", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 81 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 82 | nocrt: true, |
| 83 | system_shared_libs: [], |
| 84 | recovery_available: true, |
| 85 | } |
| 86 | llndk_library { |
| 87 | name: "libc", |
| 88 | symbol_file: "", |
| 89 | } |
| 90 | cc_library { |
| 91 | name: "libm", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 92 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 93 | nocrt: true, |
| 94 | system_shared_libs: [], |
| 95 | recovery_available: true, |
| 96 | } |
| 97 | llndk_library { |
| 98 | name: "libm", |
| 99 | symbol_file: "", |
| 100 | } |
| 101 | cc_library { |
| 102 | name: "libdl", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 103 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 104 | nocrt: true, |
| 105 | system_shared_libs: [], |
| 106 | recovery_available: true, |
| 107 | } |
| 108 | llndk_library { |
| 109 | name: "libdl", |
| 110 | symbol_file: "", |
| 111 | } |
| 112 | cc_library { |
| 113 | name: "libc++_static", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 114 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 115 | nocrt: true, |
| 116 | system_shared_libs: [], |
| 117 | stl: "none", |
| 118 | vendor_available: true, |
| 119 | recovery_available: true, |
| 120 | } |
| 121 | cc_library { |
| 122 | name: "libc++", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 123 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 124 | nocrt: true, |
| 125 | system_shared_libs: [], |
| 126 | stl: "none", |
| 127 | vendor_available: true, |
| 128 | recovery_available: true, |
| 129 | vndk: { |
| 130 | enabled: true, |
| 131 | support_system_process: true, |
| 132 | }, |
| 133 | } |
| 134 | cc_library { |
| 135 | name: "libunwind_llvm", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 136 | no_libcrt: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 137 | nocrt: true, |
| 138 | system_shared_libs: [], |
| 139 | stl: "none", |
| 140 | vendor_available: true, |
| 141 | recovery_available: true, |
| 142 | } |
| 143 | |
| 144 | cc_object { |
| 145 | name: "crtbegin_so", |
| 146 | recovery_available: true, |
| 147 | vendor_available: true, |
| 148 | } |
| 149 | |
| 150 | cc_object { |
Colin Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame] | 151 | name: "crtbegin_dynamic", |
| 152 | recovery_available: true, |
| 153 | vendor_available: true, |
| 154 | } |
| 155 | |
| 156 | cc_object { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 157 | name: "crtbegin_static", |
| 158 | recovery_available: true, |
| 159 | vendor_available: true, |
| 160 | } |
| 161 | |
| 162 | cc_object { |
| 163 | name: "crtend_so", |
| 164 | recovery_available: true, |
| 165 | vendor_available: true, |
| 166 | } |
| 167 | |
| 168 | cc_object { |
| 169 | name: "crtend_android", |
| 170 | recovery_available: true, |
| 171 | vendor_available: true, |
| 172 | } |
| 173 | |
| 174 | cc_library { |
| 175 | name: "libprotobuf-cpp-lite", |
| 176 | } |
| 177 | ` |
| 178 | if os == android.Fuchsia { |
| 179 | ret += ` |
| 180 | cc_library { |
| 181 | name: "libbioniccompat", |
| 182 | stl: "none", |
| 183 | } |
| 184 | cc_library { |
| 185 | name: "libcompiler_rt", |
| 186 | stl: "none", |
| 187 | } |
| 188 | ` |
| 189 | } |
| 190 | return ret |
| 191 | } |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 192 | |
| 193 | func CreateTestContext(bp string, fs map[string][]byte, |
| 194 | os android.OsType) *android.TestContext { |
| 195 | |
| 196 | ctx := android.NewTestArchContext() |
| 197 | ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory)) |
| 198 | ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory)) |
| 199 | ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory)) |
| 200 | ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory)) |
| 201 | ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(LibraryStaticFactory)) |
| 202 | ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory)) |
Colin Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame] | 203 | ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(TestFactory)) |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 204 | ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(ToolchainLibraryFactory)) |
| 205 | ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(LlndkLibraryFactory)) |
| 206 | ctx.RegisterModuleType("llndk_headers", android.ModuleFactoryAdaptor(llndkHeadersFactory)) |
| 207 | ctx.RegisterModuleType("vendor_public_library", android.ModuleFactoryAdaptor(vendorPublicLibraryFactory)) |
| 208 | ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(ObjectFactory)) |
| 209 | ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 210 | ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(vndkPrebuiltSharedFactory)) |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 211 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 212 | ctx.BottomUp("image", ImageMutator).Parallel() |
| 213 | ctx.BottomUp("link", LinkageMutator).Parallel() |
| 214 | ctx.BottomUp("vndk", VndkMutator).Parallel() |
| 215 | ctx.BottomUp("version", VersionMutator).Parallel() |
| 216 | ctx.BottomUp("begin", BeginMutator).Parallel() |
| 217 | }) |
| 218 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 219 | ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() |
| 220 | }) |
| 221 | ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton)) |
| 222 | |
| 223 | // add some modules that are required by the compiler and/or linker |
| 224 | bp = bp + GatherRequiredDepsForTest(os) |
| 225 | |
| 226 | mockFS := map[string][]byte{ |
| 227 | "Android.bp": []byte(bp), |
| 228 | "foo.c": nil, |
| 229 | "bar.c": nil, |
| 230 | "a.proto": nil, |
| 231 | "b.aidl": nil, |
| 232 | "my_include": nil, |
| 233 | "foo.map.txt": nil, |
| 234 | "liba.so": nil, |
| 235 | } |
| 236 | |
| 237 | for k, v := range fs { |
| 238 | mockFS[k] = v |
| 239 | } |
| 240 | |
| 241 | ctx.MockFileSystem(mockFS) |
| 242 | |
| 243 | return ctx |
| 244 | } |