Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
608 views
in Technique[技术] by (71.8m points)

c++ - What is the correct way of providing header-filter for clang-tidy in Cmake?

I have projects that sets Clang-tidy configuration as following

set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=google-*,cppcoreguidelines-*;")

However, I have noticed that it was checking all the files that are not even in the current repo like

/opt/ros/melodic/include/ros/console.h

and all the .h/.hpp files of submodules...

I tried to add a regex to filter the target .h files but couldn't get it working... I have given absolute path for a single .hpp file but it was still evaluating /opt/ros/melodic/include files...

Can I have an example on header-filter??

I assume clang-tidy will check the corresponding cpp file if hpp is in the filter. am I correct?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can look at this example. That's my commit. https://github.com/cocos2d/cocos2d-x/pull/19928

This is how I disabled clang-tidy checks on two directories with regular expressions.

'^((?!/cocos2d-x/external/|/cocos/scripting/).)*$'

It disables clang-tidy checks on external directory and cocos/scripting directory.

I create a python script to test whether the regular expression is working as intended.

#!/usr/bin/env python
import re

files = [ 
"/home/john/cocos2d-x/external/openssl/include/linux/openssl/bio.h",
"/home/john/cocos2d-x/external/tiff/include/linux/tiff.h",
"/home/john/git/cocos/cocos2d-x/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp"
"/home/john/cocos2d-x/external/json/stringbuffer.h",
"/home/john/cocos2d-x/cocos/base/ccUtils.h",
"/home/john/git/cocos/cocos2d-x/cocos/scripting/js-bindings/precheader.cpp",
"/home/john/cocos2d-x/cocos/physics/CCPhysicsBody.cpp",
"/home/john/cocos2d-x/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp",
"/home/john/cocos2d-x/templates/cpp-template-default/Classes/AppDelegate.cpp",
"/home/john/git/cocos/cocos2d-x/cocos/scripting/js-bindings/proj.android/CMakeLists.txt",
]

pattern = '^((?!/cocos2d-x/external/|/cocos/scripting/).)*$'

for file in files:
    m = re.search(pattern, file)
    if m:
        print m.group(0)

Running this python file and the output is

/home/john/cocos2d-x/cocos/base/ccUtils.h
/home/john/cocos2d-x/cocos/physics/CCPhysicsBody.cpp
/home/john/cocos2d-x/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp
/home/john/cocos2d-x/templates/cpp-template-default/Classes/AppDelegate.cpp

You can modify the regular expression and python test script to see if it works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...