Created
November 20, 2012 21:12
-
-
Save rpavlik/4121171 to your computer and use it in GitHub Desktop.
Run iwyu on compile_commands.json file created by CMake with CMAKE_EXPORT_COMPILE_COMMANDS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import subprocess | |
import sys | |
def run(cmd): | |
# print(cmd) | |
stringCmd = u" ".join(cmd) | |
subprocess.call(stringCmd, shell=True) | |
def runIWYUGDB(wd, args): | |
cmd =[u"gdb", u"--args"] | |
cmd.extend(basecmd) | |
cmd.extend(args) | |
run(cmd) | |
def runIWYU(wd, args): | |
cmd = basecmd[:] | |
cmd.extend(args) | |
run(cmd) | |
f = open("compile_commands.json", "r") | |
tunits = json.load(f) | |
extraArg = u" ".join([u"-Xiwyu " + x for x in sys.argv[1:]]) | |
basedir = u"/home/rpavlik/llvm-trunk/" | |
basecmd = [basedir + u"bin/include-what-you-use", u"-Xiwyu", u"--verbose=2", extraArg] # "-working-directory", wd] | |
srcdir = "/home/rpavlik/src/third-party/llvm/tools/clang/tools/include-what-you-use/" | |
mappingFiles = ["gcc.libc.imp", "gcc.stl.headers.imp", "gcc.symbols.imp", "google.imp", "third_party.imp"] # "iwyu.gcc.imp" | |
for mapping in mappingFiles: | |
basecmd.extend(["-Xiwyu", "--mapping_file="+srcdir+mapping]) | |
for tu in tunits: | |
oldDriver = tu["command"].split(None)[0] | |
cmd = tu["command"].replace(oldDriver, u"") | |
runIWYU(tu["directory"], [cmd]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment