bazel_clang_tidy
bazel_clang_tidy copied to clipboard
how can i not check system-headers
always report
error: invalid argument '-std=c++17' not allowed with 'C' [clang-diagnostic-error] /root/.cache/bazel/_bazel_root/c0cc7bb48e68379f59a785b3d4b8baaf/execroot/__main__/bazel-out/k8-fastbuild/bin/external/com_github_google_glog/_virtual_includes/glog/glog/logging.h:42:10: error: 'iosfwd' file not found [clang-diagnostic-error] #include <iosfwd>
@erenon
which source file is being processed when this error happens? (the source file that includes logging.h)
i build this folder
in this folder several .cpp and .h include <glog/logging.h> @erenon
Why does bazel try to compile cpp files as C? How does your toolchain definition look like? What does aquery say (compile flags)?
Why does bazel try to compile cpp files as C? How does your toolchain definition look like? What does aquery say (compile flags)? i try to compile a demo. i test out the third party "glog" print this error.how can i not check third party?
[https://github.com/google/glog/issues/839](https://github.com/google/glog/issues/839) @erenon hi,I have raised this issue
hi,@erenon this is my Minimized example,show error clang-version:15 bazel-version:bazel 4.2.1 os:ubuntu20.04
WORKSPACE
# //:WORKSPACE
load(
"@bazel_tools//tools/build_defs/repo:git.bzl",
"git_repository",
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
git_repository(
name = "bazel_clang_tidy",
commit = "fe56d1f6f6d7c7f0d27b66c15935f8319918c542",
remote = "https://github.com/boluo250/bazel_clang_tidy.git",
)
BUILD
filegroup(
name = "clang_tidy_config",
data = [".clang-tidy"],
visibility = ["//visibility:public"],
)
`
**.bazelrc**
`# Required for bazel_clang_tidy to operate as expected
build:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
build:clang-tidy --output_groups=report
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config
.clang-tidy
UseColor: true
Checks: '-*,
abseil-*,
-abseil-no-namespace'
HeaderFilterRegex: '*'
WarningsAsErrors: "*"
CheckOptions:
- key: readability-identifier-naming.IgnoreMainLikeFunctions
value: 1
- key: readability-identifier-naming.IgnoreFailedSplit
value: 0
- { key: HeaderFileExtensions, value: "x" }
es_cpp/BUILD
cc_binary(
name = "main-es1",
srcs = [ "testaaa.h"],
visibility = ["//visibility:public"],
)
es_cpp/testaaa.h
#include <iostream> // NOLINT [build/c++17]
bazel build //es_cpp:main-es1 --config clang-tidy print
root@44fa34cc27e3:~/test/2clang_tidy_test# bazel build //es_cpp:main-es1 --config clang-tidy
INFO: Analyzed target //es_cpp:main-es1 (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /root/test/2clang_tidy_test/es_cpp/BUILD:2:10: Run clang-tidy on es_cpp/testaaa.h failed: (Exit 1): clang_tidy failed: error executing command bazel-out/k8-fastbuild/bin/external/bazel_clang_tidy/clang_tidy/clang_tidy bazel-out/k8-fastbuild/bin/es_cpp/bazel_clang_tidy_es_cpp/testaaa.h.main-es1.clang-tidy.yaml --export-fixes ... (remaining 26 argument(s) skipped)
2 errors generated.
Error while processing /root/.cache/bazel/_bazel_root/c12c70d71c83a34d9ced4530ee069878/execroot/__main__/es_cpp/testaaa.h.
Found compiler error(s).
error: invalid argument '-std=c++0x' not allowed with 'C' [clang-diagnostic-error]
/root/.cache/bazel/_bazel_root/c12c70d71c83a34d9ced4530ee069878/execroot/__main__/es_cpp/testaaa.h:1:10: error: 'iostream' file not found [clang-diagnostic-error]
#include <iostream> // NOLINT [build/c++17]
^~~~~~~~~~
Aspect @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect of //es_cpp:main-es1 failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.217s, Critical Path: 0.05s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
I run into the same problem. It's actually an issue with clang treating .h
files as C.
To fix it, change the run_clang_tidy.sh
:
clang-tidy --extra-arg-before=-xc++ "$@"