Meson: clang-tidy / clang-format shouldn't run on subprojects

Created on 25 May 2020  路  2Comments  路  Source: mesonbuild/meson

Describe the bug
The generated targets for ninja clang-format and ninja clang-tidy run against, and in the case of clang-format modify, source in subprojects.

$ md5sum subprojects/cxxopts-2.2.0/src/example.cpp          
8a46e7a4065d2ba30c0879480cc14b33  subprojects/cxxopts-2.2.0/src/example.cpp
$ ninja clang-format
$ md5sum subprojects/cxxopts-2.2.0/src/example.cpp
ffe31934802efea01f8c1df3f3eb1cf8  subprojects/cxxopts-2.2.0/src/example.cpp

To Reproduce

  1. Add a subproject, such as cxxopts, with meson wrap: meson wrap install cxxopts.
  2. Add subproject as a dependency: subproject('cxxopts').get_variable('cxxopts_dep').
  3. Create a .clang-format file.
  4. Run ninja clang-format.
  5. Observe contents have changed under subprojects.

Expected behavior
The clang-format rule should not modify source under subprojects.
Ideally, clang-tidy can be skipped on subprojects since they might have different quality standards than the including project.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)?

Native.

  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)

Gentoo [stable].

  • what Python version are you using e.g. 3.8.0
$ python --version                       
Python 3.7.7
  • what meson --version
$ meson --version                                 
0.54.1
  • what ninja --version if it's a Ninja build
$ ninja --version   
1.9.0.git.kitware.dyndep-1.jobserver-1

Most helpful comment

I understand you might want to run clang-tidy on the subprojects, but I don't understand why you'd want to reformat code you got from elsewhere (via clang-format).

In the case of clang-tidy there isn't a good way with the .clang-tidy file to ignore the subprojects repository (or at least I can't find one). If I pick up a simple subproject like google-test, I have to either run with exactly the same clang-tidy settings they did or I get lots of failures. This makes the generated ninja clang-tidy recipe useless for any kind of CI.

Is there any way to create an option to include / exclude subprojects for these generated recipes?

All 2 comments

The problem here being that other people really do want to run those tools for subprojects by default. A simple solution is to add a .clang-format file that disables all formatting in the subprojects dir.

I understand you might want to run clang-tidy on the subprojects, but I don't understand why you'd want to reformat code you got from elsewhere (via clang-format).

In the case of clang-tidy there isn't a good way with the .clang-tidy file to ignore the subprojects repository (or at least I can't find one). If I pick up a simple subproject like google-test, I have to either run with exactly the same clang-tidy settings they did or I get lots of failures. This makes the generated ninja clang-tidy recipe useless for any kind of CI.

Is there any way to create an option to include / exclude subprojects for these generated recipes?

Was this page helpful?
0 / 5 - 0 ratings