-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild_release.py
executable file
·54 lines (40 loc) · 1.45 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
#!/usr/bin/env python3
import subprocess
import fileinput
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 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')
run_cmd("git submodule init")
run_cmd("git submodule update")
run_cmd("make clean")
run_cmd("make -j32 release")
run_cmd("mkdir -p bin/example")
run_cmd("cp example/download.py bin/example/download.py")
run_cmd("cp example/input.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}.linux.x64.tar.gz; cd ..;")
run_cmd("rm -rf bin")