Skip to content

Instantly share code, notes, and snippets.

@sasq64
Created October 30, 2017 20:06
Show Gist options
  • Save sasq64/b1bc795a5a8b971e36a664a3427ba805 to your computer and use it in GitHub Desktop.
Save sasq64/b1bc795a5a8b971e36a664a3427ba805 to your computer and use it in GitHub Desktop.
clang-tidy wrapper that handles .h files
#!/usr/bin/env python
import os.path
import subprocess
import platform
osname = platform.system()
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ['PATH'].split(os.pathsep):
path = path.strip("'")
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def main(args) :
fileName = None
buildDir = None
realArgs = []
while args :
if args[0] =='-p' :
buildDir = args[1]
args = args[1:]
elif args[0][0] == '-' :
realArgs.append(args[0])
else :
fileName = args[0]
args = args[1:]
cppFile = None
if fileName :
base,ext = os.path.splitext(fileName)
if ext == '.h' or ext == '.hpp' :
cppFile = base + '.cpp'
if cppFile and os.path.isfile(cppFile) :
realArgs.append(cppFile)
realArgs.append("-line-filter=[{\"name\":\"" + fileName + "\"}]")
realArgs.append("-header-filter=" + fileName)
elif fileName :
realArgs.append(fileName)
if buildDir :
realArgs.append("-p")
realArgs.append(buildDir)
clangTidy = which('clang-tidy')
subprocess.call([clangTidy] + realArgs)
if __name__ == '__main__':
import sys
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment