xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.87k stars 775 forks source link

`xmake check clang.tidy` doesn't check headers files #5647

Closed yh-sb closed 4 days ago

yh-sb commented 6 days ago

Xmake Version

2.9.5

Operating System Version and Architecture

Windows 11 23H2 22631.4037

Describe Bug

I've noticed that the xmake check clang.tidy command doesn't check header files. As I understand, it only checks files present in compile_commands.json, which does not include header files.

Do you have any ideas on how to fix this?

Expected Behavior

xmake check clang.tidy passes all source files of the project to clang-tidy.

Project Configuration

add_rules("mode.debug", "mode.release")

target("app")
    add_files("main.cpp")

Additional Information and Error Logs

No additional information

waruqi commented 6 days ago

it should has -Ixxx flags in compile_commands.json. Won't clang-tidy look for headers from these flags? Do I need to manually tell it what headers it has?

yh-sb commented 6 days ago

clang-tidy doesn't get header files from compile_commands.json. It take for analysis only files which are explicitly passed in source list.

waruqi commented 5 days ago

try this patch https://github.com/xmake-io/xmake/pull/5651

yh-sb commented 5 days ago

Unfortunately it doesn't help: headerfiles is always empty.

waruqi commented 5 days ago

Did you set add_headerfiles?

yh-sb commented 5 days ago

No, I didn't specified add_headerfiles. If I list headers using add_headerfiles, then clang.tidy check works fine, analyzing listed headers.

But in most common (non header-only) C++ projects, it's not mandatory to list headers in add_headerfiles, right?

waruqi commented 5 days ago

No, I didn't specified add_headerfiles. If I list headers using add_headerfiles, then clang.tidy check works fine, analyzing listed headers.

But in most common (non header-only) C++ projects, it's not mandatory to list headers in add_headerfiles, right?

Analyzing the header file list is not the work of xmake, it's the work of the compiler. Xmake only tells the compiler -Ixx flags. If clang-tidy does not support -Ixxx and the user does not specify header files, then xmake cannot do more. You can open a feature request to clang-tidy to support -Ixxx.