-
Notifications
You must be signed in to change notification settings - Fork 9
/
build_release.py
executable file
·137 lines (111 loc) · 4.48 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 shutil
import sys
import os
import stat
def replace_in_file(file_path, search_text, new_text):
with fileinput.input(file_path, inplace=True) as file:
for line in file:
new_line = line.replace(search_text, new_text)
print(new_line, end='')
def get_ver(splash_path):
with open(splash_path) as f:
for line in f.readlines():
line = line.strip()
if "SPLASH_VERSION" in line:
return line.split("=")[-1].strip().split("\"")[1]
print("Error: cannot read SPLASH_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()
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 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)
run_cmd(f"{make_command} clean")
#run_cmd(f"{make_command} CXX={cxx} CC={cc} PLATFORM={platform} STATIC_LINK=true -j")
#keep platform generic for result consistency across platforms
run_cmd(f"{make_command} CXX={cxx} CC={cc} PLATFORM=generic STATIC_LINK=true -j")
run_cmd("mkdir -p bin/example")
run_cmd("cp example/download.py bin/example/download.py")
run_cmd("cp example/download_10X.py bin/example/download_10X.py")
run_cmd("cp example/test_data_cell_barcode_samplesheet.csv bin/example/test_data_cell_barcode_samplesheet.csv")
run_cmd("cp example/test_non_10X_Cj_samplesheet.csv bin/example/test_non_10X_Cj_samplesheet.csv")
run_cmd("cp example/input.txt bin/example")
run_cmd("cp example/input-10X.txt bin/example")
run_cmd("cp example/S10.txt bin/example")
run_cmd("cp example/S11.txt bin/example")
run_cmd("cp example/S12.txt bin/example")
run_cmd("cp example/S13.txt bin/example")
with open("bin/example/run-example.sh", "w") as f:
f.write("#!/bin/bash\n")
f.write("./download.py\n")
f.write("../splash --bin_path .. input.txt\n")
os.chmod("bin/example/run-example.sh", os.stat("bin/example/run-example.sh").st_mode | stat.S_IEXEC)
ver = get_ver("bin/splash")
run_cmd(f"cd bin; tar -c * | pigz > ../splash-{ver}.{system}.{hardware}.tar.gz; cd ..;")
run_cmd("rm -rf bin")