Created
September 23, 2020 20:18
-
-
Save vmiheer/81e07c4df75177d0cfaa12696bc317b9 to your computer and use it in GitHub Desktop.
This file contains 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
# fix clang compilation database in the cases where one compiler uses another host compiler | |
# e.g. nvcc/icc using gcc headers | |
from subprocess import Popen, PIPE | |
from typing import List | |
import re, json | |
startRe = re.compile(r"#include [\"<][.]{3}[\">] search starts here:") | |
endRe = re.compile(r"^End of search list.$") | |
def getDefaultIncludes(): | |
p1 = Popen(["echo", ""], stdout=PIPE) | |
p2 = Popen(["/uufs/chpc.utah.edu/sys/installdir/gcc/9.2.0/bin/g++", "-", "-E", "-v"], stdin=p1.stdout, stdout=PIPE, stderr=PIPE) | |
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. | |
out = p2.communicate()[1] | |
start = False | |
includes = [] | |
for line in out.decode().split('\n'): | |
if endRe.match(line): | |
break | |
if startRe.match(line): | |
start = True | |
continue | |
if start: | |
includes.append(line.strip()) | |
return (includes) | |
commands = json.load(open('compile_commands.json')) | |
additionToCommandLine = "".join([" -I " + x for x in getDefaultIncludes()]) | |
for target in commands: | |
target['command'] = target['command'] + additionToCommandLine | |
with open('compile_commands.json', 'w') as json_file: | |
json.dump(commands, json_file, indent=' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment