Merge "rust: Add cflag checks against -xc++ and -std."

This commit is contained in:
Ivan Lozano
2020-10-21 14:37:40 +00:00
committed by Gerrit Code Review
2 changed files with 38 additions and 0 deletions

View File

@@ -150,6 +150,18 @@ func (b *bindgenDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) andr
esc := proptools.NinjaAndShellEscapeList
// Filter out invalid cflags
for _, flag := range b.ClangProperties.Cflags {
if flag == "-x c++" || flag == "-xc++" {
ctx.PropertyErrorf("cflags",
"-x c++ should not be specified in cflags; setting cpp_std specifies this is a C++ header, or change the file extension to '.hpp' or '.hh'")
}
if strings.HasPrefix(flag, "-std=") {
ctx.PropertyErrorf("cflags",
"-std should not be specified in cflags; instead use c_std or cpp_std")
}
}
// Module defined clang flags and include paths
cflags = append(cflags, esc(b.ClangProperties.Cflags)...)
for _, include := range b.ClangProperties.Local_include_dirs {

View File

@@ -134,3 +134,29 @@ func TestRustBindgenStdVersions(t *testing.T) {
t.Errorf("cpp_std value not passed in to rust_bindgen as a clang flag")
}
}
func TestBindgenDisallowedFlags(t *testing.T) {
// Make sure passing '-x c++' to cflags generates an error
testRustError(t, "cflags: -x c\\+\\+ should not be specified in cflags.*", `
rust_bindgen {
name: "libbad_flag",
wrapper_src: "src/any.h",
crate_name: "bindgen",
stem: "libbindgen",
source_stem: "bindings",
cflags: ["-x c++"]
}
`)
// Make sure passing '-std=' to cflags generates an error
testRustError(t, "cflags: -std should not be specified in cflags.*", `
rust_bindgen {
name: "libbad_flag",
wrapper_src: "src/any.h",
crate_name: "bindgen",
stem: "libbindgen",
source_stem: "bindings",
cflags: ["-std=foo"]
}
`)
}