1// 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 feature flags are being correctly generated. 23func TestFeaturesToFlags(t *testing.T) { 24 ctx := testRust(t, ` 25 rust_library_host_dylib { 26 name: "libfoo", 27 srcs: ["foo.rs"], 28 crate_name: "foo", 29 features: [ 30 "fizz", 31 "buzz" 32 ], 33 }`) 34 35 libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc") 36 37 if !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'feature=\"fizz\"'") || 38 !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'feature=\"buzz\"'") { 39 t.Fatalf("missing fizz and buzz feature flags for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"]) 40 } 41} 42 43// Test that we reject multiple source files. 44func TestEnforceSingleSourceFile(t *testing.T) { 45 46 singleSrcError := "srcs can only contain one path for rust modules" 47 48 // Test libraries 49 testRustError(t, singleSrcError, ` 50 rust_library_host { 51 name: "foo-bar-library", 52 srcs: ["foo.rs", "src/bar.rs"], 53 }`) 54 55 // Test binaries 56 testRustError(t, singleSrcError, ` 57 rust_binary_host { 58 name: "foo-bar-binary", 59 srcs: ["foo.rs", "src/bar.rs"], 60 }`) 61 62 // Test proc_macros 63 testRustError(t, singleSrcError, ` 64 rust_proc_macro { 65 name: "foo-bar-proc-macro", 66 srcs: ["foo.rs", "src/bar.rs"], 67 }`) 68 69 // Test prebuilts 70 testRustError(t, singleSrcError, ` 71 rust_prebuilt_dylib { 72 name: "foo-bar-prebuilt", 73 srcs: ["liby.so", "libz.so"], 74 host_supported: true, 75 }`) 76} 77