forked from effekseer/Effekseer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·254 lines (195 loc) · 8.5 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import subprocess
import sys
import os
import shutil
import urllib.request
import platform
from distutils.spawn import find_executable
import distutils
from distutils import dir_util
def call(cmd, env=None):
""" call command line.
"""
print(cmd)
p = subprocess.Popen(cmd, shell=True, env=env)
ret = p.wait()
if ret != 0:
print("Failed {}".format(cmd))
raise Exception
def get_files(path):
""" get files.
"""
def getlistdir(path, l):
dirs = os.listdir(path)
for d in dirs:
newpath = os.path.join(path, d)
if os.path.isdir(newpath):
getlistdir(newpath, l)
else:
l.append(newpath)
ret = []
getlistdir(path, ret)
return ret
def copytreeWithExt(src, dst, exts):
files = get_files(src)
for _from in files:
root, ext = os.path.splitext(_from)
if not ext in exts:
continue
_to = dst + _from[len(src):]
print(_from + '\t:\t' + _to)
if not os.path.exists(os.path.dirname(_to)):
os.makedirs(os.path.dirname(_to))
shutil.copy(_from, _to)
def isWin():
return platform.system() == 'Windows'
def isMac():
return platform.system() == 'Darwin'
def wget(address):
urllib.request.urlretrieve(address, os.path.basename(address))
def rm(path):
if os.path.exists(path):
os.remove(path)
def rmdir(path):
if os.path.exists(path):
print("rmdir : " + path)
shutil.rmtree(path)
else:
print("rmdir : not found " + path)
def cd(path):
os.chdir(path)
def cdToScript():
cd(os.path.dirname(os.path.abspath(__file__)))
def mkdir(path):
if not os.path.exists(path):
os.mkdir(path)
def copy(src, dst):
print("copying from {0} to {1}".format(src, dst))
shutil.copy(src, dst)
def copytree(src, dst, change=False, ignoreList=None):
print("copying tree from {0} to {1}".format(src, dst))
if change and os.path.exists(dst):
rmdir(dst)
if not os.path.exists(dst):
shutil.copytree(src, dst, ignore=ignoreList)
class CurrentDir:
def __init__(self, path):
self.prev = os.getcwd()
self.path = path
def __enter__(self):
cd(self.path)
#print("cd: " + os.getcwd())
return self
def __exit__(self, type, value, traceback):
cd(self.prev)
#print("cd: " + os.getcwd())
env = os.environ.copy()
env = os.environ.copy()
env["PKG_CONFIG_PATH"] = os.getenv(
'PKG_CONFIG_PATH', '/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig')
env["AS"] = os.getenv('AS', 'as -arch i386')
env["CC"] = os.getenv('CC', 'clang -arch i386 -mmacosx-version-min=10.6')
env["MONO_SDK_PATH"] = os.getenv(
'MONO_SDK_PATH', '/Library/Frameworks/Mono.framework/Versions/Current')
env["PACKAGEING_FOR_MAC"] = os.getenv('PACKAGEING_FOR_MAC', '0')
env["PACKAGEING_FOR_LINUX"] = os.getenv('PACKAGEING_FOR_LINUX', '0')
env['X86'] = os.getenv('X86', '0')
env["IGNORE_BUILD"] = os.getenv('IGNORE_BUILD', '0')
is_x86 = env['X86'] == '1'
is_from_ci = 'from_ci' in sys.argv
if isMac():
with CurrentDir('Tool/EffekseerLauncher'):
call('sh build_macosx.sh')
if env['IGNORE_BUILD'] == '0':
os.makedirs('build', exist_ok=True)
if isWin():
candidates = [
r"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe",
r"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe",
r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe",
r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe",
]
candidate = None
for candidate in candidates:
if os.path.exists(candidate):
msbuild_path = candidate
break
if msbuild_path is None:
raise Exception("MSBuild is not found")
elif isMac():
msbuild_path = 'msbuild'
with CurrentDir('build'):
if isWin() or isMac():
# for auto restore of .csproj
wget(r'https://dist.nuget.org/win-x86-commandline/v5.1.0/nuget.exe')
if isWin():
suffix = ''
if is_from_ci:
suffix += ' -D FROM_CI=ON'
if is_x86:
call('cmake .. -A Win32 -DBUILD_VIEWER=ON' + suffix)
else:
# run tests on x64
call('cmake .. -A x64 -DBUILD_VIEWER=ON -D BUILD_TEST=ON -D BUILD_EXAMPLES=ON' + suffix)
elif isMac():
call('cmake .. -G "Xcode" -DBUILD_VIEWER=ON -D BUILD_TEST=ON -D BUILD_EXAMPLES=ON')
elif find_executable('ninja'):
call('cmake .. -G Ninja -DBUILD_VIEWER=ON -D BUILD_TEST=ON -D BUILD_EXAMPLES=ON')
else:
call('cmake .. -G "Unix Makefiles" -DBUILD_VIEWER=ON')
call('cmake --build . --config Release')
if isWin():
call('build\\nuget.exe restore Dev/Editor/Effekseer.sln')
if isMac():
call('dotnet build Dev/Editor/Effekseer/Effekseer.Std.csproj')
call('dotnet publish Dev/Editor/Effekseer/Effekseer.Std.csproj -c Release --self-contained -r osx.10.11-x64')
call('cp -r Dev/release/osx.10.11-x64/publish/* Dev/release/')
call('rm -rf -r Dev/release/osx.10.11-x64')
elif isWin():
if is_x86:
call('"' + msbuild_path + '"' +
' Dev/Editor/EffekseerCore/EffekseerCore.csproj /t:build /p:Configuration=Release /p:Platform=x86')
call('"' + msbuild_path + '"' +
' Dev/Editor/EffekseerCoreGUI/EffekseerCoreGUI.csproj /t:build /p:Configuration=Release /p:Platform=x86')
call('"' + msbuild_path + '"' +
' Dev/Editor/Effekseer/Effekseer.csproj /t:build /p:Configuration=Release /p:Platform=x86')
else:
call('"' + msbuild_path + '"' +
' Dev/Editor/EffekseerCore/EffekseerCore.csproj /t:build /p:Configuration=Release /p:Platform=x64')
call('"' + msbuild_path + '"' +
' Dev/Editor/Effekseer/Effekseer.csproj /t:build /p:Configuration=Release /p:Platform=x64')
else:
call('dotnet build Dev/Editor/Effekseer/Effekseer.Std.csproj')
call('dotnet publish Dev/Editor/Effekseer/Effekseer.Std.csproj -c Release --self-contained -r linux-x64')
call('chmod +x Dev/release/Effekseer')
call('chmod +x Dev/release/EffekseerMaterialEditor')
call('chmod +x Dev/release/tools/fbxToEffekseerCurveConverter')
call('chmod +x Dev/release/tools/fbxToEffekseerModelConverter')
call('chmod +x Dev/release/tools/libfbxsdk.so')
call('cp -r Dev/release/linux-x64/publish/* Dev/release/')
call('rm -rf -r Dev/release/linux-x64')
if env['PACKAGEING_FOR_MAC'] == '1' and isMac():
cd('Dev')
mkdir('Mac/Effekseer.app/Contents/Resources/')
distutils.dir_util.copy_tree('release/', 'Mac/Effekseer.app/Contents/Resources/')
mkdir('Mac/Effekseer.app/Contents/MacOS/')
shutil.copy('../Tool/EffekseerLauncher/build_macosx/EffekseerLauncher', 'Mac/Effekseer.app/Contents/MacOS/')
call('chmod +x Mac/Effekseer.app/Contents/Resources/tools/fbxToEffekseerCurveConverter')
call('chmod +x Mac/Effekseer.app/Contents/Resources/tools/fbxToEffekseerModelConverter')
os.makedirs('Mac/Package', exist_ok=True)
distutils.dir_util.copy_tree('Mac/Effekseer.app', 'Mac/Package/Effekseer.app')
call('ln -s /Applications Applications > /dev/null 2>&1')
call('mv Applications Mac/Package/')
call('hdiutil create Effekseer.dmg -volname "Effekseer" -srcfolder "Mac/Package"')
cd('../')
os.makedirs('EffekseerTool', exist_ok=True)
shutil.copy('Dev/Effekseer.dmg', 'EffekseerTool/')
shutil.copy('docs/Help_Ja.html', 'EffekseerTool/')
shutil.copy('docs/Help_En.html', 'EffekseerTool/')
shutil.copy('LICENSE_TOOL', 'EffekseerTool/LICENSE_TOOL')
shutil.copy('readme_tool_mac.txt', 'EffekseerTool/readme.txt')
os.makedirs('EffekseerTool/Sample/', exist_ok=True)
distutils.dir_util.copy_tree('Release/Sample', 'EffekseerTool/Sample')
distutils.dir_util.copy_tree(
'ResourceData/samples', 'EffekseerTool/Sample')
shutil.copy('docs/readme_sample.txt', 'EffekseerTool/Sample/readme.txt')