[clang-tools-extra] [clang-tidy] support parameters file in command line (PR #120547)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 19 02:18:10 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Congcong Cai (HerrCai0907)
<details>
<summary>Changes</summary>
Fixes: #<!-- -->103499
---
Full diff: https://github.com/llvm/llvm-project/pull/120547.diff
4 Files Affected:
- (modified) clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp (+16)
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2)
- (added) clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt (+2)
- (added) clang-tools-extra/test/clang-tidy/infrastructure/read-parameters-from-file.cpp (+5)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index d42dafa8ffc362..9aebd450e458c1 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -20,12 +20,14 @@
#include "../GlobList.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "llvm/ADT/StringSet.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/WithColor.h"
+#include "llvm/TargetParser/Host.h"
#include <optional>
using namespace clang::tooling;
@@ -553,6 +555,20 @@ static llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> createBaseFS() {
int clangTidyMain(int argc, const char **argv) {
llvm::InitLLVM X(argc, argv);
+ SmallVector<const char *> Args{argv, argv + argc};
+
+ llvm::BumpPtrAllocator Alloc;
+ llvm::cl::TokenizerCallback Tokenizer =
+ llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
+ ? llvm::cl::TokenizeWindowsCommandLine
+ : llvm::cl::TokenizeGNUCommandLine;
+ llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
+ if (llvm::Error Err = ECtx.expandResponseFiles(Args)) {
+ llvm::WithColor::error() << Err << "\n";
+ return 1;
+ }
+ argc = static_cast<int>(Args.size());
+ argv = Args.data();
// Enable help for -load option, if plugins are enabled.
if (cl::Option *LoadOpt = cl::getRegisteredOptions().lookup("load"))
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 3fd7a4f9da18ad..5999a7134c7528 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,8 @@ Improvements to clang-tidy
- Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise
happening on certain platforms when interrupting the script.
+- Improved :program:`clang-tidy` by accepting parameters file in command line.
+
- Removed :program:`clang-tidy`'s global options for most of checks. All options
are changed to local options except `IncludeStyle`, `StrictMode` and
`IgnoreMacros`.
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt
new file mode 100644
index 00000000000000..a6d8fa7ee299fa
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt
@@ -0,0 +1,2 @@
+-checks='-*,llvm-namespace-comment'
+--warnings-as-errors=llvm-namespace-comment
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/read-parameters-from-file.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/read-parameters-from-file.cpp
new file mode 100644
index 00000000000000..9d8c40a2e7d415
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/read-parameters-from-file.cpp
@@ -0,0 +1,5 @@
+// RUN: not clang-tidy %s @%S/Inputs/param/parameters.txt -- | FileCheck %s
+
+namespace i {
+}
+// CHECK: error: namespace 'i' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors]
``````````
</details>
https://github.com/llvm/llvm-project/pull/120547
More information about the cfe-commits
mailing list