Skip to content

Commit 2927ef2

Browse files
committed
[clang-tidy] support parameters file in command line
Fixes: #103499
1 parent b56d1ec commit 2927ef2

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
#include "../GlobList.h"
2121
#include "clang/Tooling/CommonOptionsParser.h"
2222
#include "llvm/ADT/StringSet.h"
23+
#include "llvm/Support/CommandLine.h"
2324
#include "llvm/Support/InitLLVM.h"
2425
#include "llvm/Support/PluginLoader.h"
2526
#include "llvm/Support/Process.h"
2627
#include "llvm/Support/Signals.h"
2728
#include "llvm/Support/TargetSelect.h"
2829
#include "llvm/Support/WithColor.h"
30+
#include "llvm/TargetParser/Host.h"
2931
#include <optional>
3032

3133
using namespace clang::tooling;
@@ -553,6 +555,20 @@ static llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> createBaseFS() {
553555

554556
int clangTidyMain(int argc, const char **argv) {
555557
llvm::InitLLVM X(argc, argv);
558+
SmallVector<const char *> Args{argv, argv + argc};
559+
560+
llvm::BumpPtrAllocator Alloc;
561+
llvm::cl::TokenizerCallback Tokenizer =
562+
llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
563+
? llvm::cl::TokenizeWindowsCommandLine
564+
: llvm::cl::TokenizeGNUCommandLine;
565+
llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
566+
if (llvm::Error Err = ECtx.expandResponseFiles(Args)) {
567+
llvm::WithColor::error() << Err << "\n";
568+
return 1;
569+
}
570+
argc = static_cast<int>(Args.size());
571+
argv = Args.data();
556572

557573
// Enable help for -load option, if plugins are enabled.
558574
if (cl::Option *LoadOpt = cl::getRegisteredOptions().lookup("load"))

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Improvements to clang-tidy
115115
- Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise
116116
happening on certain platforms when interrupting the script.
117117

118+
- Improved :program:`clang-tidy` by accepting parameters file in command line.
119+
118120
- Removed :program:`clang-tidy`'s global options for most of checks. All options
119121
are changed to local options except `IncludeStyle`, `StrictMode` and
120122
`IgnoreMacros`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-checks='-*,llvm-namespace-comment'
2+
--warnings-as-errors=llvm-namespace-comment
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: not clang-tidy %s @%S/Inputs/param/parameters.txt -- | FileCheck %s
2+
3+
namespace i {
4+
}
5+
// CHECK: error: namespace 'i' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors]

0 commit comments

Comments
 (0)