[PATCH] D59734: [clang-tidy] Handle missing yaml module in run-clang-tidy.py

Zinovy Nis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 23 05:40:32 PDT 2019


zinovy.nis updated this revision to Diff 191992.

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

https://reviews.llvm.org/D59734

Files:
  clang-tidy/tool/run-clang-tidy.py
  test/clang-tidy/run-clang-tidy.cpp


Index: test/clang-tidy/run-clang-tidy.cpp
===================================================================
--- test/clang-tidy/run-clang-tidy.cpp
+++ test/clang-tidy/run-clang-tidy.cpp
@@ -1,3 +1,4 @@
+// RUN: %run_clang_tidy --help
 // RUN: rm -rf %t
 // RUN: mkdir %t
 // RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %/t/test.cpp\",\"file\":\"%/t/test.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json
Index: clang-tidy/tool/run-clang-tidy.py
===================================================================
--- clang-tidy/tool/run-clang-tidy.py
+++ clang-tidy/tool/run-clang-tidy.py
@@ -47,7 +47,12 @@
 import tempfile
 import threading
 import traceback
-import yaml
+
+yaml_imported = True
+try:
+  import yaml
+except ImportError:
+  yaml_imported = False
 
 is_py2 = sys.version[0] == '2'
 
@@ -199,9 +204,10 @@
                       'headers to output diagnostics from. Diagnostics from '
                       'the main file of each translation unit are always '
                       'displayed.')
-  parser.add_argument('-export-fixes', metavar='filename', dest='export_fixes',
-                      help='Create a yaml file to store suggested fixes in, '
-                      'which can be applied with clang-apply-replacements.')
+  if yaml_imported:
+    parser.add_argument('-export-fixes', metavar='filename', dest='export_fixes',
+                        help='Create a yaml file to store suggested fixes in, '
+                        'which can be applied with clang-apply-replacements.')
   parser.add_argument('-j', type=int, default=0,
                       help='number of tidy instances to be run in parallel.')
   parser.add_argument('files', nargs='*', default=['.*'],
@@ -254,7 +260,7 @@
     max_task = multiprocessing.cpu_count()
 
   tmpdir = None
-  if args.fix or args.export_fixes:
+  if args.fix or (yaml_imported and  args.export_fixes):
     check_clang_apply_replacements_binary(args)
     tmpdir = tempfile.mkdtemp()
 
@@ -292,7 +298,7 @@
       shutil.rmtree(tmpdir)
     os.kill(0, 9)
 
-  if args.export_fixes:
+  if yaml_imported and args.export_fixes:
     print('Writing fixes to ' + args.export_fixes + ' ...')
     try:
       merge_replacement_files(tmpdir, args.export_fixes)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59734.191992.patch
Type: text/x-patch
Size: 2259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190323/24e4feb8/attachment-0001.bin>


More information about the cfe-commits mailing list