-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistribute.py
93 lines (70 loc) · 2.39 KB
/
distribute.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
import os
import subprocess as sp
import shutil
import argparse, sys
from os import path, getcwd, makedirs
CWD = getcwd()
TARGET_PATH = path.join(CWD, "target", "dist")
DIST_PATH = path.join(CWD, "dist")
DIST_TMP_PATH = path.join(CWD, ".dist")
def build_editor():
return sp.run(["cargo", "build", "--profile=dist", "-p", "hikari_editor"])
def build_cli():
return sp.run(["cargo", "build", "--profile=dist", "-p", "hikari_cli"])
def copy_folder_structure():
folders = ["data"]
for folder in folders:
shutil.copytree(path.join(CWD, folder), path.join(DIST_TMP_PATH, folder))
def copy_binaries():
exes = ["hikari_editor", "hikari_cli"]
if sys.platform == "win32":
exes = [exe + ".exe" for exe in exes]
for exe in exes:
shutil.copy(path.join(TARGET_PATH, exe), path.join(DIST_TMP_PATH, exe))
def copy_files():
files = ["HIKARI_VERSION"]
for f in files:
shutil.copyfile(path.join(CWD, f), path.join(DIST_TMP_PATH, f))
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def exit():
shutil.rmtree(DIST_TMP_PATH)
sys.exit(-1)
def make_archive(source, destination):
base = path.basename(destination)
name = base.split('.')[0]
format = base.split('.')[1]
shutil.make_archive(name, format, source)
def run(package_path = None, clean = False):
if path.exists(DIST_TMP_PATH):
shutil.rmtree(DIST_TMP_PATH)
makedirs(DIST_TMP_PATH)
if build_editor().returncode != 0:
eprint("Failed to build editor")
exit()
if build_cli().returncode != 0:
eprint("Failed to build cli")
exit()
copy_folder_structure()
copy_files()
copy_binaries()
if path.exists(DIST_PATH):
shutil.rmtree(DIST_PATH)
if package_path:
make_archive(DIST_TMP_PATH, package_path)
else:
shutil.move(DIST_TMP_PATH, DIST_PATH)
if clean:
sp.run(["cargo", "clean", "--profile=dist"])
parser = argparse.ArgumentParser()
parser.add_argument("--package", type=str, help = "Put files into a compressed archive")
parser.add_argument("--clean", help = "Clean previous build")
args = parser.parse_args()
if args.package:
(filename, ext) = path.splitext(args.package)
ext = ext[1:]
print(ext)
if ext != "zip":
eprint("Unsupported archive format, Supported formats are: zip")
sys.exit(-1)
run(args.package, args.clean)