Skip to content

ninja clang-tidy runs even on source files that are not built by any Meson target #7662

Open
@avdgrinten

Description

@avdgrinten

Describe the bug
Meson's clang-tidy target fails on projects that contain source files which cannot be compiled as part of the current build directory, e.g., because they require optional dependencies, cross compilers and/or additional command line options. This includes files that are not part of any executable(), shared_library() or other target. In particular, in non-run-clang-tidy.py mode, ninja clang-tidy is run on all source files that are part of the source directory. This yields a huge amount of false positives -- files fail to compile due to missing headers, intrinsics that are only supported on other architectures etc.

In fact, the logic in mesonbuild/scripts/clangtidy.py is just:

for f in (x for suff in suffixes for x in srcdir.glob('**/*.' + suff))

which does not take into account build targets at all.

To Reproduce
On the following four source files (.clang-tidy, foo.c, bar.c, meson.build), run

meson build
ninja -C build
ninja -C build clang-tidy

.clang-tidy

# Empty file.

foo.c

int main(int argc, char *argv[]) { }

bar.c

#include <non-existant-header>

meson.build

project('bug-report', 'c')
executable('foo', 'foo.c')

Expected behavior
Meson only invokes clang-tidy on source files that are actually compiled. Note that bar.c is not part of any Meson target, yet, it causes the run to fail (it also neither mentioned in ninja.build nor in the compilation database).

system parameters
Tested on master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions