Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-07 Thread Matthias Gehre via cfe-commits
mgehre added a subscriber: mgehre.


Comment at: clang-tidy/rename_check.py:39
@@ +38,3 @@
+  if len(sys.argv) != 4:
+print('Usage: rename_check.py  , e.g.\n')
+print('rename_check.py misc awesome-functions new-awesome-function\n')

Should be
```
Usage: rename_check.py   
```
?


Repository:
  rL LLVM

http://reviews.llvm.org/D13440



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


Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-07 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-tidy/rename_check.py:3
@@ +2,3 @@
+#
+#===- add_new_check.py - clang-tidy check generator --*- python 
-*--===#
+#

Please update the script name and description in the comment.


Comment at: clang-tidy/rename_check.py:18
@@ +17,3 @@
+def replaceInFile(fileName, sFrom, sTo):
+txt = None
+with open(fileName, "r") as f:

Please use 2 spaces for indentation.


Comment at: clang-tidy/rename_check.py:39
@@ +38,3 @@
+  if len(sys.argv) != 4:
+print('Usage: rename_check.py  , e.g.\n')
+print('rename_check.py misc awesome-functions new-awesome-function\n')

New check name is missing.


Comment at: clang-tidy/rename_check.py:52
@@ +51,3 @@
+  clang_tidy_path = os.path.dirname(sys.argv[0])
+  module_path = os.path.join(clang_tidy_path, module)
+

This should be updated similarly to the add_new_check.py change in 
http://reviews.llvm.org/D13313.


Comment at: clang-tidy/rename_check.py:64
@@ +63,3 @@
+  replaceInFile(filename, header_guard_old, header_guard_new)
+  replaceInFile(filename, check_name, check_name_new)
+  replaceInFile(filename, check_name_camel, check_name_new_camel)

Would be nice, if this script took care of updating the file comments in .h and 
.cpp files including it's padding with dashes, e.g.:

  //===--- ProTypeReinterpretCastCheck.cpp - 
clang-tidy--===//



Repository:
  rL LLVM

http://reviews.llvm.org/D13440



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


Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-07 Thread Piotr Zegar via cfe-commits
ClockMan marked 5 inline comments as done.


Comment at: clang-tidy/rename_check.py:53
@@ +52,3 @@
+  return newFileName
+
+def getListOfFiles(clang_tidy_path):

Not sure what you mean...


Repository:
  rL LLVM

http://reviews.llvm.org/D13440



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


Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-07 Thread Piotr Zegar via cfe-commits
ClockMan updated this revision to Diff 36801.
ClockMan added a comment.

Corrected review issues.


Repository:
  rL LLVM

http://reviews.llvm.org/D13440

Files:
  clang-tidy/rename_check.py

Index: clang-tidy/rename_check.py
===
--- /dev/null
+++ clang-tidy/rename_check.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+#
+#===- rename_check.py - clang-tidy check renamer -*- python 
-*--===#
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#======#
+
+import os
+import re
+import sys
+import glob
+
+def replaceInFile(fileName, sFrom, sTo):
+  if sFrom == sTo:
+return
+  txt = None
+  with open(fileName, "r") as f:
+txt = f.read()
+
+  if sFrom not in txt:
+return
+
+  txt = txt.replace(sFrom, sTo)
+  print("Replace '%s' -> '%s' in '%s'" % (sFrom, sTo, fileName))
+  with open(fileName, "w") as f:
+f.write(txt)
+
+def generateCommentLineHeader(filename):
+  return ''.join(['//===--- ',
+  os.path.basename(filename),
+  ' - clang-tidy ',
+  '-' * max(0, 42 - len(os.path.basename(filename))),
+  '*- C++ -*-===//'])
+
+def generateCommentLineSource(filename):
+  return ''.join(['//===--- ',
+  os.path.basename(filename),
+  ' - clang-tidy',
+  '-' * max(0, 52 - len(os.path.basename(filename))),
+  '-===//'])
+
+def fileRename(fileName, sFrom, sTo):
+  if sFrom not in fileName:
+return fileName
+  newFileName = fileName.replace(sFrom, sTo)
+  print("Rename '%s' -> '%s'" % (fileName, newFileName))
+  os.rename(fileName, newFileName)
+  return newFileName
+
+def getListOfFiles(clang_tidy_path):
+  files =  glob.glob(os.path.join(clang_tidy_path,'*'))
+  for dirname in files:
+if os.path.isdir(dirname):
+  files += glob.glob(os.path.join(dirname,'*'))
+  files += glob.glob(os.path.join(clang_tidy_path,'..', 'test', 'clang-tidy', 
'*'))
+  files += glob.glob(os.path.join(clang_tidy_path,'..', 'docs', 'clang-tidy', 
'checks', '*'))
+  return [filename for filename in files if os.path.isfile(filename)]
+
+def main():
+  if len(sys.argv) != 4:
+print('Usage: rename_check.py   
\n')
+print('   example: rename_check.py misc awesome-functions 
new-awesome-function')
+return
+
+  module = sys.argv[1].lower()
+  check_name = sys.argv[2]
+  check_name_camel = ''.join(map(lambda elem: elem.capitalize(),
+ check_name.split('-'))) + 'Check'
+  check_name_new = sys.argv[3]
+  check_name_new_camel = ''.join(map(lambda elem: elem.capitalize(),
+ check_name_new.split('-'))) + 'Check'
+
+  clang_tidy_path = os.path.dirname(sys.argv[0])
+
+  header_guard_old = module.upper() + '_' + check_name.upper().replace('-', 
'_')
+  header_guard_new = module.upper() + '_' + 
check_name_new.upper().replace('-', '_')
+
+  for filename in getListOfFiles(clang_tidy_path):
+originalName = filename
+filename = fileRename(filename, check_name, check_name_new)
+filename = fileRename(filename, check_name_camel, check_name_new_camel)
+replaceInFile(filename, generateCommentLineHeader(originalName), 
generateCommentLineHeader(filename))
+replaceInFile(filename, generateCommentLineSource(originalName), 
generateCommentLineSource(filename))
+replaceInFile(filename, header_guard_old, header_guard_new)
+replaceInFile(filename, check_name, check_name_new)
+replaceInFile(filename, check_name_camel, check_name_new_camel)
+
+if __name__ == '__main__':
+  main()


Index: clang-tidy/rename_check.py
===
--- /dev/null
+++ clang-tidy/rename_check.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+#
+#===- rename_check.py - clang-tidy check renamer -*- python -*--===#
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#======#
+
+import os
+import re
+import sys
+import glob
+
+def replaceInFile(fileName, sFrom, sTo):
+  if sFrom == sTo:
+return
+  txt = None
+  with open(fileName, "r") as f:
+txt = f.read()
+
+  if sFrom not in txt:
+return
+
+  txt = txt.replace(sFrom, sTo)
+  print("Replace '%s' -> '%s' in '%s'" % (sFrom, sTo, fileName))
+  with open(fileName, "w") as f:
+f.write(txt)
+
+def generateCommentLineHeader(filename):
+  return ''.join(['//===--- ',
+  os.path.basename(filename),
+  ' - clang-tidy ',
+  '-' * max(0, 42 - len(os.path.basename(filename))),
+  '*- C++ -*-===//'])
+
+d

Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-07 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-tidy/rename_check.py:53
@@ +52,3 @@
+  return newFileName
+
+def getListOfFiles(clang_tidy_path):

ClockMan wrote:
> Not sure what you mean...
I meant that after that patch the module file name can be more complex. 
However, this doesn't seem relevant as you don't generate the module file name.


Repository:
  rL LLVM

http://reviews.llvm.org/D13440



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


Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-09 Thread Piotr Zegar via cfe-commits
ClockMan marked 3 inline comments as done.
ClockMan added a comment.

Repository:
  rL LLVM

http://reviews.llvm.org/D13440



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


Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-09 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good. Do you have commit rights? If no, please have someone commit this 
for you. I won't be able to help with this soon, unfortunately.


Repository:
  rL LLVM

http://reviews.llvm.org/D13440



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


Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-09 Thread Aaron Ballman via cfe-commits
On Fri, Oct 9, 2015 at 11:21 AM, Alexander Kornienko  wrote:
> alexfh accepted this revision.
> alexfh added a comment.
> This revision is now accepted and ready to land.
>
> Looks good. Do you have commit rights? If no, please have someone commit this 
> for you. I won't be able to help with this soon, unfortunately.

If not, I can commit.

~Aaron

>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D13440
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-10 Thread Piotr Zegar via cfe-commits
ClockMan added a comment.

No, I don't have commits rights


Repository:
  rL LLVM

http://reviews.llvm.org/D13440



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