在Cmake中为clang-tidy提供标头过滤器的正确方法是什么? [英] What is the correct way of providing header-filter for clang-tidy in Cmake?

查看:239
本文介绍了在Cmake中为clang-tidy提供标头过滤器的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些将Clang-tidy配置如下的项目

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

以及子模块的所有.h / .hpp文件...

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

我试图添加一个正则表达式来过滤目标.h文件,但无法使其正常工作...
我为单个.hpp文件提供了绝对路径,但它仍在评估 / opt / ros / melodic / include 文件...

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??

我假设如果hpp在过滤器中,则clang-tidy将检查相应的cpp文件。我正确吗?

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

推荐答案

您可以看一下此示例。那是我的承诺。 https://github.com/cocos2d/cocos2d-x/pull/19928

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

这是我在具有正则表达式的两个目录上禁用clang-tidy检查的方式。

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

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

它在外部目录和 cocos / scripting 目录上禁用整洁检查

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

我创建一个python脚本来测试正则表达式是否按预期工作。

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)

运行此python文件,输出为

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

您可以将正则表达式和python测试脚本修改为看看是否可行。

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

这篇关于在Cmake中为clang-tidy提供标头过滤器的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆