-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild_package.py
More file actions
128 lines (113 loc) · 3.41 KB
/
build_package.py
File metadata and controls
128 lines (113 loc) · 3.41 KB
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
import os
import re
import shutil
import subprocess
import sys
import zipfile
g_dev_mode = False
def get_commit_id_short():
try:
commit_hash = (
subprocess.check_output(
["git", "rev-parse", "--short", "HEAD"], stderr=subprocess.STDOUT
)
.strip()
.decode("utf-8")
)
return commit_hash
except subprocess.CalledProcessError as e:
print(f"Error: {e.output.decode('utf-8')}")
return None
if len(sys.argv) >= 2:
if sys.argv[1] == "dev":
g_dev_mode = True
# create dist folder
if os.path.exists("dist"):
shutil.rmtree("dist")
os.makedirs("dist")
# run build command
os.system("cd hid && xmake build -y")
os.system("cargo build --release --package lua-framework --package luaf-libffi")
file_src_dst = [
# loader
{
"type": "file",
"src": "hid/build/windows/x64/release/hid.dll",
"dst": "hid.dll",
},
# core files
{
"type": "file",
"src": "target/release/lua_framework.dll",
"dst": "lua_framework.dll",
},
{
"type": "file",
"src": "lib/cimgui.dll",
"dst": "lua_framework/bin/cimgui.dll",
},
{
"type": "file",
"src": "target/release/luaf_libffi.dll",
"dst": "lua_framework/extensions/luaf_libffi.dll",
},
{
"type": "file",
"src": "mhw-imgui-core/x64/Release/mhw-imgui-core.dll",
"dst": "lua_framework/extensions/mhw-imgui-core.dll",
},
# assets
{
"type": "file",
"src": "assets/SourceHanSansCN-Regular.otf",
"dst": "lua_framework/fonts/SourceHanSansCN-Regular.otf",
},
# scripts
{"type": "create_dir", "dst": "lua_framework/scripts"},
{
"type": "dir",
"src": "scripts/_framework",
"dst": "lua_framework/scripts/_framework",
},
]
for src_dst in file_src_dst:
if src_dst["type"] == "file":
dst = "./dist/" + src_dst["dst"]
os.makedirs(os.path.dirname(dst), exist_ok=True)
shutil.copy(src_dst["src"], dst)
elif src_dst["type"] == "dir":
shutil.copytree(src_dst["src"], "./dist/" + src_dst["dst"])
elif src_dst["type"] == "create_dir":
os.makedirs("./dist/" + src_dst["dst"])
# get version from Cargo.toml
version = ""
with open("Cargo.toml", "r", encoding="utf-8") as f:
for line in f:
if line.startswith("version"):
results = re.findall(r'version = "(\d+\.\d+\.\d+)"', line)
if len(results) > 0:
version = results[0]
zip_name = None
if g_dev_mode:
commit_id_short = get_commit_id_short()
zip_name = f"lua-framework_v{version}-dev-{commit_id_short}.zip"
else:
zip_name = f"lua-framework_v{version}.zip"
# create zip file
archive = zipfile.ZipFile(f"dist/{zip_name}", "w", zipfile.ZIP_DEFLATED)
for src_dst in file_src_dst:
if src_dst["type"] == "file":
archive.write(src_dst["src"], src_dst["dst"])
elif src_dst["type"] == "dir":
for root, dirs, files in os.walk(src_dst["src"]):
for file in files:
archive.write(
os.path.join(root, file),
os.path.join(
src_dst["dst"],
os.path.relpath(os.path.join(root, file), src_dst["src"]),
),
)
elif src_dst["type"] == "create_dir":
archive.mkdir(src_dst["dst"])
archive.close()