@@ -33,7 +33,6 @@ class LibsCompiler(cocos.CCPlugin):
33
33
34
34
KEY_XCODE_TARGETS = 'targets'
35
35
KEY_VS_BUILD_TARGETS = 'build_targets'
36
- KEY_VS_RENAME_TARGETS = 'rename_targets'
37
36
38
37
@staticmethod
39
38
def plugin_name ():
@@ -53,7 +52,7 @@ def parse_args(self, argv):
53
52
parser .add_argument ('-e' , dest = 'engine_path' , help = MultiLanguage .get_string ('GEN_LIBS_ARG_ENGINE' ))
54
53
parser .add_argument ('-p' , dest = 'platform' , action = "append" , choices = ['ios' , 'mac' , 'android' , 'win32' ],
55
54
help = MultiLanguage .get_string ('GEN_LIBS_ARG_PLATFORM' ))
56
- parser .add_argument ('-m' , "--mode" , dest = 'compile_mode' , default = 'release ' , choices = ['debug' , 'release' ],
55
+ parser .add_argument ('-m' , "--mode" , dest = 'compile_mode' , default = 'debug ' , choices = ['debug' , 'release' ],
57
56
help = MultiLanguage .get_string ('GEN_LIBS_ARG_MODE' ))
58
57
parser .add_argument ('--dis-strip' , dest = 'disable_strip' , action = "store_true" ,
59
58
help = MultiLanguage .get_string ('GEN_LIBS_ARG_DISABLE_STRIP' ))
@@ -65,6 +64,10 @@ def parse_args(self, argv):
65
64
help = MultiLanguage .get_string ('GEN_LIBS_ARG_ABI' ))
66
65
group .add_argument ("--ap" , dest = "android_platform" ,
67
66
help = MultiLanguage .get_string ('COMPILE_ARG_AP' ))
67
+ group .add_argument ('-l' , dest = 'language' ,
68
+ choices = ['cpp' , 'lua' , 'js' ],
69
+ default = 'cpp' ,
70
+ help = 'set project type to build' )
68
71
69
72
(args , unknown ) = parser .parse_known_args (argv )
70
73
self .init (args )
@@ -104,6 +107,7 @@ def init(self, args):
104
107
self .clean = args .clean
105
108
self .mode = args .compile_mode
106
109
self ._verbose = True
110
+ self .language = args .language
107
111
108
112
if args .platform is None :
109
113
self .build_ios = True
@@ -128,7 +132,7 @@ def init(self, args):
128
132
self .vs_version = args .vs_version
129
133
self .use_incredibuild = False
130
134
if args .app_abi is None :
131
- self .app_abi = 'armeabi'
135
+ self .app_abi = 'armeabi-v7a '
132
136
else :
133
137
self .app_abi = args .app_abi
134
138
self .android_platform = args .android_platform
@@ -171,7 +175,7 @@ def compile(self):
171
175
if self .build_android :
172
176
self .compile_android ()
173
177
# generate prebuilt mk files
174
- self .modify_binary_mk ()
178
+ # self.modify_binary_mk()
175
179
176
180
def build_win32_proj (self , cmd_path , sln_path , proj_name , mode ):
177
181
build_cmd = " " .join ([
@@ -216,84 +220,56 @@ def compile_win(self):
216
220
217
221
# get the VS projects info
218
222
win32_proj_info = self .cfg_info [LibsCompiler .KEY_VS_PROJS_INFO ]
223
+ proj_path = win32_proj_info ['proj_path' ]
219
224
for vs_version in compile_vs_versions :
220
225
if not vs_version in vs_cmd_info .keys ():
221
226
continue
222
227
223
- # rename the cocos2d project out dll name
224
- f = open (cocos2d_proj_file , 'r' )
225
- old_file_content = f .read ()
226
- f .close ()
227
-
228
- new_file_content = old_file_content .replace ('$(OutDir)$(ProjectName).dll' , '$(OutDir)$(ProjectName)_%d.dll' % vs_version )
229
- f = open (cocos2d_proj_file , 'w' )
230
- f .write (new_file_content )
231
- f .close ()
232
-
233
228
try :
234
229
vs_command = vs_cmd_info [vs_version ]
235
- for key in win32_proj_info .keys ():
236
- # clean solutions
237
- proj_path = os .path .join (self .repo_x , key )
238
- clean_cmd = " " .join ([
239
- "\" %s\" " % vs_command ,
240
- "\" %s\" " % proj_path ,
241
- "/t:Clean /p:Configuration=%s" % mode_str
230
+ # clean solutions
231
+ full_proj_path = os .path .join (self .repo_x , proj_path )
232
+ clean_cmd = " " .join ([
233
+ "\" %s\" " % vs_command ,
234
+ "\" %s\" " % full_proj_path ,
235
+ "/t:Clean /p:Configuration=%s" % mode_str
236
+ ])
237
+ self ._run_cmd (clean_cmd )
238
+
239
+ output_dir = os .path .join (self .lib_dir , "win32" )
240
+
241
+ # get the build folder & win32 output folder
242
+ build_folder_path = os .path .join (os .path .dirname (proj_path ), "%s.win32" % mode_str )
243
+ win32_output_dir = os .path .join (self .repo_x , output_dir )
244
+ if not os .path .exists (win32_output_dir ):
245
+ os .makedirs (win32_output_dir )
246
+
247
+ # build project
248
+ if self .use_incredibuild :
249
+ # use incredibuild, build whole sln
250
+ build_cmd = " " .join ([
251
+ "BuildConsole" ,
252
+ "%s" % proj_path ,
253
+ "/build" ,
254
+ "/cfg=\" %s|Win32\" " % mode_str
242
255
])
243
- self ._run_cmd (clean_cmd )
244
-
245
- for key in win32_proj_info .keys ():
246
- output_dir = os .path .join (self .lib_dir , "win32" )
247
- proj_path = os .path .join (self .repo_x , key )
248
-
249
- # get the build folder & win32 output folder
250
- build_folder_path = os .path .join (os .path .dirname (proj_path ), "%s.win32" % mode_str )
251
- win32_output_dir = os .path .join (self .repo_x , output_dir )
252
- if not os .path .exists (win32_output_dir ):
253
- os .makedirs (win32_output_dir )
254
-
255
- # build project
256
- if self .use_incredibuild :
257
- # use incredibuild, build whole sln
258
- build_cmd = " " .join ([
259
- "BuildConsole" ,
260
- "%s" % proj_path ,
261
- "/build" ,
262
- "/cfg=\" %s|Win32\" " % mode_str
263
- ])
264
- self ._run_cmd (build_cmd )
265
- else :
266
- for proj_name in win32_proj_info [key ][LibsCompiler .KEY_VS_BUILD_TARGETS ]:
267
- # build the projects
268
- self .build_win32_proj (vs_command , proj_path , proj_name , mode_str )
269
-
270
- # copy the libs into prebuilt dir
271
- for file_name in os .listdir (build_folder_path ):
272
- name , ext = os .path .splitext (file_name )
273
- if ext != ".lib" and ext != ".dll" :
274
- continue
275
-
276
- file_path = os .path .join (build_folder_path , file_name )
277
- shutil .copy (file_path , win32_output_dir )
278
-
279
- # rename the specified libs
280
- suffix = "_%d" % vs_version
281
- for proj_name in win32_proj_info [key ][LibsCompiler .KEY_VS_RENAME_TARGETS ]:
282
- src_name = os .path .join (win32_output_dir , "%s.lib" % proj_name )
283
- dst_name = os .path .join (win32_output_dir , "%s%s.lib" % (proj_name , suffix ))
284
- if not os .path .exists (src_name ):
285
- raise CCPluginError (MultiLanguage .get_string ('GEN_LIBS_ERROR_LIB_NOT_GEN_FMT' , src_name ),
286
- CCPluginError .ERROR_PATH_NOT_FOUND )
287
-
288
- if os .path .exists (dst_name ):
289
- os .remove (dst_name )
290
- os .rename (src_name , dst_name )
256
+ self ._run_cmd (build_cmd )
257
+ else :
258
+ for proj_name in win32_proj_info [self .language ][LibsCompiler .KEY_VS_BUILD_TARGETS ]:
259
+ # build the projects
260
+ self .build_win32_proj (vs_command , proj_path , proj_name , mode_str )
261
+
262
+ # copy the libs into prebuilt dir
263
+ for file_name in os .listdir (build_folder_path ):
264
+ name , ext = os .path .splitext (file_name )
265
+ if ext != ".lib" and ext != ".dll" :
266
+ continue
267
+
268
+ file_path = os .path .join (build_folder_path , file_name )
269
+ shutil .copy (file_path , win32_output_dir )
270
+
291
271
except Exception as e :
292
272
raise e
293
- finally :
294
- f = open (cocos2d_proj_file , 'w' )
295
- f .write (old_file_content )
296
- f .close ()
297
273
298
274
def compile_mac_ios (self ):
299
275
xcode_proj_info = self .cfg_info [LibsCompiler .KEY_XCODE_PROJS_INFO ]
@@ -307,9 +283,19 @@ def compile_mac_ios(self):
307
283
mac_out_dir = os .path .join (self .lib_dir , "mac" )
308
284
ios_sim_libs_dir = os .path .join (ios_out_dir , "simulator" )
309
285
ios_dev_libs_dir = os .path .join (ios_out_dir , "device" )
310
- for key in xcode_proj_info .keys ():
311
- proj_path = os .path .join (self .repo_x , key )
312
- target = xcode_proj_info [key ][LibsCompiler .KEY_XCODE_TARGETS ]
286
+ cocos_cmd = self ._get_cocos_cmd_path ()
287
+
288
+ if self .language == 'cpp' :
289
+ build_types = ['cpp' ]
290
+ if self .language == 'lua' :
291
+ build_types = ['cpp' , 'lua' ]
292
+ if self .language == 'js' :
293
+ build_types = ['cpp' , 'js' ]
294
+
295
+ for key in build_types :
296
+ proj_info = xcode_proj_info [key ]
297
+ proj_path = os .path .join (self .repo_x , proj_info ['proj_path' ])
298
+ target = proj_info ['targets' ]
313
299
314
300
if self .build_mac :
315
301
# compile mac
@@ -325,15 +311,15 @@ def compile_mac_ios(self):
325
311
build_cmd = XCODE_CMD_FMT % (proj_path , mode_str , "%s iOS" % target , "-sdk iphoneos" , ios_dev_libs_dir )
326
312
self ._run_cmd (build_cmd )
327
313
328
- if self .build_ios :
329
- # generate fat libs for iOS
330
- for lib in os .listdir (ios_sim_libs_dir ):
331
- sim_lib = os .path .join (ios_sim_libs_dir , lib )
332
- dev_lib = os .path .join (ios_dev_libs_dir , lib )
333
- output_lib = os .path .join (ios_out_dir , lib )
334
- lipo_cmd = "lipo -create -output \" %s\" \" %s\" \" %s\" " % (output_lib , sim_lib , dev_lib )
314
+ if self .build_ios :
315
+ # generate fat libs for iOS
316
+ for lib in os .listdir (ios_sim_libs_dir ):
317
+ sim_lib = os .path .join (ios_sim_libs_dir , lib )
318
+ dev_lib = os .path .join (ios_dev_libs_dir , lib )
319
+ output_lib = os .path .join (ios_out_dir , lib )
320
+ lipo_cmd = "lipo -create -output \" %s\" \" %s\" \" %s\" " % (output_lib , sim_lib , dev_lib )
335
321
336
- self ._run_cmd (lipo_cmd )
322
+ self ._run_cmd (lipo_cmd )
337
323
338
324
# remove the simulator & device libs in iOS
339
325
utils .rmdir (ios_sim_libs_dir )
@@ -350,25 +336,27 @@ def compile_mac_ios(self):
350
336
351
337
def compile_android (self ):
352
338
# build .so for android
353
- CONSOLE_PATH = "tools/cocos2d-console/bin"
354
- ANDROID_A_PATH = "frameworks/runtime-src/proj.android/obj/local"
355
-
356
- android_out_dir = os .path .join (self .lib_dir , "android" )
339
+ cmd_path = self ._get_cocos_cmd_path ()
357
340
engine_dir = self .repo_x
358
- console_dir = os .path .join (engine_dir , CONSOLE_PATH )
359
- if cocos .os_is_win32 ():
360
- cmd_path = os .path .join (console_dir , "cocos.bat" )
361
- else :
362
- cmd_path = os .path .join (console_dir , "cocos" )
363
341
364
342
# build the simulator project
365
- proj_path = os .path .join (engine_dir , 'tools/simulator' )
343
+ proj_path = os .path .join (engine_dir , 'tests/cpp-empty-test' )
344
+ if self .language == 'lua' :
345
+ proj_path = os .path .join (engine_dir , 'tests/lua-empty-test' )
346
+ elif self .language == 'js' :
347
+ proj_path = os .path .join (engine_dir , 'tests/js-tests' )
348
+
366
349
build_cmd = "%s compile -s %s -p android --ndk-mode %s --app-abi %s" % (cmd_path , proj_path , self .mode , self .app_abi )
367
350
if self .android_platform is not None :
368
351
build_cmd += ' --ap %s' % self .android_platform
369
352
self ._run_cmd (build_cmd )
370
353
371
354
# copy .a to prebuilt dir
355
+ ANDROID_A_PATH = "proj.android/app/build/intermediates/ndkBuild/%s/obj/local/%s" % (self .mode , self .app_abi )
356
+ if self .language != 'cpp' :
357
+ ANDROID_A_PATH = 'project/' + ANDROID_A_PATH
358
+
359
+ android_out_dir = os .path .join (self .lib_dir , "android" )
372
360
obj_dir = os .path .join (proj_path , ANDROID_A_PATH )
373
361
copy_cfg = {
374
362
"from" : obj_dir ,
@@ -391,7 +379,7 @@ def compile_android(self):
391
379
sys_folder_name = "windows"
392
380
for bit_str in check_bits :
393
381
check_folder_name = "windows%s" % bit_str
394
- check_path = os .path .join (ndk_root , "toolchains/arm-linux-androideabi-4.8 /prebuilt/%s" % check_folder_name )
382
+ check_path = os .path .join (ndk_root , "toolchains/arm-linux-androideabi-4.9 /prebuilt/%s" % check_folder_name )
395
383
if os .path .isdir (check_path ):
396
384
sys_folder_name = check_folder_name
397
385
break
@@ -407,12 +395,11 @@ def compile_android(self):
407
395
strip_execute_name = "strip"
408
396
409
397
# strip arm libs
410
- strip_cmd_path = os .path .join (ndk_root , "toolchains/arm-linux-androideabi-4.8 /prebuilt/%s/arm-linux-androideabi/bin/%s"
398
+ strip_cmd_path = os .path .join (ndk_root , "toolchains/arm-linux-androideabi-4.9 /prebuilt/%s/arm-linux-androideabi/bin/%s"
411
399
% (sys_folder_name , strip_execute_name ))
412
400
if os .path .exists (strip_cmd_path ):
413
- armlibs = ["armeabi" , "armeabi-v7a" ]
414
- for fold in armlibs :
415
- self .trip_libs (strip_cmd_path , os .path .join (android_out_dir , fold ))
401
+ self .trip_libs (strip_cmd_path , os .path .join (android_out_dir , "armeabi-v7a" ))
402
+
416
403
417
404
# strip arm64-v8a libs
418
405
strip_cmd_path = os .path .join (ndk_root , "toolchains/aarch64-linux-android-4.9/prebuilt/%s/aarch64-linux-android/bin/%s" % (sys_folder_name , strip_execute_name ))
@@ -424,6 +411,18 @@ def compile_android(self):
424
411
if os .path .exists (strip_cmd_path ) and os .path .exists (os .path .join (android_out_dir , "x86" )):
425
412
self .trip_libs (strip_cmd_path , os .path .join (android_out_dir , 'x86' ))
426
413
414
+ def _get_cocos_cmd_path (self ):
415
+ CONSOLE_PATH = "tools/cocos2d-console/bin"
416
+
417
+ engine_dir = self .repo_x
418
+ console_dir = os .path .join (engine_dir , CONSOLE_PATH )
419
+ if cocos .os_is_win32 ():
420
+ cmd_path = os .path .join (console_dir , "cocos.bat" )
421
+ else :
422
+ cmd_path = os .path .join (console_dir , "cocos" )
423
+
424
+ return cmd_path
425
+
427
426
def trip_libs (self , strip_cmd , folder ):
428
427
if not os .path .isdir (folder ):
429
428
return
0 commit comments