-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathccwrapper.py
34 lines (27 loc) · 949 Bytes
/
ccwrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
import io
import re
from pathlib import Path
import subprocess
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--source", "-i", type=Path, required=True, help="input file being compiled"
)
parser.add_argument("--logdir", "-d", type=Path, required=True, help="log directory")
parser.add_argument(
"cmd",
action="extend",
nargs="+",
help="full compilation command (including -H etc...)",
)
shargs = parser.parse_args()
logline = re.compile(r"^\.* .+$") # a series of dots, a space, a filename
proc = subprocess.run(shargs.cmd, capture_output=True, encoding="ascii")
if proc.returncode != 0:
exit(proc.returncode)
with open(shargs.logdir / f"{shargs.source.name}.log", "w") as file:
print(" " + str(shargs.source), file=file)
for line in io.StringIO(proc.stderr):
if logline.match(line):
print(line.rstrip(), file=file) # remove trailing '\n'