首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在添加自定义模块后,我的自定义clang-整齐检查没有出现?

为什么在添加自定义模块后,我的自定义clang-整齐检查没有出现?
EN

Stack Overflow用户
提问于 2022-08-29 15:39:46
回答 1查看 63关注 0票数 0

我有几张定制的干净支票。例如,一个在cppcoreguidelines模块中,另一个在misc模块中。他们工作得很好。现在,我通过自定义模块扩展clang,将它们组织起来。

当我重新构建时,它会成功,但是当我运行./clang-tidy -list-checks -checks=*时,我的检查将不会出现。

下面是我在添加名为sw的自定义模块时所做的工作

  • sw下创建了一个子目录/clang-tools-extra/clang-tidy/
  • 通过以下方式更新/clang-tools-extra/clang-tidy/CMakeLists.txt
代码语言:javascript
复制
- adding `add_subdirectory(sw)` right below `add_subdirectory(readability)`
- listing `clangTidySWModule` inside the `set(ALL_CLANG_TIDY_CHECKS ...)` command
  • 添加了具有以下内容的/clang-tools-extra/clang-tidy/sw/CMakeLists.txt
代码语言:javascript
复制
set(LLVM_LINK_COMPONENTS
  FrontendOpenMP
  Support
  )

add_clang_library(clangTidySWModule
  AllCapsEnumeratorsCheck.cpp
  CatchByConstReferenceCheck.cpp
  SWTidyModule.cpp

  LINK_LIBS
  clangTidy
  clangTidyUtils

  DEPENDS
  omp_gen
  )

clang_target_link_libraries(clangTidySWModule
  PRIVATE
  clangAnalysis
  clangAST
  clangASTMatchers
  clangBasic
  clangLex
  clangTooling
  )
  • 添加了具有以下内容的/clang-tools-extra/clang-tidy/sw/SWTidyModule.cpp
代码语言:javascript
复制
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "AllCapsEnumeratorsCheck.h"
#include "CatchByConstReferenceCheck.h"

namespace clang {
namespace tidy {
namespace sw {

class SWModule : public ClangTidyModule {
public:
  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
    CheckFactories.registerCheck<AllCapsEnumeratorsCheck>(
        "sw-all-caps-enumerators");
    CheckFactories.registerCheck<CatchByConstReferenceCheck>(
        "sw-catch-by-const-reference");
  }
};

// Register the SWModule using this statically initialized variable.
static ClangTidyModuleRegistry::Add<SWModule>
    X("sw-module", "Adds my custom checks.");

} // namespace sw

// This anchor is used to force the linker to link in the generated object file
// and thus register the ReadabilityModule.
volatile int SWModuleAnchorSource = 0;

} // namespace tidy
} // namespace clang

我添加了两个检查( all-caps-enumeratorscatch-by-const-reference ),就像之前在其他模块下所做的那样:

代码语言:javascript
复制
python3 add_new_check.py sw all-caps-enumerators
python3 add_new_check.py sw catch-by-const-reference

我是不是遗漏了什么?为什么我的支票没出现?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-30 15:18:44

我找到了我所缺少的这里。希望这篇文章至少能帮助其他人更快地找到答案,再加上准确地添加缺失部分的位置。

我在/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h中错过了下面的内容

代码语言:javascript
复制
// This anchor is used to force the linker to link the SWModule.
extern volatile int SWModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED SWModuleAnchorDestination =
    SWModuleAnchorSource;

现在我的支票出现了,我很高兴(:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73531240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档