tools: Fixes bug where clang-tidy assumes cc flags
A minor bug was introduced where the clang-tidy tooling would always
assume that it was compiling for c++ even when compiling a c source
file. This change fixes this bug, and additionally adds regression
tests.
diff --git a/.bazelrc b/.bazelrc
index b6e4a9c..22c27d5 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -14,4 +14,7 @@
coverage --combined_report=lcov
coverage --experimental_use_llvm_covmap
coverage --experimental_generate_llvm_lcov
-coverage --incompatible_cc_coverage
\ No newline at end of file
+coverage --incompatible_cc_coverage
+
+# Static analyser support
+build:analyser --aspects //tools/clang_tidy:clang_tidy.bzl%clang_tidy_aspect --output_groups=report
\ No newline at end of file
diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel
index 05448f9..4888efd 100644
--- a/tests/BUILD.bazel
+++ b/tests/BUILD.bazel
@@ -21,3 +21,8 @@
name = "dereferencing_null_pointer",
srcs = ["dereferencing_null_pointer.cc"],
)
+
+cc_binary(
+ name = "c_only",
+ srcs = ["c_only.c"],
+)
diff --git a/tests/c_only.c b/tests/c_only.c
new file mode 100644
index 0000000..3ce2722
--- /dev/null
+++ b/tests/c_only.c
@@ -0,0 +1,6 @@
+#ifdef __cplusplus
+#error \
+ "This is the C file, this file should not be compiled with -xc++ \
+ language directives."
+#endif
+int main() { return 0; }
\ No newline at end of file
diff --git a/tools/clang_tidy/clang_tidy.bzl b/tools/clang_tidy/clang_tidy.bzl
index 4969f3b..f1677d9 100644
--- a/tools/clang_tidy/clang_tidy.bzl
+++ b/tools/clang_tidy/clang_tidy.bzl
@@ -16,7 +16,7 @@
Args:
file (File): The file to get the language for
"""
- if file.extension == ".c":
+ if file.extension == "c":
return "c"
else:
return "cc"