[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-13 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.


https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From 0c1f7d83c765a6c829543db9719420f7bf7eb02d Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export-fixes flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  2 +
 .../test/clang-tidy/check_clang_tidy.py   | 74 ++-
 2 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b66be44e9f8a6f..1405fb0df1f8dd 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument 
`-export-fixes`
+  to aid in clang-tidy and test development.
 
 New checks
 ^^
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..6d4b466afa691a 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export-fixes, the tool simply exports fixes to a provided
+file and does not run FileCheck.
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
+
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export-fixes=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export_fixes = args.export_fixes
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,13 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ [
+"-fix"
+if self.export_fixes is None
+else "--export-fixes=" + self.export_fixes
+]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +273,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export_fixes is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export_fixes is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +304,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From b9cc1681c73a8af31df38e5f96cf19f14dbc0ccd Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export-fixes flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  2 +
 .../test/clang-tidy/check_clang_tidy.py   | 70 ++-
 2 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b66be44e9f8a6f..1405fb0df1f8dd 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument 
`-export-fixes`
+  to aid in clang-tidy and test development.
 
 New checks
 ^^
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..291a70e37827c0 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export-fixes, the tool simply exports fixes to a provided
+file and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export-fixes=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export_fixes = args.export_fixes
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export_fixes is None else "--export-fixes=" + 
self.export_fixes]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export_fixes is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export_fixes is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+formatter_class=argparse.RawDescriptionHelpFormatter,
+)
 

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Edwin Vane via cfe-commits


@@ -298,7 +318,19 @@ def parse_arguments():
 type=csv,
 help="comma-separated list of FileCheck suffixes",
 )
-parser.add_argument("-std", type=csv, default=["c++11-or-later"])
+parser.add_argument(
+"-export",

revane wrote:

Done

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Edwin Vane via cfe-commits


@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export

revane wrote:

Done

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From b01f3305c350afb543afb37cc9f8b98be3ccb06c Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export-fixes flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  2 +
 .../test/clang-tidy/check_clang_tidy.py   | 72 +--
 2 files changed, 54 insertions(+), 20 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b66be44e9f8a6f..1405fb0df1f8dd 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument 
`-export-fixes`
+  to aid in clang-tidy and test development.
 
 New checks
 ^^
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..3cee5df58d5c8c 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#rgs!/usr/bin/env python3
 #
 # ===- check_clang_tidy.py - ClangTidy Test Helper *- python 
-*--===#
 #
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export-fixes, the tool simply exports fixes to a provided
+file and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export-fixes=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export_fixes = args.export_fixes
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export_fixes is None else "--export-fixes=" + 
self.export_fixes]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export_fixes is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export_fixes is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = 

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Piotr Zegar via cfe-commits


@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export

PiotrZSL wrote:

export_fixes

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Piotr Zegar via cfe-commits


@@ -298,7 +318,19 @@ def parse_arguments():
 type=csv,
 help="comma-separated list of FileCheck suffixes",
 )
-parser.add_argument("-std", type=csv, default=["c++11-or-later"])
+parser.add_argument(
+"-export",

PiotrZSL wrote:

can't we call it export-fixes ?

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL requested changes to this pull request.

Rename this from -export to -export-fixes, because that's what it is, and could 
land.

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Edwin Vane via cfe-commits

revane wrote:

@AaronBallman Other reviewers you would suggest?

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From 91d07d734c92ee807bc804c2d08374771cae8c0a Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  2 +
 .../test/clang-tidy/check_clang_tidy.py   | 70 ++-
 2 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b66be44e9f8a6f..59d50f49120fc0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument `-export`
+  to aid in clang-tidy and test development.
 
 New checks
 ^^
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..4065eb5cbf2cdb 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export is None else "--export-fixes=" + 
self.export]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+formatter_class=argparse.RawDescriptionHelpFormatter,
+)
 parser.add_argument("-expect-clang-tidy-error", 

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From 91d07d734c92ee807bc804c2d08374771cae8c0a Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  2 +
 .../test/clang-tidy/check_clang_tidy.py   | 70 ++-
 2 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b66be44e9f8a6f..59d50f49120fc0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument `-export`
+  to aid in clang-tidy and test development.
 
 New checks
 ^^
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..4065eb5cbf2cdb 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export is None else "--export-fixes=" + 
self.export]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+formatter_class=argparse.RawDescriptionHelpFormatter,
+)
 parser.add_argument("-expect-clang-tidy-error", 

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread via cfe-commits


@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument `-export`

EugeneZelenko wrote:

Sorry, my bad - I missed that tool names are different :-( Please drop later 
commit.

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread Edwin Vane via cfe-commits


@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument `-export`

revane wrote:

Done. Could you explain the rules for when new points are warranted? It appears 
there is a new point for each checker so I guessed there would be a new point 
for each different tool.

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From 8dda3028dc7f83ced4cdc2475858075d45e04646 Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +-
 .../test/clang-tidy/check_clang_tidy.py   | 70 ++-
 2 files changed, 54 insertions(+), 20 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b66be44e9f8a6f..b745ac1e886336 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -99,7 +99,9 @@ Improvements to clang-tidy
 
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
-  similar fashion to what `-header-filter` does for header files.
+  similar fashion to what `-header-filter` does for header files. Improved
+  :program:`check_clang_tidy.py` script. Added argument `-export` to aid in
+  clang-tidy and test development.
 
 New checks
 ^^
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..4065eb5cbf2cdb 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export is None else "--export-fixes=" + 
self.export]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+formatter_class=argparse.RawDescriptionHelpFormatter,
+

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread via cfe-commits


@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument `-export`

EugeneZelenko wrote:

Please merge with previous entry.

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread Edwin Vane via cfe-commits

revane wrote:

@PiotrZSL @carlosgalvezp @LegalizeAdulthood @njames93 For your consideration.  

https://github.com/llvm/llvm-project/pull/88186
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From 91d07d734c92ee807bc804c2d08374771cae8c0a Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  2 +
 .../test/clang-tidy/check_clang_tidy.py   | 70 ++-
 2 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b66be44e9f8a6f..59d50f49120fc0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument `-export`
+  to aid in clang-tidy and test development.
 
 New checks
 ^^
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..4065eb5cbf2cdb 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export is None else "--export-fixes=" + 
self.export]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+formatter_class=argparse.RawDescriptionHelpFormatter,
+)
 parser.add_argument("-expect-clang-tidy-error", 

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From bc5071c54e825d7036b6a54f4dfa02268e3a5c72 Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 .../test/clang-tidy/check_clang_tidy.py   | 70 ++-
 1 file changed, 51 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..4065eb5cbf2cdb 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export is None else "--export-fixes=" + 
self.export]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+formatter_class=argparse.RawDescriptionHelpFormatter,
+)
 parser.add_argument("-expect-clang-tidy-error", action="store_true")
 parser.add_argument("-resource-dir")
 parser.add_argument("-assume-filename")
@@ -298,7 +318,19 @@ def parse_arguments():
 type=csv,
 help="comma-separated list of FileCheck suffixes",
 )
-parser.add_argument("-std", type=csv, default=["c++11-or-later"])
+parser.add_argument(
+"-export",
+default=None,
+type=str,
+metavar="file",
+help="A file to export fixes into instead of fixing.",
+)
+parser.add_argument(
+"-std",
+type=csv,
+default=["c++11-or-later"],
+help="Passed to clang. Special -or-later values are expanded.",
+)
 return parser.parse_known_args()
 
 


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-09 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From 631ac048e4b8fcbc242be54f48e5bf432a6a5b3d Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 .../test/clang-tidy/check_clang_tidy.py   | 70 ++-
 1 file changed, 51 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..4065eb5cbf2cdb 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export is None else "--export-fixes=" + 
self.export]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+formatter_class=argparse.RawDescriptionHelpFormatter,
+)
 parser.add_argument("-expect-clang-tidy-error", action="store_true")
 parser.add_argument("-resource-dir")
 parser.add_argument("-assume-filename")
@@ -298,7 +318,19 @@ def parse_arguments():
 type=csv,
 help="comma-separated list of FileCheck suffixes",
 )
-parser.add_argument("-std", type=csv, default=["c++11-or-later"])
+parser.add_argument(
+"-export",
+default=None,
+type=str,
+metavar="file",
+help="A file to export fixes into instead of fixing.",
+)
+parser.add_argument(
+"-std",
+type=csv,
+default=["c++11-or-later"],
+help="Passed to clang. Special -or-later values are expanded.",
+)
 return parser.parse_known_args()
 
 


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-09 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
2950283dddab03c183c1be2d7de9d4999cc86131...596037423faeebf01759158b5a93a3e933978941
 clang-tools-extra/test/clang-tidy/check_clang_tidy.py
``





View the diff from darker here.


``diff
--- check_clang_tidy.py 2024-04-09 20:07:52.00 +
+++ check_clang_tidy.py 2024-04-09 20:17:24.042204 +
@@ -112,19 +112,18 @@
 
 self.clang_extra_args = []
 self.clang_tidy_extra_args = extra_args
 if "--" in extra_args:
 i = self.clang_tidy_extra_args.index("--")
-self.clang_extra_args = self.clang_tidy_extra_args[i + 1:]
+self.clang_extra_args = self.clang_tidy_extra_args[i + 1 :]
 self.clang_tidy_extra_args = self.clang_tidy_extra_args[:i]
 
 # If the test does not specify a config style, force an empty one; 
otherwise
 # auto-detection logic can discover a ".clang-tidy" file that is not 
related to
 # the test.
 if not any(
-[re.match("^-?-config(-file)?=", arg)
- for arg in self.clang_tidy_extra_args]
+[re.match("^-?-config(-file)?=", arg) for arg in 
self.clang_tidy_extra_args]
 ):
 self.clang_tidy_extra_args.append("--config={}")
 
 if extension in [".m", ".mm"]:
 self.clang_extra_args = [
@@ -139,12 +138,11 @@
 # Tests should not rely on STL being available, and instead provide 
mock
 # implementations of relevant APIs.
 self.clang_extra_args.append("-nostdinc++")
 
 if self.resource_dir is not None:
-self.clang_extra_args.append(
-"-resource-dir=%s" % self.resource_dir)
+self.clang_extra_args.append("-resource-dir=%s" % 
self.resource_dir)
 
 def read_input(self):
 with open(self.input_file_name, "r", encoding="utf-8") as input_file:
 self.input_text = input_file.read()
 
@@ -156,20 +154,17 @@
 + ' but "%s" was given' % suffix
 )
 
 file_check_suffix = ("-" + suffix) if suffix else ""
 
-has_check_fix = self.fixes.check(
-file_check_suffix, self.input_text)
+has_check_fix = self.fixes.check(file_check_suffix, 
self.input_text)
 self.has_check_fixes = self.has_check_fixes or has_check_fix
 
-has_check_message = self.messages.check(
-file_check_suffix, self.input_text)
+has_check_message = self.messages.check(file_check_suffix, 
self.input_text)
 self.has_check_messages = self.has_check_messages or 
has_check_message
 
-has_check_note = self.notes.check(
-file_check_suffix, self.input_text)
+has_check_note = self.notes.check(file_check_suffix, 
self.input_text)
 self.has_check_notes = self.has_check_notes or has_check_note
 
 if has_check_note and has_check_message:
 sys.exit(
 "Please use either %s or %s but not both"
@@ -187,22 +182,22 @@
 def prepare_test_inputs(self):
 # Remove the contents of the CHECK lines to avoid CHECKs matching on
 # themselves.  We need to keep the comments to preserve line numbers 
while
 # avoiding empty lines which could potentially trigger 
formatting-related
 # checks.
-cleaned_test = re.sub(
-"// *CHECK-[A-Z0-9\\-]*:[^\r\n]*", "//", self.input_text)
+cleaned_test = re.sub("// *CHECK-[A-Z0-9\\-]*:[^\r\n]*", "//", 
self.input_text)
 write_file(self.temp_file_name, cleaned_test)
 write_file(self.original_file_name, cleaned_test)
 
 def run_clang_tidy(self):
 args = (
 [
 "clang-tidy",
 self.temp_file_name,
-] + ["-fix" if self.export is None else "--export-fixes=" + 
self.export] +
-[
+]
++ ["-fix" if self.export is None else "--export-fixes=" + 
self.export]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
 + ["--"]
 + self.clang_extra_args
@@ -328,12 +323,16 @@
 default=None,
 type=str,
 metavar="file",
 help="A file to export fixes into instead of fixing.",
 )
-parser.add_argument("-std", type=csv, default=["c++11-or-later"],
-help="Passed to clang. Special -or-later values are 
expanded.")
+parser.add_argument(
+"-std",
+type=csv,
+default=["c++11-or-later"],
+help="Passed to clang. Special -or-later values are expanded.",
+)
 return parser.parse_known_args()
 
 
 def main():
 args, extra_args = parse_arguments()

``





[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-09 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Edwin Vane (revane)


Changes

Makes it possible to export fixes from running llvm-lit on a clang-tidy test. 
To enable, modify the RUN invocation directly in the test with the new -export 
flag. llvm-lit will report the test passed and fixes can be found in the file 
specified to the -export flag.

---
Full diff: https://github.com/llvm/llvm-project/pull/88186.diff


1 Files Affected:

- (modified) clang-tools-extra/test/clang-tidy/check_clang_tidy.py (+59-26) 


``diff
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..38728df5c48716 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -102,14 +114,15 @@ def __init__(self, args, extra_args):
 self.clang_tidy_extra_args = extra_args
 if "--" in extra_args:
 i = self.clang_tidy_extra_args.index("--")
-self.clang_extra_args = self.clang_tidy_extra_args[i + 1 :]
+self.clang_extra_args = self.clang_tidy_extra_args[i + 1:]
 self.clang_tidy_extra_args = self.clang_tidy_extra_args[:i]
 
 # If the test does not specify a config style, force an empty one; 
otherwise
 # auto-detection logic can discover a ".clang-tidy" file that is not 
related to
 # the test.
 if not any(
-[re.match("^-?-config(-file)?=", arg) for arg in 
self.clang_tidy_extra_args]
+[re.match("^-?-config(-file)?=", arg)
+ for arg in self.clang_tidy_extra_args]
 ):
 self.clang_tidy_extra_args.append("--config={}")
 
@@ -128,7 +141,8 @@ def __init__(self, args, extra_args):
 self.clang_extra_args.append("-nostdinc++")
 
 if self.resource_dir is not None:
-self.clang_extra_args.append("-resource-dir=%s" % 
self.resource_dir)
+self.clang_extra_args.append(
+"-resource-dir=%s" % self.resource_dir)
 
 def read_input(self):
 with open(self.input_file_name, "r", encoding="utf-8") as input_file:
@@ -144,13 +158,16 @@ def get_prefixes(self):
 
 file_check_suffix = ("-" + suffix) if suffix else ""
 
-has_check_fix = self.fixes.check(file_check_suffix, 
self.input_text)
+has_check_fix = self.fixes.check(
+file_check_suffix, self.input_text)
 self.has_check_fixes = self.has_check_fixes or has_check_fix
 
-has_check_message = self.messages.check(file_check_suffix, 
self.input_text)
+has_check_message = self.messages.check(
+file_check_suffix, self.input_text)
 self.has_check_messages = self.has_check_messages or 
has_check_message
 
-has_check_note = self.notes.check(file_check_suffix, 
self.input_text)
+has_check_note = 

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-09 Thread Edwin Vane via cfe-commits

https://github.com/revane created 
https://github.com/llvm/llvm-project/pull/88186

Makes it possible to export fixes from running llvm-lit on a clang-tidy test. 
To enable, modify the RUN invocation directly in the test with the new -export 
flag. llvm-lit will report the test passed and fixes can be found in the file 
specified to the -export flag.

>From 596037423faeebf01759158b5a93a3e933978941 Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 .../test/clang-tidy/check_clang_tidy.py   | 85 +--
 1 file changed, 59 insertions(+), 26 deletions(-)

diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..38728df5c48716 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -102,14 +114,15 @@ def __init__(self, args, extra_args):
 self.clang_tidy_extra_args = extra_args
 if "--" in extra_args:
 i = self.clang_tidy_extra_args.index("--")
-self.clang_extra_args = self.clang_tidy_extra_args[i + 1 :]
+self.clang_extra_args = self.clang_tidy_extra_args[i + 1:]
 self.clang_tidy_extra_args = self.clang_tidy_extra_args[:i]
 
 # If the test does not specify a config style, force an empty one; 
otherwise
 # auto-detection logic can discover a ".clang-tidy" file that is not 
related to
 # the test.
 if not any(
-[re.match("^-?-config(-file)?=", arg) for arg in 
self.clang_tidy_extra_args]
+[re.match("^-?-config(-file)?=", arg)
+ for arg in self.clang_tidy_extra_args]
 ):
 self.clang_tidy_extra_args.append("--config={}")
 
@@ -128,7 +141,8 @@ def __init__(self, args, extra_args):
 self.clang_extra_args.append("-nostdinc++")
 
 if self.resource_dir is not None:
-self.clang_extra_args.append("-resource-dir=%s" % 
self.resource_dir)
+self.clang_extra_args.append(
+"-resource-dir=%s" % self.resource_dir)
 
 def read_input(self):
 with open(self.input_file_name, "r", encoding="utf-8") as input_file:
@@ -144,13 +158,16 @@ def get_prefixes(self):
 
 file_check_suffix = ("-" + suffix) if suffix else ""
 
-has_check_fix = self.fixes.check(file_check_suffix, 
self.input_text)
+has_check_fix = self.fixes.check(
+file_check_suffix, self.input_text)
 self.has_check_fixes = self.has_check_fixes or has_check_fix
 
-has_check_message =