Exemplo n.º 1
0
    def run(self):
        if self.is_clean_before_build:
            utils_cocos.rmdir(self.simulator_output_dir)

        # backup some files
        modify_files = self.get_depend_project_file_list()
        if utils_cocos.os_is_mac():
            modify_files.append(os.path.join(self.simulator_abs_path, 'frameworks/runtime-src/proj.ios_mac/mac/Info.plist'))
        elif utils_cocos.os_is_win32():
            modify_files.append(os.path.join(self.simulator_abs_path, 'frameworks/runtime-src/proj.win32/game.rc'))

        self.backup_files(modify_files)

        try:
            # modify bundle version
            self.update_bundle_version()

            # modify project config files
            self.change_cocos2d_debug_macro_to_1(modify_files)

            # compile simulator
            self.do_compile()
        except Exception as e:
            raise e
        finally:
            # roll back modified files
            self.rollback_files(modify_files)
            Logging.info("")
            Logging.info(self.build_log)
            Logging.info("")

        return 0
Exemplo n.º 2
0
    def generate(self):
        self.clean_template()
        self.copy_template()
        self.modify_binary_mk()
        self.gen_templates()

        # copy the templates into the templates folder of engine
        excopy.copy_files_in_dir(self.temp_dir,
                                 os.path.join(self.repo_x, "templates"))

        # remove the temp dir
        utils_cocos.rmdir(self.temp_dir)
Exemplo n.º 3
0
 def clean_template(self):
     utils_cocos.rmdir(self.temp_dir)
     utils_cocos.rmdir(
         os.path.join(self.engine_template_dir, "cpp-template-binary"))
     utils_cocos.rmdir(
         os.path.join(self.engine_template_dir, "lua-template-binary"))
     utils_cocos.rmdir(
         os.path.join(self.engine_template_dir, "js-template-binary"))
Exemplo n.º 4
0
    def run(self):
        if self.is_clean_before_build:
            utils_cocos.rmdir(self.simulator_output_dir)

        # backup some files
        modify_files = self.get_depend_project_file_list()
        if utils_cocos.os_is_mac():
            modify_files.append(
                os.path.join(
                    self.simulator_abs_path,
                    'frameworks/runtime-src/proj.ios_mac/mac/Info.plist'))
        elif utils_cocos.os_is_win32():
            modify_files.append(
                os.path.join(self.simulator_abs_path,
                             'frameworks/runtime-src/proj.win32/game.rc'))

        self.backup_files(modify_files)

        try:
            # modify bundle version
            self.update_bundle_version()

            # modify project config files
            self.change_cocos2d_debug_macro_to_1(modify_files)

            # compile simulator
            self.do_compile()
        except Exception as e:
            raise e
        finally:
            # roll back modified files
            self.rollback_files(modify_files)
            Logging.info("")
            Logging.info(self.build_log)
            Logging.info("")

        return 0
 def clean_template(self):
     utils_cocos.rmdir(os.path.join(self.engine_template_dir, "cpp-template-binary"))
     utils_cocos.rmdir(os.path.join(self.engine_template_dir, "lua-template-binary"))
     utils_cocos.rmdir(os.path.join(self.engine_template_dir, "js-template-binary"))
Exemplo n.º 6
0
 def clean_libs(self):
     print("to clean libs")
     utils_cocos.rmdir(self.lib_dir)
Exemplo n.º 7
0
    def compile_mac_ios(self):
        if not utils_cocos.os_is_mac():
            print("this is not mac platform, needn't compile")
            return
        print("to compile mac")

        xcode_proj_info = self.cfg_info[CocosLibsCompiler.KEY_XCODE_PROJS_INFO]

        XCODE_CMD_FMT = "xcodebuild -project \"%s\" -configuration Release -target \"%s\" %s CONFIGURATION_BUILD_DIR=%s"
        for key in xcode_proj_info.keys():
            proj_path = os.path.join(self.repo_x, key)
            ios_out_dir = os.path.join(self.lib_dir, "ios")
            mac_out_dir = os.path.join(self.lib_dir, "mac")
            ios_sim_libs_dir = os.path.join(ios_out_dir, "simulator")
            ios_dev_libs_dir = os.path.join(ios_out_dir, "device")

            target = xcode_proj_info[key][CocosLibsCompiler.KEY_XCODE_TARGETS]

            # compile ios simulator
            build_cmd = XCODE_CMD_FMT % (
                proj_path, "%s iOS" % target,
                "-sdk iphonesimulator ARCHS=\"i386 x86_64\" VALID_ARCHS=\"i386 x86_64\"",
                ios_sim_libs_dir)
            retVal = utils_cocos.execute_command(build_cmd)
            if 0 != retVal:
                print("[ERROR] compile ios simulator fail")
                return retVal

            # compile ios device
            build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target,
                                         "-sdk iphoneos", ios_dev_libs_dir)
            retVal = utils_cocos.execute_command(build_cmd)
            if 0 != retVal:
                print("[ERROR] compile ios device fail")
                return retVal

            # compile mac
            build_cmd = XCODE_CMD_FMT % (proj_path, "%s Mac" % target, "",
                                         mac_out_dir)
            retVal = utils_cocos.execute_command(build_cmd)
            if 0 != retVal:
                print("[ERROR] compile mac fail")
                return retVal

            # generate fat libs for iOS
            for lib in os.listdir(ios_sim_libs_dir):
                sim_lib = os.path.join(ios_sim_libs_dir, lib)
                dev_lib = os.path.join(ios_dev_libs_dir, lib)
                output_lib = os.path.join(ios_out_dir, lib)
                lipo_cmd = "lipo -create -output \"%s\" \"%s\" \"%s\"" % (
                    output_lib, sim_lib, dev_lib)

                utils_cocos.execute_command(lipo_cmd)

            # remove the simulator & device libs in iOS
            utils_cocos.rmdir(ios_sim_libs_dir)
            utils_cocos.rmdir(ios_dev_libs_dir)

            if not self.disable_strip:
                # strip the libs
                ios_strip_cmd = "xcrun -sdk iphoneos strip -S %s/*.a" % ios_out_dir
                utils_cocos.execute_command(ios_strip_cmd)
                mac_strip_cmd = "xcrun strip -S %s/*.a" % mac_out_dir
                utils_cocos.execute_command(mac_strip_cmd)
Exemplo n.º 8
0
    def compile_android(self, language):
        print("compile android")
        # build .so for android
        CONSOLE_PATH = "tools/cocos2d-console/bin"
        ANDROID_A_PATH = "frameworks/runtime-src/proj.android/obj/local"

        android_out_dir = os.path.join(self.lib_dir, "android")
        engine_dir = self.repo_x
        console_dir = os.path.join(engine_dir, CONSOLE_PATH)
        if utils_cocos.os_is_win32():
            cmd_path = os.path.join(console_dir, "cocos.bat")
        else:
            cmd_path = os.path.join(console_dir, "cocos")

        proj_name = "My%sGame" % language
        proj_dir = os.path.join(self.cur_dir, "temp")
        proj_path = os.path.join(proj_dir, proj_name)
        utils_cocos.rmdir(proj_path)

        # create a runtime project
        create_cmd = "%s new -l %s -t runtime -d %s %s" % (cmd_path, language,
                                                           proj_dir, proj_name)
        utils_cocos.execute_command(create_cmd)

        # build it
        build_cmd = "%s compile -s %s -p android --ndk-mode release -j 4 --app-abi %s" % (
            cmd_path, proj_path, self.app_abi)
        utils_cocos.execute_command(build_cmd)

        # copy .a to prebuilt dir
        obj_dir = os.path.join(proj_path, ANDROID_A_PATH)
        copy_cfg = {
            "from": obj_dir,
            "to": android_out_dir,
            "include": ["*.a$"]
        }
        excopy.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)

        if not self.disable_strip:
            # strip the android libs
            ndk_root = os.environ["NDK_ROOT"]
            if utils_cocos.os_is_win32():
                if utils_cocos.is_32bit_windows():
                    bit_str = ""
                else:
                    bit_str = "-x86_64"
                sys_folder_name = "windows%s" % bit_str
            elif utils_cocos.os_is_mac():
                sys_folder_name = "darwin-x86_64"

            # set strip execute file name
            if utils_cocos.os_is_win32():
                strip_execute_name = "strip.exe"
            else:
                strip_execute_name = "strip"

            # strip arm libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/arm-linux-androideabi-4.8/prebuilt/%s/arm-linux-androideabi/bin/%s"
                % (sys_folder_name, strip_execute_name))
            if not os.path.exists(strip_cmd_path):
                strip_cmd_path = os.path.join(
                    ndk_root,
                    "toolchains/arm-linux-androideabi-4.8/prebuilt/%s/arm-linux-androideabi/bin/%s"
                    %
                    (sys_folder_name.replace(bit_str, ""), strip_execute_name))
            if os.path.exists(strip_cmd_path):
                armlibs = ["armeabi", "armeabi-v7a"]
                for fold in armlibs:
                    self.trip_libs(strip_cmd_path,
                                   os.path.join(android_out_dir, fold))

            # strip x86 libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/x86-4.8/prebuilt/%s/i686-linux-android/bin/%s" %
                (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path) and os.path.exists(
                    os.path.join(android_out_dir, "x86")):
                self.trip_libs(strip_cmd_path,
                               os.path.join(android_out_dir, 'x86'))

        # remove the project
        utils_cocos.rmdir(proj_path)
Exemplo n.º 9
0
 def clean_libs(self):
     print("to clean libs")
     utils_cocos.rmdir(self.lib_dir)
Exemplo n.º 10
0
    def compile_mac_ios(self):
        if not utils_cocos.os_is_mac():
            print("this is not mac platform, needn't compile")
            return
        print("to compile mac")

        xcode_proj_info = self.cfg_info[CocosLibsCompiler.KEY_XCODE_PROJS_INFO]

        XCODE_CMD_FMT = "xcodebuild -project \"%s\" -configuration Release -target \"%s\" %s CONFIGURATION_BUILD_DIR=%s"
        ios_out_dir = os.path.join(self.lib_dir, "ios")
        mac_out_dir = os.path.join(self.lib_dir, "mac")
        ios_sim_libs_dir = os.path.join(ios_out_dir, "simulator")
        ios_dev_libs_dir = os.path.join(ios_out_dir, "device")
        for key in xcode_proj_info.keys():
            proj_path = os.path.join(self.repo_x, key)
            target = xcode_proj_info[key][CocosLibsCompiler.KEY_XCODE_TARGETS]

            if self.build_mac:
                # compile mac
                build_cmd = XCODE_CMD_FMT % (proj_path, "%s Mac" % target, "", mac_out_dir)
                retVal = utils_cocos.execute_command(build_cmd)
                if 0 != retVal:
                    print("[ERROR] compile mac fail")
                    return retVal

            if self.build_ios:
                # compile ios simulator
                build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphonesimulator ARCHS=\"i386 x86_64\" VALID_ARCHS=\"i386 x86_64\"", ios_sim_libs_dir)
                retVal = utils_cocos.execute_command(build_cmd)
                if 0 != retVal:
                    print("[ERROR] compile ios simulator fail")
                    return retVal

                # compile ios device
                build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphoneos", ios_dev_libs_dir)
                retVal = utils_cocos.execute_command(build_cmd)
                if 0 != retVal:
                    print("[ERROR] compile ios device fail")
                    return retVal

        if self.build_ios:
            # generate fat libs for iOS
            for lib in os.listdir(ios_sim_libs_dir):
                sim_lib = os.path.join(ios_sim_libs_dir, lib)
                dev_lib = os.path.join(ios_dev_libs_dir, lib)
                output_lib = os.path.join(ios_out_dir, lib)
                lipo_cmd = "lipo -create -output \"%s\" \"%s\" \"%s\"" % (output_lib, sim_lib, dev_lib)

                utils_cocos.execute_command(lipo_cmd)

            # remove the simulator & device libs in iOS
            utils_cocos.rmdir(ios_sim_libs_dir)
            utils_cocos.rmdir(ios_dev_libs_dir)

        if not self.disable_strip:
            # strip the libs
            if self.build_ios:
                ios_strip_cmd = "xcrun -sdk iphoneos strip -S %s/*.a" % ios_out_dir
                utils_cocos.execute_command(ios_strip_cmd)
            if self.build_mac:
                mac_strip_cmd = "xcrun strip -S %s/*.a" % mac_out_dir
                utils_cocos.execute_command(mac_strip_cmd)