-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
162 lines (132 loc) · 4.89 KB
/
build.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
#bin/python
import sys
import os
import subprocess
import shutil
# By default we build everything as x64, set this to False if you want 32bit
# Some things doesn't seem to work (nvimage) in x64 so we roll 32bits.
build_win64 = False
if build_win64:
builder_exec = "Binaries/Win64/Builder-release.exe"
else:
builder_exec = "Binaries/Win32/Builder-release.exe"
def copy_dep(target_path):
if (os.path.isdir("External")):
f = open("External/shared_libraries.txt")
dest = ""
for line in f:
line = line.strip()
if line == "[32]":
if build_win64:
dest = "" # Skip 32bit libs if we build 64
else:
dest = target_path+"Win32"
elif line == "[64]":
if build_win64:
dest = target_path+"Win64"
else:
dest = ""
elif line != "" and dest != "":
shutil.copy2("External/"+line, dest)
def setup_directories(base_dir = "Binaries/"):
if (os.path.isdir(base_dir) == False):
os.mkdir(base_dir)
if build_win64:
if (os.path.isdir(base_dir+"Win64") == False):
os.mkdir(base_dir+"/Win64")
else:
if (os.path.isdir(base_dir+"Win32") == False):
os.mkdir(base_dir+"Win32")
if (os.path.isdir(base_dir+"Content") == False):
os.mkdir(base_dir+"Content")
copy_dep(base_dir)
def run_builder(content_source, content_target, server_mode = True):
setup_directories()
if (subprocess.call(["tundra2", "Builder", "release"]) != 0):
print("Could not run builder")
return
cmd = [builder_exec,"--source",content_source,"--target",content_target]
if server_mode:
cmd.append("--server")
subprocess.Popen(cmd)
else:
subprocess.call(cmd)
def get_commit_id():
proc = subprocess.Popen(["git","rev-parse", "--short","HEAD"], stdout=subprocess.PIPE)
id = proc.stdout.readline().strip()
return id.decode("utf-8")
def build_program(target, platform, version, clean_build = False):
arg = ""
if clean_build:
arg = "-l"
cmd = ["tundra2", arg, target, platform, version]
return subprocess.call(cmd)
def run_tests():
if build_win64:
print("\n===== Testing Win64 =====")
ret = subprocess.call("Binaries/Win64/Test_Foundation-release.exe")
return ret
else:
print("\n===== Testing Win32 =====")
ret = subprocess.call("Binaries/Win32/Test_Foundation-release.exe")
return ret
def build_release():
if (os.path.isdir("Release") == False):
os.mkdir("Release")
commit_id = get_commit_id()
release_name = "Sandbox-"+commit_id
target_path = "Release"+"/"+release_name+"/"
if (os.path.isdir(target_path) == True):
shutil.rmtree(target_path)
setup_directories(target_path)
# Clean build of the runnables
if build_win64:
if build_program("Launcher", "win64-vs2013", "release", True) != 0:
shutil.rmtree(target_path) # Cleanup
return
if build_program("Builder", "win64-vs2013", "release", False) != 0:
shutil.rmtree(target_path) # Cleanup
return
else:
if build_program("Launcher", "win32-vs2013", "release", True) != 0:
shutil.rmtree(target_path) # Cleanup
return
if build_program("Builder", "win32-vs2013", "release", False) != 0:
shutil.rmtree(target_path) # Cleanup
return
# Tests
if build_win64:
if build_program("Test_Foundation", "win64-vs2013", "release") != 0:
shutil.rmtree(target_path) # Cleanup
return
else:
if build_program("Test_Foundation", "win32-vs2013", "release") != 0:
shutil.rmtree(target_path) # Cleanup
return
if run_tests() != 0:
shutil.rmtree(target_path) # Cleanup
return
# Copy programs to target path
if build_win64:
shutil.copy2("Binaries/Win64/Launcher-release.exe", target_path+"Win64/Sandbox.exe")
shutil.copy2("Binaries/Win64/Builder-release.exe", target_path+"Win64/Builder.exe")
else:
shutil.copy2("Binaries/Win32/Launcher-release.exe", target_path+"Win32/Sandbox.exe")
shutil.copy2("Binaries/Win32/Builder-release.exe", target_path+"Win32/Builder.exe")
# Build content
run_builder("Content", target_path+"Content", False)
print("Release '" + release_name + "' built.")
def main(argv):
if len(argv) < 2:
print("Usage: "+argv[0]+" <action>")
return
if argv[1] == "setup":
setup_directories()
elif argv[1] == "build_assets":
run_builder("Content", "Binaries/Content", False)
elif argv[1] == "release":
build_release()
else:
print('Invalid command')
if __name__ == "__main__":
main(sys.argv)