-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
203 lines (153 loc) · 5.3 KB
/
build.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import os
import platform
import sys
import multiprocessing
import shutil
def getParallel(args):
par = multiprocessing.cpu_count()
for x in args:
if x.startswith("--par="):
val = x.split("=",1)[1]
par = int(val)
if par < 1:
par = 1
idx = args.index(x)
args[idx] = ""
return (args,par)
def replace(list, find, replace):
if find in list:
idx = list.index(find)
list[idx] = replace;
return list
def Build(projectName, argv, install, par, sudo, noConfig):
osStr = (platform.system())
buildDir = ""
config = ""
buildType = ""
setup = "--setup" in argv;
argv = replace(argv, "--setup", "")
if "--debug" in argv:
buildType = "Debug"
else:
buildType = "Release"
argv = replace(argv, "--debug", "")
if osStr == "Windows":
buildDir = "out/build/x64-{0}".format(buildType)
config = "--config {0}".format(buildType)
elif osStr == "Darwin":
buildDir = "out/build/osx"
else:
buildDir = "out/build/linux"
argv.append("-DCMAKE_BUILD_TYPE={0}".format(buildType))
argStr = ""
for a in argv:
argStr = argStr + " " + a
parallel = ""
if par != 1:
parallel = " --parallel " + str(par)
mkDirCmd = "mkdir -p {0}".format(buildDir);
CMakeCmd = "cmake -S . -B {0} {1}".format(buildDir, argStr)
BuildCmd = "cmake --build {0} {1} {2} ".format(buildDir, config, parallel)
InstallCmd = ""
if sudo:
sudo = "sudo "
else:
sudo = ""
if install:
InstallCmd = sudo
InstallCmd += "cmake --install {0} {1} ".format(buildDir, config)
print("\n\n====== build.py ("+projectName+") ========")
if not noConfig:
print(mkDirCmd)
print(CMakeCmd)
if not setup:
print(BuildCmd)
if len(InstallCmd):
print(InstallCmd)
print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n\n")
if not noConfig:
os.system(mkDirCmd)
os.system(CMakeCmd)
if not setup:
os.system(BuildCmd)
if len(sudo) > 0:
print("installing "+projectName+": {0}\n".format(InstallCmd))
os.system(InstallCmd)
def help():
print(" --install \n\tInstructs the script to install whatever is currently being built to the default location.")
print(" --install=prefix \n\tinstall to the provided prefix.")
print(" --sudo \n\twhen installing, use sudo. May require password.")
print(" --par=n \n\twhen building do use parallel builds with n threads. default = num cores.")
print(" --noauto \n\twhen building do not automatically fetch dependencies.")
print(" --par=n \n\twhen building do use parallel builds with n threads. default = num cores.")
print(" --debug \n\tdebug build.")
print("any additional arguments are forward to cmake.\n")
print("-build the library")
print(" python build.py")
print("-build the library with cmake configurations")
print(" python build.py --debug -DENABLE_SSE=ON")
print("-build the library and install with sudo")
print(" python build.py --install --sudo")
print("-build the library and install to prefix")
print(" python build.py --install=~/my/install/dir ")
def parseInstallArgs(args):
prefix = ""
doInstall = False
for x in args:
if x.startswith("--install="):
prefix = x.split("=",1)[1]
prefix = os.path.abspath(os.path.expanduser(prefix))
idx = args.index(x)
args[idx] = "-DCMAKE_INSTALL_PREFIX=" + prefix
doInstall = True
if x == "--install":
idx = args.index(x)
osStr = (platform.system())
if osStr == "Windows":
args[idx] = "-DCMAKE_INSTALL_PREFIX=c:/lib"
else:
args[idx] = "-DCMAKE_INSTALL_PREFIX=/usr/local"
doInstall = True
return (args, doInstall)
def rm(path):
if os.path.exists(path):
shutil.rmtree(path, ignore_errors=True)
def main(projectName, argv):
if "--help" in argv:
help()
return
if "--clean" in argv:
rm("out/build")
rm("out/install")
rm("out/bitpolymul/out")
rm("out/coproto/out")
rm("out/function2/out")
rm("out/libsodium/Build")
rm("out/macoro/out")
rm("out/libOTe/out")
rm("out/optional-lite/out")
rm("out/span-lite/out")
rm("out/variant-lite/out")
return
sudo = "--sudo" in argv;
if not sudo:
argv.append("-DSUDO_FETCH=OFF")
if "--noauto" in argv:
argv = replace(argv, "--noauto", "")
argv.append("-DFETCH_AUTO=OFF")
else:
argv.append("-DFETCH_AUTO=ON")
if "--system" in argv:
argv = replace(argv, "--system", "")
argv.append("-DVOLE_PSI_NO_SYSTEM_PATH=false")
else:
argv.append("-DVOLE_PSI_NO_SYSTEM_PATH=true")
argv = replace(argv, "--sudo", "-DSUDO_FETCH=ON")
argv, install = parseInstallArgs(argv)
argv, par = getParallel(argv)
argv.append("-DPARALLEL_FETCH="+str(par))
noConfig = "--nc" in argv
argv = replace(argv, "--nc", "")
Build(projectName, argv, install, par, sudo, noConfig)
if __name__ == "__main__":
main("vole-psi", sys.argv[1:])