https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/120547

>From 2927ef2ccd286e1efeb12ef12eb5f0fd2dcf2454 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0...@163.com>
Date: Thu, 19 Dec 2024 15:23:02 +0800
Subject: [PATCH 1/4] [clang-tidy] support parameters file in command line

Fixes: #103499
---
 .../clang-tidy/tool/ClangTidyMain.cpp            | 16 ++++++++++++++++
 clang-tools-extra/docs/ReleaseNotes.rst          |  2 ++
 .../infrastructure/Inputs/param/parameters.txt   |  2 ++
 .../infrastructure/read-parameters-from-file.cpp |  5 +++++
 4 files changed, 25 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/read-parameters-from-file.cpp

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]

>From f76fc26378f8c7bdf313f07df35d99e7668ee929 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0...@163.com>
Date: Thu, 19 Dec 2024 23:53:18 +0800
Subject: [PATCH 2/4] fix error handling

---
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp            | 2 +-
 .../infrastructure/read-parameters-from-file-error.cpp         | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/read-parameters-from-file-error.cpp

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 9aebd450e458c1..fab7e37b882bd6 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -564,7 +564,7 @@ int clangTidyMain(int argc, const char **argv) {
           : llvm::cl::TokenizeGNUCommandLine;
   llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
   if (llvm::Error Err = ECtx.expandResponseFiles(Args)) {
-    llvm::WithColor::error() << Err << "\n";
+    llvm::WithColor::error() << llvm::toString(std::move(Err)) << "\n";
     return 1;
   }
   argc = static_cast<int>(Args.size());
diff --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/read-parameters-from-file-error.cpp
 
b/clang-tools-extra/test/clang-tidy/infrastructure/read-parameters-from-file-error.cpp
new file mode 100644
index 00000000000000..183f44365137c2
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/infrastructure/read-parameters-from-file-error.cpp
@@ -0,0 +1,3 @@
+// RUN: echo @%t.param > %t.param && not clang-tidy %s @%t.param -- 2>&1 | 
FileCheck %s
+
+// CHECK: recursive expansion of

>From 68c9409cd68797d66a816056c99036ad391b9a24 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0...@163.com>
Date: Fri, 20 Dec 2024 07:59:54 +0800
Subject: [PATCH 3/4] add comment

---
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index fab7e37b882bd6..caca65c1cf481f 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -557,6 +557,7 @@ int clangTidyMain(int argc, const char **argv) {
   llvm::InitLLVM X(argc, argv);
   SmallVector<const char *> Args{argv, argv + argc};
 
+  // expand parameters file to argc and argv.
   llvm::BumpPtrAllocator Alloc;
   llvm::cl::TokenizerCallback Tokenizer =
       llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()

>From 5739d0327b314896927e88e4acaeac565872500c Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0...@163.com>
Date: Fri, 20 Dec 2024 08:04:36 +0800
Subject: [PATCH 4/4] update doc

---
 clang-tools-extra/docs/clang-tidy/index.rst | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/clang-tools-extra/docs/clang-tidy/index.rst 
b/clang-tools-extra/docs/clang-tidy/index.rst
index f053e57e8d4c84..9d812d8f5d534e 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -33,6 +33,13 @@ compilation options on the command line after ``--``:
 
   $ clang-tidy test.cpp -- -Imy_project/include -DMY_DEFINES ...
 
+If there are too many options to specify on the command line, you can store 
them
+in a parameter file, and use :program:`clang-tidy` with parameters file:
+
+.. code-block:: console
+
+  $ clang-tidy @parameters_file
+
 :program:`clang-tidy` has its own checks and can also run Clang Static Analyzer
 checks. Each check has a name and the checks to run can be chosen using the
 ``-checks=`` option, which specifies a comma-separated list of positive and

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to