[PATCH] [clang-tidy] Add a little python script that can run clang-tidy and apply fixes over an entire codebase.

Manuel Klimek klimek at google.com
Mon Sep 8 03:53:47 PDT 2014


================
Comment at: clang-tidy/tool/run-clang-tidy.py:11
@@ +10,3 @@
+#===------------------------------------------------------------------------===#
+# TODO: Integrate with clang-tidy-diff.py
+
----------------
FIXME

================
Comment at: clang-tidy/tool/run-clang-tidy.py:13
@@ +12,3 @@
+
+r"""
+Parallel clang-tidy runner
----------------
Is that for the \ at the end of the run-clang-tidy invocation?

================
Comment at: clang-tidy/tool/run-clang-tidy.py:63-66
@@ +62,6 @@
+  start = ['clang-tidy']
+  if header_filter is not None:
+    start.append('-header-filter=' + header_filter)
+  else:
+    start.append('-header-filter=^' + build_path + '/.*')
+  if checks:
----------------
The second branch might need a comment.

================
Comment at: clang-tidy/tool/run-clang-tidy.py:71-72
@@ +70,4 @@
+    start.append('-export-fixes')
+    # mktemp is unsafe but the only reasonable way to get a temporary file name.
+    start.append(tempfile.mktemp(suffix='.yaml', dir=tmpdir))
+  start.append('-p=' + build_path)
----------------
Unsafe how? Also, why is it ok for us?

================
Comment at: clang-tidy/tool/run-clang-tidy.py:117
@@ +116,3 @@
+  # Build up a big regexy filter from all command line arguments.
+  bigre = re.compile('(' + ')|('.join(args.files) + ')')
+
----------------
Call that file_name_re or something? Then you can remove the comment on bigre.search...

================
Comment at: clang-tidy/tool/run-clang-tidy.py:127-130
@@ +126,6 @@
+        if bigre.search(name):  # Apply file name filter.
+          inv = get_tidy_invocation(name, args.checks, tmpdir, build_path,
+                                    args.header_filter)
+          print ' '.join(inv)
+          processes.append(subprocess.Popen(inv))
+
----------------
Since we have to break anyway, call it invocation. Otherwise I'll always read it as invitation. Which is kinda funny, but in a sad way.

================
Comment at: clang-tidy/tool/run-clang-tidy.py:144-145
@@ +143,4 @@
+
+      # os.wait() would be nicer, but it confuses Popen.
+      time.sleep(0.05)
+
----------------
Uuuh. Don't we have some way to pool() multiple processes?

================
Comment at: clang-tidy/tool/run-clang-tidy.py:147-153
@@ +146,9 @@
+
+  except KeyboardInterrupt:
+    # This is a sad hack. Unfortunately subprocess goes
+    # bonkers with ctrl-c and we start forking merrily.
+    print '\nCtrl-C detected, goodbye.'
+    if args.fix:
+      shutil.rmtree(tmpdir)  # Racy but we should be able to get away with it.
+    os.kill(0, 9)
+
----------------
This reads like one of Shakespeare's tragicomedies. Just less entertaining. Oh, Python.

================
Comment at: clang-tidy/tool/run-clang-tidy.py:156-162
@@ +155,9 @@
+  if args.fix:
+    print 'Applying fixes ...'
+    invocation = ['clang-apply-replacements']
+    if args.format:
+        invocation.append('-format')
+    invocation.append(tmpdir)
+    subprocess.call(invocation)
+    shutil.rmtree(tmpdir)
+
----------------
Pull into a function.

================
Comment at: clang-tidy/tool/run-clang-tidy.py:158-159
@@ +157,4 @@
+    invocation = ['clang-apply-replacements']
+    if args.format:
+        invocation.append('-format')
+    invocation.append(tmpdir)
----------------
Indent.

http://reviews.llvm.org/D5188






More information about the cfe-commits mailing list