forked from xavierd/clang_complete
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cc_args.py
executable file
·84 lines (69 loc) · 1.76 KB
/
cc_args.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import os
import sys
CONFIG_NAME = ".clang_complete"
def readConfiguration():
try:
f = open(CONFIG_NAME, "r")
except IOError:
return []
result = []
for line in f.readlines():
strippedLine = line.strip()
if len(strippedLine) > 0:
result += [strippedLine]
f.close()
return result
def writeConfiguration(lines):
f = open(CONFIG_NAME, "w")
f.writelines(lines)
f.close()
def parseArguments(arguments):
nextIsInclude = False
nextIsDefine = False
nextIsIncludeFile = False
includes = []
defines = []
include_file = []
for arg in arguments:
if nextIsInclude:
includes += [arg]
nextIsInclude = False
elif nextIsDefine:
defines += [arg]
nextIsDefine = False
elif nextIsIncludeFile:
include_file += [arg]
nextIsIncludeFile = False
elif arg == "-I":
nextIsInclude = True
elif arg == "-D":
nextIsDefine = True
elif arg[:2] == "-I":
includes += [arg[2:]]
elif arg[:2] == "-D":
defines += [arg[2:]]
elif arg == "-include":
nextIsIncludeFile = True
result = map(lambda x: "-I" + x, includes)
result += map(lambda x: "-D" + x, defines)
result += map(lambda x: "-include " + x, include_file)
return result
def mergeLists(base, new):
result = list(base)
for newLine in new:
try:
result.index(newLine)
except ValueError:
result += [newLine]
return result
configuration = readConfiguration()
args = parseArguments(sys.argv)
result = mergeLists(configuration, args)
writeConfiguration(map(lambda x: x + "\n", result))
status = os.system(" ".join(sys.argv[1:]))
if not os.WIFEXITED(status):
sys.exit(1)
sys.exit(os.WEXITSTATUS(status))
# vim: set ts=2 sts=2 sw=2 expandtab :