summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Gräsman <kim.grasman@proceranetworks.com>2017-09-17 11:15:47 +0200
committerKim Gräsman <kim.grasman@gmail.com>2017-09-18 20:53:47 +0200
commitfbcc7e31f240920201bae37ff598e6a67a18384e (patch)
tree4929df82238f3b295772ad2bcf086ac8c8b76422
parent37670ddaff58398a342a690e9dc104e4d150fd73 (diff)
Support 'arguments' key in compilation databases
Move things around a little to make this easier to implement -- run_iwyu now translates from a compilation database entry to a command-line. This should fix issue #456.
-rwxr-xr-xiwyu_tool.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/iwyu_tool.py b/iwyu_tool.py
index d0d8108..efda8c1 100755
--- a/iwyu_tool.py
+++ b/iwyu_tool.py
@@ -96,10 +96,22 @@ def get_output(cwd, command):
return process.communicate()[0].decode("utf-8").splitlines()
-def run_iwyu(cwd, compile_command, iwyu_args, verbose):
+def run_iwyu(dbentry, iwyu_args, verbose):
""" Rewrite compile_command to an IWYU command, and run it. """
- compiler, _, args = compile_command.partition(' ')
- if compiler.endswith('cl.exe'):
+ cwd = dbentry['directory']
+
+ if 'arguments' in dbentry:
+ # arguments is a command-line in list form
+ arguments = dbentry['arguments']
+ compile_command, compile_args = arguments[0], arguments[1:]
+ compile_args = ' '.join(compile_args)
+ elif 'command' in dbentry:
+ # command is a command-line in string form
+ compile_command, _, compile_args = dbentry['command'].partition(' ')
+ else:
+ raise ValueError('Invalid compilation database entry: %s' % dbentry)
+
+ if compile_command.endswith('cl.exe'):
# If the compiler name is cl.exe, let IWYU be cl-compatible
clang_args = ['--driver-mode=cl']
else:
@@ -107,7 +119,7 @@ def run_iwyu(cwd, compile_command, iwyu_args, verbose):
iwyu_args = ['-Xiwyu ' + a for a in iwyu_args]
command = ['include-what-you-use'] + clang_args + iwyu_args
- command = '%s %s' % (' '.join(command), args.strip())
+ command = '%s %s' % (' '.join(command), compile_args.strip())
if verbose:
print('%s:' % command)
@@ -160,9 +172,8 @@ def main(compilation_db_path, source_files, verbose, formatter, jobs, iwyu_args)
# Details here: https://stackoverflow.com/a/28660669.
results = []
for entry in entries:
- cwd, compile_command = entry['directory'], entry['command']
results.append(pool.apply_async(run_iwyu,
- (cwd, compile_command, iwyu_args, verbose),
+ (entry, iwyu_args, verbose),
callback=formatter))
pool.close()
pool.join()