blob: eeee8417c22d1bfa0a561f2796a6446d340a233b [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// Copyright 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 rust
16
17import (
18 "strings"
19 "testing"
20)
21
22// Test that the prefer_dynamic property is handled correctly.
23func TestPreferDynamicBinary(t *testing.T) {
24 ctx := testRust(t, `
25 rust_binary_host {
26 name: "fizz-buzz-dynamic",
27 srcs: ["foo.rs"],
28 prefer_dynamic: true,
29 }
30
31 rust_binary_host {
32 name: "fizz-buzz",
33 srcs: ["foo.rs"],
34 }`)
35
36 fizzBuzz := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Output("fizz-buzz")
37 fizzBuzzDynamic := ctx.ModuleForTests("fizz-buzz-dynamic", "linux_glibc_x86_64").Output("fizz-buzz-dynamic")
38
Chih-Hung Hsieha7562702020-08-10 21:50:43 -070039 path := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module).HostToolPath()
40 if g, w := path.String(), "/host/linux-x86/bin/fizz-buzz"; !strings.Contains(g, w) {
41 t.Errorf("wrong host tool path, expected %q got %q", w, g)
42 }
43
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -070044 // Do not compile binary modules with the --test flag.
45 flags := fizzBuzzDynamic.Args["rustcFlags"]
46 if strings.Contains(flags, "--test") {
47 t.Errorf("extra --test flag, rustcFlags: %#v", flags)
48 }
49 if !strings.Contains(flags, "prefer-dynamic") {
50 t.Errorf("missing prefer-dynamic flag, rustcFlags: %#v", flags)
Ivan Lozanoffee3342019-08-27 12:03:00 -070051 }
52
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -070053 flags = fizzBuzz.Args["rustcFlags"]
54 if strings.Contains(flags, "--test") {
55 t.Errorf("extra --test flag, rustcFlags: %#v", flags)
56 }
57 if strings.Contains(flags, "prefer-dynamic") {
58 t.Errorf("unexpected prefer-dynamic flag, rustcFlags: %#v", flags)
Ivan Lozanoffee3342019-08-27 12:03:00 -070059 }
60}
Ivan Lozano2093af22020-08-25 12:48:19 -040061
62func TestLinkObjects(t *testing.T) {
63 ctx := testRust(t, `
64 rust_binary {
65 name: "fizz-buzz",
66 srcs: ["foo.rs"],
67 shared_libs: ["libfoo"],
68 }
69 cc_library {
70 name: "libfoo",
71 }`)
72
73 fizzBuzz := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a").Output("fizz-buzz")
74 linkFlags := fizzBuzz.Args["linkFlags"]
75 if !strings.Contains(linkFlags, "/libfoo.so") {
76 t.Errorf("missing shared dependency 'libfoo.so' in linkFlags: %#v", linkFlags)
77 }
78}