-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.py
115 lines (97 loc) · 3.51 KB
/
builder.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""
0xA2_chess-engine
Copyright (C) 2020-2021 Ofek Shochat
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from os.path import relpath
from glob import glob
import os
from sys import argv
dirs = glob(".\\{}\\*".format(argv[argv.index("-project")+1]))
g_dirs = []
def get_children(path):
ds = []
for i in glob(path + "\\*"):
if i.count(".") < 2:
dd = get_children(i)
for d in dd:
ds.append(d)
else:
ds.append(i)
return ds
# get all file dirs (all tree)
for i in dirs:
if i.count(".") < 2:
dd = get_children(i)
for i in dd:
g_dirs.append(i)
else:
g_dirs.append(i)
class f:
def __init__(self, text, name):
self.text = text
self.once = False
self.name = name
self.deps = 0
self.dds = []
# new plan: iterating over the includes. searching for the include in g_dirs (local include) and then doing `deps += 1`
# and doing that for every thing in that file for every file. not efficiant but works
def get_includes(path, curr):
try:
for i in open(path, encoding="utf-8").readlines():
if i[0:11].__contains__("#include \""):
curr.deps += 1
curr.dds.append(i[11:-1])
for d in g_dirs:
if d.split('\\')[-1] == i[11:-1]:
get_includes(d, curr)
except UnicodeDecodeError:
for i in open(path, encoding="ISO-8859-1").readlines():
if i[0:11].__contains__("#include \""):
curr.deps += 1
curr.dds.append(i[11:-1])
for d in g_dirs:
if d.split('\\')[-1] == i[11:-1]:
get_includes(d, curr)
fs = []
for t in g_dirs:
curr = f(hash(t), t)
get_includes(t, curr)
fs.append(curr)
ss = sorted(fs, key=lambda i: i.deps)
for d in range(len(ss)):
try:
if ss[d].deps == ss[d+1].deps:
filename, file_extension = os.path.splitext(ss[d+1].name)
if filename + ".h" in ss[d].dds:
ss[d+1], ss[d] = ss[d], ss[d+1]
if ss[d].name == argv[argv.index("-main")+1]:
ss.insert(len(ss),ss[d])
del ss[d]
except IndexError:
break
files = ""
for i in ss:
filename, file_extension = os.path.splitext(i.name)
if file_extension == ".cc" or file_extension == ".cpp":
files += i.name + " "
print(files)
compilers = ["g++", "cl"]
comp = input("compiler to use " + str(compilers) + ": ")
if comp == "cl":
options = {"pCompileHigh":"/MP8", "pCompileMid":"/MP:4", "pLoops":"/Qpar", "pGenMax":"/CGTHREADS:8", "pGenMid":"/CGTHREADS4", "debugerFast":"/DEBUG[FASTLINK]", "speed":"/O2"}
active = ""
for i in argv[2:]:
try:
active += options[i] + " "
except KeyError: pass
os.system("{} /std:c++17 /Fo.\\build\\objs\\ /Fe.\\build\\main.exe {}/I.\src {}".format(comp, active, files))