-
Notifications
You must be signed in to change notification settings - Fork 8
/
package.py
167 lines (126 loc) · 5.18 KB
/
package.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import zipfile
import os.path
import os
import sys
import json
import re
import subprocess
import winreg
import shutil
""" creats a zip file release """
def get_version():
exp = re.compile('O3DS_VERSION_TAG\s+"([0-9.]+)"')
with open('CMakeLists.txt') as fp:
for line in fp:
ret = exp.search(line)
if ret:
return ret.group(1)
return None
def build_ue(plugin, ue_base, version, ue_install_path):
out = ue_base + "\\" + version + "\\Open3dStream"
exe = rf"{ue_install_path}\Engine\Build\BatchFiles\RunUAT.bat"
if not os.path.isfile(exe) :
raise RuntimeError("Could not find unreal: " + version)
cmd = [exe,
"BuildPlugin",
"-Plugin=" + plugin,
"-TargetPlatforms=Win64",
"-Package=" + out,
"-Rocket",
"-VS2022"
]
try:
pr = subprocess.Popen(cmd, shell=True)
pr.wait()
if pr.returncode != 0:
raise RuntimeError("Plugin Build Failed")
except Exception as ex:
print(ex)
def remove_directory(base):
if not os.path.isdir(base):
return
for d, _, f in os.walk(base):
for each_file in f:
print("RM " + os.path.join(d, each_file))
version_input = get_version()
if version_input is None:
raise RuntimeError("Could not determine version")
print("Packaging version: " + version_input)
version = "Open3DStream_" + version_input
cwd = os.path.abspath('')
out_root = "Open3DStream"
outzip = os.path.join(cwd, version + ".zip")
out_dir = os.path.abspath('usr')
# Unreal
unreal_src_plugin = os.path.abspath("D:/P4_PD/o3ds/plugins/Open3DStream/Open3DStream.uplugin")
unreal_dst_base = os.path.join(out_dir, "plugins", "unreal")
unreal_stage_base = os.path.join(cwd, "unrealstage")
ue_registry_prefix_path = r'SOFTWARE\EpicGames\Unreal Engine'
ue_registry_prefix_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, ue_registry_prefix_path, 0, winreg.KEY_READ)
ue_version_index = 0
while True:
try:
ue_version = winreg.EnumKey(ue_registry_prefix_key, ue_version_index)
except OSError as e:
if "[WinError 259]" in str(e):
break
raise e
print(ue_version)
if ue_version == "4.26":
ue_version_index = ue_version_index + 1
continue
ue_version_key = winreg.OpenKey(ue_registry_prefix_key, ue_version, 0, winreg.KEY_READ)
ue_path, _ = winreg.QueryValueEx(ue_version_key, "InstalledDirectory")
build_ue(unreal_src_plugin, unreal_stage_base, ue_version, ue_path)
print(f"Unreal path: {ue_path}")
dst_plugin_dir = os.path.join(unreal_dst_base, ue_version, "Open3dStream")
remove_directory(dst_plugin_dir)
ue_host_project_dir = os.path.join(unreal_stage_base, ue_version, "Open3DStream", "HostProject")
if os.path.isdir(ue_host_project_dir):
# Project was build as a "host project", copy it to the location
ue_built_plugin = os.path.join(ue_host_project_dir, "Plugins", "Open3DStream")
else:
ue_built_plugin = os.path.join(unreal_stage_base, ue_version, "Open3DStream")
if not os.path.isfile(os.path.join(ue_built_plugin, "Open3DStream.uplugin")):
raise RuntimeError("Could not find plugin: " + ue_built_plugin)
shutil.copytree(ue_built_plugin, dst_plugin_dir)
# libs
unreal_lib_dir = os.path.join(unreal_dst_base, ue_version, "Open3dStream" , "lib")
print(unreal_lib_dir)
if not os.path.isdir(unreal_lib_dir):
os.mkdir(unreal_lib_dir)
usr_lib_dir = os.path.join(out_dir, "lib")
for libfile in os.listdir(usr_lib_dir):
if libfile.endswith(".lib"):
name = libfile[:-4]
if name.endswith("d"):
release_name = name[:-1] + ".lib"
if os.path.isfile(os.path.join(out_dir, "lib", release_name)):
continue
print(libfile)
shutil.copyfile(os.path.join(out_dir, "lib", libfile), os.path.join(unreal_lib_dir, libfile))
# includes
unreal_include_dir = os.path.join(unreal_dst_base, ue_version, "Open3dStream" , "lib", "include")
usr_include_dir = os.path.join(out_dir, "include")
shutil.copytree(usr_include_dir, unreal_include_dir)
ue_version_index = ue_version_index + 1
fp = zipfile.ZipFile(outzip, "w", zipfile.ZIP_DEFLATED)
for d, _, f in os.walk(out_dir):
base = d[len(out_dir)+1:]
for each_file in f:
src = os.path.join(d, each_file)
out = os.path.join(base, each_file)
print(out)
fp.write(src, out)
fp.close()
#installer
nsis = "C:/Program Files (x86)/NSIS/makensis.exe"
if not os.path.isfile(nsis):
raise RuntimeError("Could not find NSIS: " + str(nsis))
nsis = '"' + nsis.replace("/", "\\") + '"'
nsi_script = os.path.join(os.path.split(__file__)[0], 'o3ds.nsi')
cmd = nsis + ' /DOUT_FILE=' + version + '.exe /DFILE_VERSION=' + version + ' ' + nsi_script
if subprocess.run(cmd).returncode != 0:
raise RuntimeError("NSI Error")
if not os.path.isfile(version + ".exe"):
raise RuntimeError("NISI did not produce: " + version + ".exe")