<div dir="ltr">There is an alternative solution that is already working. With Clang tarball release you can build custom clang-tidy with additional checks outside of LLVM sources like you do with any other Clang tool after <a href="https://reviews.llvm.org/D73236" class="gmail-remarkup-link" target="_blank" rel="noreferrer" style="text-decoration-line:none;color:rgb(19,108,178);margin-top:0px;font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">https://reviews.llvm.org/D73236</a> and <a href="https://reviews.llvm.org/D73300" class="gmail-remarkup-link" target="_blank" rel="noreferrer" style="color:rgb(19,108,178);margin-top:0px;font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">https://reviews.llvm.org/D73300</a>. Minimal boilerplate looks like this:<div><br></div><div>#include <clang/Config/config.h><br>#include <llvm/Support/Compiler.h><br>#include <clang-tidy/tool/ClangTidyMain.h><br><br>namespace clang {<br>namespace tidy {<br><br>// This anchor is used to force the linker to link the CustomModule.<br>extern volatile int CustomModuleAnchorSource;<br>static int LLVM_ATTRIBUTE_UNUSED CustomModuleAnchorDestination =<br>    CustomModuleAnchorSource;<br><br>} // tidy<br>} // clang<br><br>int main(int argc, const char **argv) {<br>   return clang::tidy::clangTidyMain(argc, argv);<br>}<br></div><div><br></div><div>I think it is reasonable alternative to clang-tidy plugins that works everywhere. Anyway clang-tidy plugins are version dependent so they will work with almost the same version of Clang only.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 23, 2020 at 2:24 PM Aaron Ballman via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, Jun 23, 2020 at 8:42 AM Nathan James via cfe-dev<br>
<<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Dear List,<br>
><br>
> I've heard a few small discussions about this topic and they seem to be<br>
> positive so I thought I'd query it here to see what the consensus is.<br>
><br>
> The general idea is to add a `add-plugin` command line option to clang-<br>
> tidy, akin to the plugins clang supports. This will be used to load one<br>
> or more plugins that link additional ClangTidyModules to better enable<br>
> users to utilise their own custom clang-tidy checks.<br>
><br>
> Currently the only way to do that is to download the entire llvm<br>
> source, create the module and link it into clang-tidy the same way all<br>
> the built-in modules are linked.<br>
><br>
> Under this new proposal one could just get the required libraries. Then<br>
> build their module out of tree and tell clang-tidy to link at runtime<br>
> with `-add-plugin=<path-to-module>` command line option.<br>
><br>
> A typical modules source code could be as simple as this for just one<br>
> check<br>
><br>
> -----------------------------------------------------------------------<br>
><br>
> #include "ClangTidy.h"<br>
> #include "ClangTidyCheck.h"<br>
> #include "ClangTidyModule.h"<br>
> #include "ClangTidyModuleRegistry.h"<br>
><br>
> using namespace clang;<br>
> using namespace clang::tidy;<br>
> using namespace clang::ast_matchers;<br>
> using namespace llvm;<br>
><br>
> class AwesomeFunctionCheck : public ClangTidyCheck {<br>
> public:<br>
>   using ClangTidyCheck::ClangTidyCheck;<br>
><br>
>   void registerMatchers(MatchFinder *Finder) override {<br>
>     Finder->addMatcher(<br>
>         functionDecl(unless(matchesName("Awesome$"))).bind("Function"),<br>
> this);<br>
>   }<br>
>   void check(const MatchFinder::MatchResult &Result) override {<br>
>     const auto *Function =<br>
> Result.Nodes.getNodeAs<FunctionDecl>("Function");<br>
>     diag(Function->getLocation(), "Function '%0' is not sufficiently<br>
> awesome")<br>
>         << Function<br>
>         << FixItHint::CreateReplacement(<br>
>                Function->getLocation(),<br>
>                (Function->getName() + "Awesome").str());<br>
>   }<br>
> };<br>
><br>
> class MyPluginModule : public ClangTidyModule {<br>
> public:<br>
>   void addCheckFactories(ClangTidyCheckFactories &CheckFactories)<br>
> override {<br>
>     CheckFactories.registerCheck<AwesomeFunctionCheck>(<br>
>         "my-plugin-awesome-function");<br>
>   }<br>
> };<br>
><br>
> // Register the MyPluginModule using this statically initialized<br>
> variable.<br>
> static ClangTidyModuleRegistry::Add<MyPluginModule><br>
>     X("my-plugin-module", "Adds my plugin checks.");<br>
><br>
> -----------------------------------------------------------------------<br>
><br>
> Obviously larger code bases may want multiple different checks in which<br>
> case it would be nicer to seperate the checks out into their own<br>
> implementation files (The way clang tidy is written now).<br>
><br>
> Once a plugin is linked its checks will still need to be turned on<br>
> using the `Checks` option from config files or the `checks` command<br>
> line option.<br>
><br>
> There will also need to be some documentation detailing how to create<br>
> plugins. <a href="https://clang.llvm.org/extra/clang-tidy/Contributing.html" rel="noreferrer" target="_blank">https://clang.llvm.org/extra/clang-tidy/Contributing.html</a><br>
> already has some useful information but not everything needed for this purpose.<br>
><br>
> On the point of getting the required libraries I'm not too sure how<br>
> everything is packaged. From what I can see the clangTidy libraries are<br>
> packaged but the headers aren't. That would probably need addressing as<br>
> well.<br>
<br>
I recently had a use case at work where we wanted to write a<br>
clang-tidy plugin but couldn't due to the lack of infrastructure and<br>
so we wound up writing a clang static analyzer plugin instead.<br>
Unfortunately, because LLVM-based plugin systems do not work on<br>
Windows, this functionality still wouldn't have helped us out for our<br>
needs. That said, I'm still 100% behind the proposal -- even with the<br>
general plugin limitations this is a feature I have often wished for<br>
and been surprised wasn't supported.<br>
<br>
~Aaron<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>