-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_release.py
executable file
·137 lines (113 loc) · 4.62 KB
/
build_release.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
#!/usr/bin/env python3
import subprocess
import fileinput
import tarfile
import shutil
import os
import sys
#from https://stackoverflow.com/questions/14697629/running-a-bat-file-though-python-in-current-process
def init_vsvars():
vswhere_path = r"%ProgramFiles(x86)%/Microsoft Visual Studio/Installer/vswhere.exe"
vswhere_path = os.path.expandvars(vswhere_path)
if not os.path.exists(vswhere_path):
raise EnvironmentError("vswhere.exe not found at: %s", vswhere_path)
vs_path = os.popen('"{}" -latest -property installationPath'.format(vswhere_path)).read().rstrip()
vsvars_path = os.path.join(vs_path, "VC\\Auxiliary\\Build\\vcvars64.bat")
output = os.popen('"{}" && set'.format(vsvars_path)).read()
for line in output.splitlines():
pair = line.split("=", 1)
if(len(pair) >= 2):
os.environ[pair[0]] = pair[1]
def get_ver():
with open("src/common/defs.h") as f:
for line in f.readlines():
line = line.strip()
if "BKC_VERSION" in line:
return line.split("BKC_VERSION")[-1].split("\"")[-2].strip()
print("Error: cannot read BKC version")
sys.exit(1)
def get_os():
if os.name == 'nt':
return 'windows'
elif os.name == 'posix':
if os.uname()[0] == 'Linux':
return 'linux'
elif os.uname()[0] == 'Darwin':
return 'mac'
else:
print("Error: unknown os", os.uname()[0])
sys.exit(1)
else:
print("Error: unknown os.name", os.name)
sys.exit(1)
def get_hardware():
if os.name == 'nt':
return 'x64' # TODO: do a real check and support ARM also...
elif os.name == 'posix':
if os.uname()[4] == 'x86_64':
return 'x64'
elif os.uname()[4] == 'aarch64' or os.uname()[4] == 'arm64':
return 'arm64'
else:
print("Error: unknown hardware", os.uname()[4])
sys.exit(1)
else:
print("Error: unknown os.name", os.name)
sys.exit(1)
def run_cmd(cmd):
p = subprocess.Popen(cmd, shell=True)
p.communicate()
def run_cmd_get_stdout(cmd):
p = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
return p.stdout.decode('utf-8')
if __name__ == "__main__":
system = get_os()
hardware = get_hardware()
ver = get_ver()
print(f"building\n\tVersion: {ver}\n\tOperating system: {system}\n\tHardware: {hardware}")
run_cmd("git submodule update --init --recursive --jobs=8")
make_command = "make"
if system == "mac":
make_command = "gmake"
platform = "axv"
if hardware == "arm64":
if system == "mac":
platform = "m1"
else:
platform = "arm8"
# In general use the default g++, but not on mac where the default is just clang++
# which is currently not supported
cxx = "g++"
cc = "gcc"
if system == "mac":
for version in [13, 12, 11, 10]:
if shutil.which(f"g++-{version}") and shutil.which(f"gcc-{version}"):
out = run_cmd_get_stdout(f"g++-{version} --version")
if "gcc" in out.lower():
cxx = f"g++-{version}"
else:
continue
# lets check if the same version works for CC and is GNU
out = run_cmd_get_stdout(f"gcc-{version} --version")
if "gcc" in out.lower():
cc = f"gcc-{version}"
break
if system != 'windows':
if not "g++" in run_cmd_get_stdout(f"{cxx} --version").lower() or not "gcc" in run_cmd_get_stdout(f"{cc} --version"):
print(f"The selected C++ compiler ({cxx}) or C compiler ({cc}) is not GNU g++/gcc.\n"
"If you are using macOS, you may install it with Homebrew (https://brew.sh/)")
sys.exit(1)
if system == 'windows':
init_vsvars()
#run_cmd("MSBuild.exe bkc.sln /property:Configuration=Release /property:Platform=x64")
run_cmd("devenv bkc.sln /Build \"Release|x64\"")
#run_cmd("devenv bkc.sln /Rebuild \"Release|x64\"")
with tarfile.open(f"bkc-{ver}.{system}.{hardware}.tar.gz", "w:gz") as tar:
#tar.add(source_dir, arcname=os.path.basename(source_dir))
tar.add("x64/Release/bkc.exe", arcname="bkc.exe")
tar.add("x64/Release/bkc_dump.exe", arcname="bkc_dump.exe")
else:
run_cmd(f"{make_command} clean")
run_cmd(f"{make_command} CXX={cxx} CC={cc} PLATFORM=generic STATIC_LINK=true -j")
run_cmd(f"cd bin; tar -c * | pigz > ../bkc-{ver}.{system}.{hardware}.tar.gz; cd ..;")
run_cmd(f"{make_command} clean")