[clang-tools-extra] r357114 - [clang-tidy] Handle missing yaml module in run-clang-tidy.py
Zinovy Nis via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 27 12:21:32 PDT 2019
Author: zinovy.nis
Date: Wed Mar 27 12:21:32 2019
New Revision: 357114
URL: http://llvm.org/viewvc/llvm-project?rev=357114&view=rev
Log:
[clang-tidy] Handle missing yaml module in run-clang-tidy.py
The Yaml module is missing on some systems and on many of clang buildbots.
But the test for run-clang-tidy.py doesn't fail due to 'NOT' statement masking a python runtime error.
This patch conditionally imports and enables the yaml module only if it's present in the system.
If not, then '-export-fixes' is disabled.
Differential Revision: https://reviews.llvm.org/D59734
Modified:
clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
clang-tools-extra/trunk/test/clang-tidy/bugprone-parent-virtual-call.cpp (props changed)
clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp
Modified: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py?rev=357114&r1=357113&r2=357114&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py Wed Mar 27 12:21:32 2019
@@ -36,11 +36,10 @@ import tempfile
import threading
import traceback
-yaml_imported = True
try:
import yaml
except ImportError:
- yaml_imported = False
+ yaml = None
is_py2 = sys.version[0] == '2'
@@ -144,7 +143,7 @@ def main():
default='')
parser.add_argument('-path', dest='build_path',
help='Path used to read a compile command database.')
- if yaml_imported:
+ if yaml:
parser.add_argument('-export-fixes', metavar='FILE', dest='export_fixes',
help='Create a yaml file to store suggested fixes in, '
'which can be applied with clang-apply-replacements.')
@@ -204,7 +203,7 @@ def main():
max_task_count = min(len(lines_by_file), max_task_count)
tmpdir = None
- if yaml_imported and args.export_fixes:
+ if yaml and args.export_fixes:
tmpdir = tempfile.mkdtemp()
# Tasks for clang-tidy.
@@ -238,7 +237,7 @@ def main():
# Run clang-tidy on files containing changes.
command = [args.clang_tidy_binary]
command.append('-line-filter=' + line_filter_json)
- if yaml_imported and args.export_fixes:
+ if yaml and args.export_fixes:
# Get a temporary file. We immediately close the handle so clang-tidy can
# overwrite it.
(handle, tmp_name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
@@ -253,7 +252,7 @@ def main():
# Wait for all threads to be done.
task_queue.join()
- if yaml_imported and args.export_fixes:
+ if yaml and args.export_fixes:
print('Writing fixes to ' + args.export_fixes + ' ...')
try:
merge_replacement_files(tmpdir, args.export_fixes)
Modified: clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py?rev=357114&r1=357113&r2=357114&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py Wed Mar 27 12:21:32 2019
@@ -47,7 +47,11 @@ import sys
import tempfile
import threading
import traceback
-import yaml
+
+try:
+ import yaml
+except ImportError:
+ yaml = None
is_py2 = sys.version[0] == '2'
@@ -199,9 +203,10 @@ def main():
'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:
+ 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 +259,7 @@ def main():
max_task = multiprocessing.cpu_count()
tmpdir = None
- if args.fix or args.export_fixes:
+ if args.fix or (yaml and args.export_fixes):
check_clang_apply_replacements_binary(args)
tmpdir = tempfile.mkdtemp()
@@ -292,7 +297,7 @@ def main():
shutil.rmtree(tmpdir)
os.kill(0, 9)
- if args.export_fixes:
+ if yaml and args.export_fixes:
print('Writing fixes to ' + args.export_fixes + ' ...')
try:
merge_replacement_files(tmpdir, args.export_fixes)
Propchange: clang-tools-extra/trunk/test/clang-tidy/bugprone-parent-virtual-call.cpp
------------------------------------------------------------------------------
--- svn:executable (original)
+++ svn:executable (removed)
@@ -1 +0,0 @@
-*
Modified: clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp?rev=357114&r1=357113&r2=357114&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp Wed Mar 27 12:21:32 2019
@@ -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
More information about the cfe-commits
mailing list