Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame^] | 1 | // Copyright 2020 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 | "strings" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
| 22 | func TestRustBindgen(t *testing.T) { |
| 23 | ctx := testRust(t, ` |
| 24 | rust_bindgen { |
| 25 | name: "libbindgen", |
| 26 | wrapper_src: "src/any.h", |
| 27 | stem: "bindings", |
| 28 | flags: ["--bindgen-flag"], |
| 29 | cflags: ["--clang-flag"], |
| 30 | shared_libs: ["libfoo_shared"], |
| 31 | static_libs: ["libfoo_static"], |
| 32 | } |
| 33 | cc_library_shared { |
| 34 | name: "libfoo_shared", |
| 35 | export_include_dirs: ["shared_include"], |
| 36 | } |
| 37 | cc_library_static { |
| 38 | name: "libfoo_static", |
| 39 | export_include_dirs: ["static_include"], |
| 40 | } |
| 41 | |
| 42 | `) |
| 43 | libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a").Output("bindings.rs") |
| 44 | if !strings.Contains(libbindgen.Args["flags"], "--bindgen-flag") { |
| 45 | t.Errorf("missing bindgen flags in rust_bindgen rule: flags %#v", libbindgen.Args["flags"]) |
| 46 | } |
| 47 | if !strings.Contains(libbindgen.Args["cflags"], "--clang-flag") { |
| 48 | t.Errorf("missing clang cflags in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"]) |
| 49 | } |
| 50 | if !strings.Contains(libbindgen.Args["cflags"], "-Ishared_include") { |
| 51 | t.Errorf("missing clang cflags in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"]) |
| 52 | } |
| 53 | if !strings.Contains(libbindgen.Args["cflags"], "-Istatic_include") { |
| 54 | t.Errorf("missing clang cflags in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"]) |
| 55 | } |
| 56 | } |