[PATCH] D149088: [clang-format] Add run-clang-format.py script.

2023-04-25 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/tools/run-clang-format.py:63
+default="c,cc,cpp,cxx,c++,h,hh,hpp,hxx,h++")
+parser.add_argument('-style',
+help='formatting style',

what about 

```
run-clang-format ` --  
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149088/new/

https://reviews.llvm.org/D149088

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


[PATCH] D149088: [clang-format] Add run-clang-format.py script.

2023-04-25 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

is it possible to pass other arguments like `-n`  if not running in place is 
there any protection from prevent stdout/stderr from overlapping..?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149088/new/

https://reviews.llvm.org/D149088

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


[PATCH] D149088: [clang-format] Add run-clang-format.py script.

2023-04-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang/tools/run-clang-format.py:1
+#!/usr/bin/env python3
+#

Looks like Windows en of lines were mixed with UNIX ones.



Comment at: clang/tools/run-clang-format.py:26
+
+from __future__ import print_function
+import argparse

Is it really necessary since Python 3 is specified explicitly?



Comment at: clang/tools/run-clang-format.py:30
+import os
+import multiprocessing
+import queue

Should be before `os`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149088/new/

https://reviews.llvm.org/D149088

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


[PATCH] D149088: [clang-format] Add run-clang-format.py script.

2023-04-24 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

I guess I need to add a test in a similar that run-clang-tidy is tested, but 
I'd like to gather some initial review still.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149088/new/

https://reviews.llvm.org/D149088

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


[PATCH] D149088: [clang-format] Add run-clang-format.py script.

2023-04-24 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
curdeius requested review of this revision.
Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Fixes https://github.com/llvm/llvm-project/issues/62108.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149088

Files:
  clang/tools/CMakeLists.txt
  clang/tools/run-clang-format.py

Index: clang/tools/run-clang-format.py
===
--- /dev/null
+++ clang/tools/run-clang-format.py
@@ -0,0 +1,167 @@
+#!/usr/bin/env python3
+#
+#===- run-clang-format.py - Parallel clang-format runner *- python -*--===#
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===---===#
+
+"""
+Parallel clang-format runner
+==
+
+Runs clang-format over all files in given directories. Requires clang-format in $PATH.
+
+Example invocations.
+- Run clang-format on all files in the current working directory.
+run-clang-format.py
+
+- Run clang-format on all files in the chosen directories.
+run-clang-format.py dir1 dir2 dir3
+"""
+
+
+from __future__ import print_function
+import argparse
+import fnmatch
+import os
+import multiprocessing
+import queue
+import subprocess
+import sys
+import threading
+
+
+def glob_files(args):
+files = []
+
+extensions = args.extensions.split(',')
+
+for directory in args.directories:
+for root, _, filenames in os.walk(directory):
+for ext in extensions:
+for filename in fnmatch.filter(filenames, '*.' + ext):
+files.append(os.path.join(root, filename))
+
+return files
+
+
+def parse_args(argv=None):
+if argv is None:
+argv = sys.argv
+parser = argparse.ArgumentParser(
+description='Runs clang-format over all files in given directories.'
+' Requires clang-format in PATH.')
+parser.add_argument('--clang-format-binary', metavar='PATH',
+default='clang-format',
+help='path to clang-format binary')
+parser.add_argument('-e', '--extensions', dest='extensions',
+help='comma-delimited list of extensions used to glob source files',
+default="c,cc,cpp,cxx,c++,h,hh,hpp,hxx,h++")
+parser.add_argument('-style',
+help='formatting style',
+default="file")
+parser.add_argument('--no-inplace', dest='inplace', action='store_false',
+help='do not format files inplace, but write output to the console'
+' (useful for debugging)',
+default=True)
+parser.add_argument('-j', metavar='THREAD_COUNT', type=int, default=0,
+help='number of clang-format instances to be run in parallel')
+parser.add_argument('-v', '--verbose', action='store_true',
+help='output verbose comments')
+parser.add_argument(metavar='DIRPATH', dest='directories', nargs='*',
+help='path(s) used to glob source files')
+
+args = parser.parse_args(argv[1:])
+
+if not args.directories:
+args.directories = [os.getcwd()]
+
+check_clang_format_binary(args)
+
+return args
+
+
+def _get_format_invocation(args, filename):
+invocation = [args.clang_format_binary]
+invocation.append('-style=' + args.style)
+if args.inplace:
+invocation.append('-i')
+
+invocation.append(filename)
+return invocation
+
+
+def check_clang_format_binary(args):
+"""Checks if invoking supplied clang-format binary works."""
+try:
+subprocess.check_output([args.clang_format_binary, '--version'])
+except OSError:
+print('Unable to run clang-format. Is clang-format '
+  'binary correctly specified?',