This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Handle missing yaml module in run-clang-tidy.py
ClosedPublic

Authored by zinovy.nis on Mar 23 2019, 5:37 AM.

Details

Summary

The Yaml module is missing on some systems and on many clang buildbots. But the test for run-clang-tidy.py doesn't fail due to not statement masking the python runtime error.

This patch conditionally imports and enables the yaml module only if it's present in system. If not, then -export-fixes is disabled, the same as for clang-tidy-diff.py.

Diff Detail

Event Timeline

zinovy.nis created this revision.Mar 23 2019, 5:37 AM
zinovy.nis marked an inline comment as done.
zinovy.nis added inline comments.
test/clang-tidy/run-clang-tidy.cpp
1

Just check that python doesn't complain on the script code and imported modules.

clang-tidy/tool/run-clang-tidy.py
51

Could be

try:
    import yaml
except ImportError:
    yaml = None

and later

if yaml:
    ...
clang-tidy/tool/run-clang-tidy.py
210

could be

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.')
else:
    parser.export_fixes = False

This would make later condition easier to read.

zinovy.nis marked an inline comment as done.Mar 25 2019, 10:16 AM
zinovy.nis added inline comments.
clang-tidy/tool/run-clang-tidy.py
210

Looks strange. Not sure this works.

zinovy.nis marked an inline comment as done.
This revision was not accepted when it landed; it landed in state Needs Review.Mar 27 2019, 12:20 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2019, 12:20 PM