@@ -33,7 +33,6 @@ class LibsCompiler(cocos.CCPlugin):
3333
3434 KEY_XCODE_TARGETS = 'targets'
3535 KEY_VS_BUILD_TARGETS = 'build_targets'
36- KEY_VS_RENAME_TARGETS = 'rename_targets'
3736
3837 @staticmethod
3938 def plugin_name ():
@@ -53,7 +52,7 @@ def parse_args(self, argv):
5352 parser .add_argument ('-e' , dest = 'engine_path' , help = MultiLanguage .get_string ('GEN_LIBS_ARG_ENGINE' ))
5453 parser .add_argument ('-p' , dest = 'platform' , action = "append" , choices = ['ios' , 'mac' , 'android' , 'win32' ],
5554 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' ],
5756 help = MultiLanguage .get_string ('GEN_LIBS_ARG_MODE' ))
5857 parser .add_argument ('--dis-strip' , dest = 'disable_strip' , action = "store_true" ,
5958 help = MultiLanguage .get_string ('GEN_LIBS_ARG_DISABLE_STRIP' ))
@@ -65,6 +64,10 @@ def parse_args(self, argv):
6564 help = MultiLanguage .get_string ('GEN_LIBS_ARG_ABI' ))
6665 group .add_argument ("--ap" , dest = "android_platform" ,
6766 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' )
6871
6972 (args , unknown ) = parser .parse_known_args (argv )
7073 self .init (args )
@@ -104,6 +107,7 @@ def init(self, args):
104107 self .clean = args .clean
105108 self .mode = args .compile_mode
106109 self ._verbose = True
110+ self .language = args .language
107111
108112 if args .platform is None :
109113 self .build_ios = True
@@ -128,7 +132,7 @@ def init(self, args):
128132 self .vs_version = args .vs_version
129133 self .use_incredibuild = False
130134 if args .app_abi is None :
131- self .app_abi = 'armeabi'
135+ self .app_abi = 'armeabi-v7a '
132136 else :
133137 self .app_abi = args .app_abi
134138 self .android_platform = args .android_platform
@@ -171,7 +175,7 @@ def compile(self):
171175 if self .build_android :
172176 self .compile_android ()
173177 # generate prebuilt mk files
174- self .modify_binary_mk ()
178+ # self.modify_binary_mk()
175179
176180 def build_win32_proj (self , cmd_path , sln_path , proj_name , mode ):
177181 build_cmd = " " .join ([
@@ -216,84 +220,56 @@ def compile_win(self):
216220
217221 # get the VS projects info
218222 win32_proj_info = self .cfg_info [LibsCompiler .KEY_VS_PROJS_INFO ]
223+ proj_path = win32_proj_info ['proj_path' ]
219224 for vs_version in compile_vs_versions :
220225 if not vs_version in vs_cmd_info .keys ():
221226 continue
222227
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-
233228 try :
234229 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
242255 ])
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+
291271 except Exception as e :
292272 raise e
293- finally :
294- f = open (cocos2d_proj_file , 'w' )
295- f .write (old_file_content )
296- f .close ()
297273
298274 def compile_mac_ios (self ):
299275 xcode_proj_info = self .cfg_info [LibsCompiler .KEY_XCODE_PROJS_INFO ]
@@ -307,9 +283,19 @@ def compile_mac_ios(self):
307283 mac_out_dir = os .path .join (self .lib_dir , "mac" )
308284 ios_sim_libs_dir = os .path .join (ios_out_dir , "simulator" )
309285 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' ]
313299
314300 if self .build_mac :
315301 # compile mac
@@ -325,15 +311,15 @@ def compile_mac_ios(self):
325311 build_cmd = XCODE_CMD_FMT % (proj_path , mode_str , "%s iOS" % target , "-sdk iphoneos" , ios_dev_libs_dir )
326312 self ._run_cmd (build_cmd )
327313
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 )
335321
336- self ._run_cmd (lipo_cmd )
322+ self ._run_cmd (lipo_cmd )
337323
338324 # remove the simulator & device libs in iOS
339325 utils .rmdir (ios_sim_libs_dir )
@@ -350,25 +336,27 @@ def compile_mac_ios(self):
350336
351337 def compile_android (self ):
352338 # 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 ()
357340 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" )
363341
364342 # 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+
366349 build_cmd = "%s compile -s %s -p android --ndk-mode %s --app-abi %s" % (cmd_path , proj_path , self .mode , self .app_abi )
367350 if self .android_platform is not None :
368351 build_cmd += ' --ap %s' % self .android_platform
369352 self ._run_cmd (build_cmd )
370353
371354 # 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" )
372360 obj_dir = os .path .join (proj_path , ANDROID_A_PATH )
373361 copy_cfg = {
374362 "from" : obj_dir ,
@@ -391,7 +379,7 @@ def compile_android(self):
391379 sys_folder_name = "windows"
392380 for bit_str in check_bits :
393381 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 )
395383 if os .path .isdir (check_path ):
396384 sys_folder_name = check_folder_name
397385 break
@@ -407,12 +395,11 @@ def compile_android(self):
407395 strip_execute_name = "strip"
408396
409397 # 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"
411399 % (sys_folder_name , strip_execute_name ))
412400 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+
416403
417404 # strip arm64-v8a libs
418405 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):
424411 if os .path .exists (strip_cmd_path ) and os .path .exists (os .path .join (android_out_dir , "x86" )):
425412 self .trip_libs (strip_cmd_path , os .path .join (android_out_dir , 'x86' ))
426413
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+
427426 def trip_libs (self , strip_cmd , folder ):
428427 if not os .path .isdir (folder ):
429428 return
0 commit comments