-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcc
More file actions
52 lines (38 loc) · 1.16 KB
/
cc
File metadata and controls
52 lines (38 loc) · 1.16 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
import subprocess
import sys
import tempfile
import json
import os
opt_sep = ":"
compiler_name = os.path.basename(sys.argv[0])
def compile():
os.environ["PATH"] = os.environ["PATH"][1:]
completed = subprocess.run(
[compiler_name] + sys.argv[1:],
env=os.environ
)
return completed.returncode
def get_filename():
suffixes = ["cc", "cpp", "c"]
filename = ""
for a in sys.argv[1:]:
for suffix in suffixes:
if a.lower().endswith(suffix):
filename = a
break
return filename
if __name__ == "__main__":
rc = compile()
filename = get_filename()
if filename:
command = {
"directory": os.getcwd(),
"arguments": ([compiler_name] + sys.argv[1:]), # noqa: E501
"file": filename
}
temp_prefix = os.environ.get("COMPDB_PREFIX", "comp_")
with tempfile.NamedTemporaryFile(mode="w", prefix=temp_prefix, delete=False) as temp: # noqa: E501
# print(f"saving to {temp.name}")
json.dump([command], temp)
exit(rc)