forked from funkyzooink/fresh-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·238 lines (194 loc) · 7.96 KB
/
build.py
File metadata and controls
executable file
·238 lines (194 loc) · 7.96 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
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
#!/usr/bin/env python
import getopt
import json
import os
import shutil
import subprocess
import sys
def terminal_output(text):
print text
def copy_resources(config_file_path, android_platform):
src = config_file_path + '/Resources' #todo
dest = 'Resources'
copy_files(src, dest)
#android specific
src = config_file_path + 'android/' + android_platform + '/res/mipmap-hdpi' #todo
dest = 'proj.android/app/res/mipmap-hdpi'
copy_files(src, dest)
src = config_file_path + 'android/' + android_platform + '/res/mipmap-mdpi' #todo
dest = 'proj.android/app/res/mipmap-mdpi'
copy_files(src, dest)
src = config_file_path + 'android/' + android_platform + '/res/mipmap-xhdpi' #todo
dest = 'proj.android/app/res/mipmap-xhdpi'
copy_files(src, dest)
src = config_file_path + 'android/' + android_platform + '/res/mipmap-xxhdpi' #todo
dest = 'proj.android/app/res/mipmap-xxhdpi'
copy_files(src, dest)
src = config_file_path + 'android/' + android_platform + '/res/mipmap-xxxhdpi' #todo
dest = 'proj.android/app/res/mipmap-xxxhdpi'
copy_files(src, dest)
#ios specific
src = config_file_path + '/ios/Images.xcassets' #todo
dest = 'proj.ios_mac/ios/Images.xcassets'
copy_files(src, dest)
def copy_templates():
# iOS
src = 'templates/proj.ios_mac'
dest = 'proj.ios_mac'
if os.path.isdir(dest):
terminal_output('Workspace not clean')
sys.exit(2)
copy_files(src, dest)
# Android
src = 'templates/proj.android'
dest = 'proj.android'
if os.path.isdir(dest):
terminal_output('Workspace not clean')
sys.exit(2)
copy_files(src, dest)
# Linux
src = 'templates/proj.linux'
dest = 'proj.linux'
if os.path.isdir(dest):
terminal_output('Workspace not clean')
sys.exit(2)
copy_files(src, dest)
def prepare_templates(app_name, android_bundle_id, ios_bundle_id, version_code, version_name):
src = 'templates/proj.ios_mac'
dest = 'proj.ios_mac'
set_ios_values(dest, app_name, ios_bundle_id) # TODO version number
src = 'templates/proj.android'
dest = 'proj.android'
set_android_values(dest, app_name, android_bundle_id, version_code, version_name)
# rename android folders
app_name = app_name.replace(" ", "")
src = 'proj.android/app/jni/hellocpp'
dest = 'proj.android/app/jni/' + app_name.lower()
os.rename(src, dest)
# cmake
src = 'templates/CMakeLists.txt'
dest = 'CMakeLists.txt'
shutil.copyfile(src, dest)
replace_in_file(dest, app_name.lower(), 'hellocpp')
def copy_files(src, dest):
try:
shutil.copytree(src, dest)
# Directories are the same
except shutil.Error as e:
print('Directory not copied. Error: %s' % e)
# Any error saying that the directory doesn't exist
except OSError as e:
print('Directory not copied. Error: %s' % e)
terminal_output('Files copied to: %s' % dest)
def set_android_values(path, app_name, bundle_id, version_code, version_name):
manifestpath = path + '/app/AndroidManifest.xml'
replace_in_file(manifestpath, bundle_id, 'org.cocos2dx.hellocpp')
terminal_output('App bundleid set to: %s in folder: %s ' % (bundle_id, manifestpath))
stringvaluepath = path + '/app/res/values/strings.xml'
replace_in_file(stringvaluepath, app_name, 'HelloCpp')
terminal_output('App name set to: %s in folder: %s ' % (app_name, stringvaluepath))
gradlepath = path + '/settings.gradle'
replace_in_file(gradlepath, app_name, 'HelloCpp')
gradlepath = path + '/app/build.gradle'
replace_in_file(gradlepath, bundle_id, 'org.cocos2dx.hellocpp')
code = 'versionCode ' + str(version_code)
name = 'versionName \"' + version_name + '\"'
replace_in_file(gradlepath, code , 'versionCode 1')
replace_in_file(gradlepath, name, 'versionName \"1.0\"')
mkpath = path + '/app/jni/Android.mk'
replace_in_file(mkpath, app_name.lower(), 'hellocpp')
def set_ios_values(path, app_name, bundle_id):
srcfolder = path + '/HelloCpp.xcodeproj'
destfolder = path + '/' + app_name + '.xcodeproj'
filepath = srcfolder + '/project.pbxproj'
# App name
replace_in_file(filepath, app_name, 'HelloCpp')
os.rename(srcfolder, destfolder)
terminal_output('App name set to: %s in folder: %s ' % (app_name, destfolder))
# bundle id
infoplistpath = path + '/ios/Info.plist'
replace_in_file(infoplistpath, bundle_id, 'org.cocos2dx.hellocpp')
terminal_output('ios App bundleid set to: %s in folder: %s ' % (bundle_id, infoplistpath))
# TODO mac build, remove?
#infoplistpath = path + '/mac/Info.plist'
#replace_in_file(infoplistpath, bundle_id, 'org.cocos2dx.hellocpp')
#terminal_output('mac App bundleid set to: %s in folder: %s ' % (bundle_id, infoplistpath))
def replace_in_file(filepath, new_value, old_value):
with open (filepath, 'r') as file:
filedata = file.read()
filedata = filedata.replace(old_value, new_value)
with open (filepath, 'w') as file:
file.write(filedata)
def build(platform, build_type):
terminal_output('building platform as %s %s: ' % (platform, build_type))
subprocess.call(["cocos2d//tools//cocos2d-console//bin//cocos", "compile", "-p", platform, "-m", build_type , "-j", "16"])
def clean_folders():
dest = 'proj.ios_mac'
if os.path.isdir(dest):
shutil.rmtree(dest)
terminal_output('Removed %s' % dest)
dest = 'proj.android'
if os.path.isdir(dest):
shutil.rmtree(dest)
terminal_output('Removed %s' % dest)
dest = 'proj.linux'
if os.path.isdir(dest):
shutil.rmtree(dest)
terminal_output('Removed %s' % dest)
dest = 'Resources'
if os.path.isdir(dest):
shutil.rmtree(dest)
terminal_output('Removed %s' % dest)
dest = 'bin'
if os.path.isdir(dest):
shutil.rmtree(dest)
terminal_output('Removed %s' % dest)
def main(argv):
platform = ''
build_type = 'release'
config_file_path = ''
try:
opts, args = getopt.getopt(argv,"p:a:m:n:tc",["platform=", "android-platform=", "build_type=", "config_file_path=", "template", "clean"])
except getopt.GetoptError:
terminal_output("Wrong argument specified")
sys.exit(2)
android_platform = "play"
for opt, arg in opts:
if opt in ("-p", "--platform"):
platform = arg
elif opt in ("-a", "--android-platform"):
android_platform = arg
elif opt in ("-m", "--build_type"):
build_type = arg
elif opt in ("-n", "--config_file_path"):
config_file_path = arg
elif opt in ("-t", "--template"):
copy_templates()
sys.exit(0)
elif opt in ("-c", "--clean"):
clean_folders()
sys.exit(0)
if platform != "":
build(platform, build_type)
elif config_file_path != "":
config = json.loads(open(config_file_path + "/config.json").read())
app_name = config['app_name']
bundle_id_name = android_platform + '_bundle_id'
android_bundle_id = config[bundle_id_name]
ios_bundle_id = config['ios_bundle_id']
version_code = config['version_code']
version_name = config['version_name']
copy_templates()
prepare_templates(app_name, android_bundle_id, ios_bundle_id, version_code, version_name)
copy_resources(config_file_path, android_platform)
else :
terminal_output('Missing Arguments: platform: %s, build_type %s, config_file_path %s' % (platform, build_type, config_file_path))
if __name__ == "__main__":
if len(sys.argv) < 2:
terminal_output("please run with arguments")
terminal_output("for cleaning: build.py -c")
terminal_output("for copying empty templates: build.py -t")
terminal_output("for compiling: build.py -p <iOS|Android> -m <release|debug>")
terminal_output("for creating project files: build.py -n <folder path>")
sys.exit(0)
main(sys.argv[1:])