Created
April 5, 2023 01:44
-
-
Save klemens-morgenstern/d999dcb11ab208e43f89b2f687f2574e to your computer and use it in GitHub Desktop.
b2 -> compile_commands.json
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
import subprocess | |
import re | |
import sys | |
import os | |
import json | |
import os.path | |
cwd = os.getcwd() | |
ll = subprocess.Popen( | |
sys.argv[1:] + ['-n'], | |
stdout=subprocess.PIPE | |
).stdout.readlines() | |
rc = re.compile("^([^.]+)\.compile\.c(?:\+\+)? ([^\n]+)$") | |
tc = re.compile('.*"((?:\\"|[^"])+)"$') | |
res = [] | |
i = 0 | |
while i < len(ll): | |
m = rc.match(ll[i].decode()) | |
if m: | |
output = m[2] | |
i += 2 | |
command = ll[i].strip().decode() | |
file = tc.match(command)[1] | |
res.append({ | |
"directory": cwd, | |
"command": command, | |
"file": os.path.abspath(file), | |
"output": os.path.abspath(output) | |
}) | |
i += 1 | |
json.dump(res, sys.stdout, indent=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment