Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [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 rust |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | func GatherRequiredDepsForTest() string { |
| 22 | bp := ` |
| 23 | rust_prebuilt_dylib { |
| 24 | name: "libarena_x86_64-unknown-linux-gnu", |
| 25 | srcs: [""], |
| 26 | host_supported: true, |
| 27 | } |
| 28 | rust_prebuilt_dylib { |
| 29 | name: "libfmt_macros_x86_64-unknown-linux-gnu", |
| 30 | srcs: [""], |
| 31 | host_supported: true, |
| 32 | } |
| 33 | rust_prebuilt_dylib { |
| 34 | name: "libgraphviz_x86_64-unknown-linux-gnu", |
| 35 | srcs: [""], |
| 36 | host_supported: true, |
| 37 | } |
| 38 | rust_prebuilt_dylib { |
| 39 | name: "libserialize_x86_64-unknown-linux-gnu", |
| 40 | srcs: [""], |
| 41 | host_supported: true, |
| 42 | } |
| 43 | rust_prebuilt_dylib { |
| 44 | name: "libstd_x86_64-unknown-linux-gnu", |
| 45 | srcs: [""], |
| 46 | host_supported: true, |
| 47 | } |
| 48 | rust_prebuilt_dylib { |
| 49 | name: "libsyntax_x86_64-unknown-linux-gnu", |
| 50 | srcs: [""], |
| 51 | host_supported: true, |
| 52 | } |
| 53 | rust_prebuilt_dylib { |
| 54 | name: "libsyntax_ext_x86_64-unknown-linux-gnu", |
| 55 | srcs: [""], |
| 56 | host_supported: true, |
| 57 | } |
| 58 | rust_prebuilt_dylib { |
| 59 | name: "libsyntax_pos_x86_64-unknown-linux-gnu", |
| 60 | srcs: [""], |
| 61 | host_supported: true, |
| 62 | } |
| 63 | rust_prebuilt_dylib { |
| 64 | name: "libterm_x86_64-unknown-linux-gnu", |
| 65 | srcs: [""], |
| 66 | host_supported: true, |
| 67 | } |
| 68 | rust_prebuilt_dylib { |
| 69 | name: "libtest_x86_64-unknown-linux-gnu", |
| 70 | srcs: [""], |
| 71 | host_supported: true, |
| 72 | } |
| 73 | ` |
| 74 | return bp |
| 75 | } |
| 76 | |
| 77 | func CreateTestContext(bp string) *android.TestContext { |
| 78 | ctx := android.NewTestArchContext() |
| 79 | ctx.RegisterModuleType("rust_binary", android.ModuleFactoryAdaptor(RustBinaryFactory)) |
| 80 | ctx.RegisterModuleType("rust_binary_host", android.ModuleFactoryAdaptor(RustBinaryHostFactory)) |
| 81 | ctx.RegisterModuleType("rust_library", android.ModuleFactoryAdaptor(RustLibraryFactory)) |
| 82 | ctx.RegisterModuleType("rust_library_host", android.ModuleFactoryAdaptor(RustLibraryHostFactory)) |
| 83 | ctx.RegisterModuleType("rust_library_host_rlib", android.ModuleFactoryAdaptor(RustLibraryRlibHostFactory)) |
| 84 | ctx.RegisterModuleType("rust_library_host_dylib", android.ModuleFactoryAdaptor(RustLibraryDylibHostFactory)) |
| 85 | ctx.RegisterModuleType("rust_library_rlib", android.ModuleFactoryAdaptor(RustLibraryRlibFactory)) |
| 86 | ctx.RegisterModuleType("rust_library_dylib", android.ModuleFactoryAdaptor(RustLibraryDylibFactory)) |
| 87 | ctx.RegisterModuleType("rust_proc_macro", android.ModuleFactoryAdaptor(ProcMacroFactory)) |
| 88 | ctx.RegisterModuleType("rust_prebuilt_dylib", android.ModuleFactoryAdaptor(PrebuiltDylibFactory)) |
| 89 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 90 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
| 91 | }) |
| 92 | bp = bp + GatherRequiredDepsForTest() |
| 93 | |
| 94 | mockFS := map[string][]byte{ |
| 95 | "Android.bp": []byte(bp), |
| 96 | "foo.rs": nil, |
| 97 | "src/bar.rs": nil, |
| 98 | "liby.so": nil, |
| 99 | "libz.so": nil, |
| 100 | } |
| 101 | |
| 102 | ctx.MockFileSystem(mockFS) |
| 103 | |
| 104 | return ctx |
| 105 | } |