Exemplo n.º 1
0
    def update_bundle_version(self):
        build_date = date.today().strftime("%Y%m%d")

        if utils_cocos.os_is_mac():
            # mac
            info_plist_path = os.path.join(self.simulator_abs_path, "frameworks/runtime-src/proj.ios_mac/mac/Info.plist")
            info_plist_content = self.get_content_from_file(info_plist_path)

            match = re.compile('<key>CFBundleVersion</key>(\s)*<string>(.*?)</string>').findall(info_plist_content)
            if len(match):
                build_date_tag = "<string>%s</string>" % match[0][1]
                keyword_map = { build_date_tag : "<string>%s</string>" % build_date }
                self.replace_keyword_with_file(info_plist_path, keyword_map)

        if utils_cocos.os_is_win32():
            # win32
            game_rc_path = os.path.join(self.simulator_abs_path,"frameworks/runtime-src/proj.win32/game.rc")
            game_rc_content = self.get_content_from_file(game_rc_path)
            match = re.compile('"Version[^\(]*\(.*\)"').findall(game_rc_content)
            if len(match):
                build_info_str = match[0]
                m = re.match(r'"(Version[^\(]*)\(.*\)', build_info_str)
                target_str = '"%s(%s)"' % (m.group(1), build_date)
                keyword_map = { build_info_str : target_str}
                self.replace_keyword_with_file(game_rc_path,keyword_map)
Exemplo n.º 2
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.º 3
0
    def update_bundle_version(self):
        build_date = date.today().strftime("%Y%m%d")

        if utils_cocos.os_is_mac():
            # mac
            info_plist_path = os.path.join(
                self.simulator_abs_path,
                "frameworks/runtime-src/proj.ios_mac/mac/Info.plist")
            info_plist_content = self.get_content_from_file(info_plist_path)

            match = re.compile(
                '<key>CFBundleVersion</key>(\s)*<string>(.*?)</string>'
            ).findall(info_plist_content)
            if len(match):
                build_date_tag = "<string>%s</string>" % match[0][1]
                keyword_map = {
                    build_date_tag: "<string>%s</string>" % build_date
                }
                self.replace_keyword_with_file(info_plist_path, keyword_map)

        if utils_cocos.os_is_win32():
            # win32
            game_rc_path = os.path.join(
                self.simulator_abs_path,
                "frameworks/runtime-src/proj.win32/game.rc")
            game_rc_content = self.get_content_from_file(game_rc_path)
            match = re.compile('"Version[^\(]*\(.*\)"').findall(
                game_rc_content)
            if len(match):
                build_info_str = match[0]
                m = re.match(r'"(Version[^\(]*)\(.*\)', build_info_str)
                target_str = '"%s(%s)"' % (m.group(1), build_date)
                keyword_map = {build_info_str: target_str}
                self.replace_keyword_with_file(game_rc_path, keyword_map)
Exemplo n.º 4
0
    def do_compile(self):
        if self.platform == 'all':
            self.compile_all()
            return

        if utils_cocos.os_is_mac():
            support_platforms = SimulatorCompiler.SUPPORT_PLATFORMS['mac']
        elif utils_cocos.os_is_win32():
            support_platforms = SimulatorCompiler.SUPPORT_PLATFORMS['win']
        else:
            support_platforms = SimulatorCompiler.SUPPORT_PLATFORMS['other']

        if self.platform not in support_platforms:
            raise CustomError(
                '%s is not support in current system.' % self.platform,
                CustomError.ERROR_WRONG_ARGS)

        if self.platform == 'win32':
            self.compile_for_win32()
        elif self.platform == 'android':
            self.compile_for_android()
        elif self.platform == 'ios':
            self.compile_for_ios()
        elif self.platform == 'mac':
            self.compile_for_osx()
Exemplo n.º 5
0
 def compile_all(self):
     if utils_cocos.os_is_mac():
         self.compile_for_android()
         self.compile_for_osx()
         self.compile_for_ios()
     elif utils_cocos.os_is_win32():
         self.compile_for_win32()
         self.compile_for_android()
Exemplo n.º 6
0
 def compile_all(self):
     if utils_cocos.os_is_mac():
         self.compile_for_android()
         self.compile_for_osx()
         self.compile_for_ios()
     elif utils_cocos.os_is_win32():
         self.compile_for_win32()
         self.compile_for_android()
Exemplo n.º 7
0
    def get_depend_project_file_list(self):
        file_list = []

        if utils_cocos.os_is_mac():
            IOS_MAC_PROJECT_SUFFIX = "project.pbxproj"
            IOS_MAC_PROJECT_REFERENCES_TAG = 'ProjectRef ='
            IOS_MAC_PROJECT_NAME_RE = r'\w+.xcodeproj'
            IOS_MAC_PROJECT_PATH_RE = r'name = %s; path = (.)*.xcodeproj'

            project_file_path = os.path.join(
                self.simulator_abs_path,
                "frameworks/runtime-src/proj.ios_mac/simulator.xcodeproj",
                IOS_MAC_PROJECT_SUFFIX)
            contents_str = self.get_content_from_file(project_file_path)
            lines = re.split(r'\n', contents_str)

            simulator_mac_project_path = os.path.dirname(
                os.path.dirname(project_file_path))
            project_references = []
            for l in lines:
                if IOS_MAC_PROJECT_REFERENCES_TAG in l:
                    ret = re.search(IOS_MAC_PROJECT_NAME_RE, l)
                    if ret: project_references.append(ret.group(0))

            for references in project_references:
                re_str = IOS_MAC_PROJECT_PATH_RE % references
                ret = re.search(re_str, contents_str)
                if ret:
                    match_str = ret.group(0)
                    match_str = match_str.replace(
                        "name = %s; path = " % references, "")
                    match_str = match_str.replace('"', "")
                    file_list.append(
                        os.path.join(simulator_mac_project_path, match_str,
                                     IOS_MAC_PROJECT_SUFFIX))

        elif utils_cocos.os_is_win32():
            WIN32_PROJECT_TAG = "Project(\""
            project_file_path = os.path.join(
                self.simulator_abs_path,
                "frameworks/runtime-src/proj.win32/simulator.sln")
            simulator_win32_project_path = os.path.dirname(project_file_path)

            content_str = self.get_content_from_file(project_file_path)
            lines = content_str.split('\n')
            for l in lines:
                if l.startswith(WIN32_PROJECT_TAG):
                    ret = re.compile('"(.*?)"').findall(l.split(',')[1])
                    if ret:
                        path = self.convert_path_to_win32(
                            os.path.join(simulator_win32_project_path, ret[0]))
                        file_list.append(path)

        return file_list
Exemplo n.º 8
0
    def convert_path_to_python(self,path):
        """ Convert path which include space to correct style which python can treat correctly.

            eg: on mac: convert '/usr/xxx/apache-ant\ 1.9.3' to '/usr/xxx/apache-ant 1.9.3'
            eg: on windows: convert '"c:\apache-ant 1.9.3"\bin' to 'c:\apache-ant 1.9.3\bin'
        """
        ret = path
        if utils_cocos.os_is_mac():
            ret = path.replace("\ ", " ")

        if utils_cocos.os_is_win32():
            ret = ret.replace("\"", "")

        return ret
Exemplo n.º 9
0
    def trip_libs(self, strip_cmd, folder):
        if not os.path.isdir(folder):
            return

        if utils_cocos.os_is_win32():
            for name in os.listdir(folder):
                basename, ext = os.path.splitext(name)
                if ext == ".a":
                    full_name = os.path.join(folder, name)
                    command = "%s -S %s" % (strip_cmd, full_name)
                    utils_cocos.execute_command(command)
        else:
            strip_cmd = "%s -S %s/*.a" % (strip_cmd, folder)
            utils_cocos.execute_command(strip_cmd)
Exemplo n.º 10
0
    def convert_path_to_python(self, path):
        """ Convert path which include space to correct style which python can treat correctly.

            eg: on mac: convert '/usr/xxx/apache-ant\ 1.9.3' to '/usr/xxx/apache-ant 1.9.3'
            eg: on windows: convert '"c:\apache-ant 1.9.3"\bin' to 'c:\apache-ant 1.9.3\bin'
        """
        ret = path
        if utils_cocos.os_is_mac():
            ret = path.replace("\ ", " ")

        if utils_cocos.os_is_win32():
            ret = ret.replace("\"", "")

        return ret
Exemplo n.º 11
0
    def trip_libs(self, strip_cmd, folder):
        if not os.path.isdir(folder):
            return

        if utils_cocos.os_is_win32():
            for name in os.listdir(folder):
                basename, ext = os.path.splitext(name)
                if ext == ".a":
                    full_name = os.path.join(folder, name)
                    command = "%s -S %s" % (strip_cmd, full_name)
                    utils_cocos.execute_command(command)
        else:
            strip_cmd = "%s -S %s/*.a" % (strip_cmd, folder)
            utils_cocos.execute_command(strip_cmd)
Exemplo n.º 12
0
    def get_depend_project_file_list(self):
        file_list = []

        if utils_cocos.os_is_mac():
            IOS_MAC_PROJECT_SUFFIX = "project.pbxproj"
            IOS_MAC_PROJECT_REFERENCES_TAG = 'ProjectRef ='
            IOS_MAC_PROJECT_NAME_RE = r'\w+.xcodeproj'
            IOS_MAC_PROJECT_PATH_RE = r'name = %s; path = (.)*.xcodeproj'

            project_file_path = os.path.join(self.simulator_abs_path,
                                            "frameworks/runtime-src/proj.ios_mac/simulator.xcodeproj",
                                            IOS_MAC_PROJECT_SUFFIX)
            contents_str = self.get_content_from_file(project_file_path)
            lines = re.split(r'\n', contents_str)

            simulator_mac_project_path = os.path.dirname(os.path.dirname(project_file_path))
            project_references = []
            for l in lines:
                if IOS_MAC_PROJECT_REFERENCES_TAG in l:
                    ret = re.search(IOS_MAC_PROJECT_NAME_RE, l)
                    if ret: project_references.append(ret.group(0))

            for references in project_references:
                re_str = IOS_MAC_PROJECT_PATH_RE % references
                ret = re.search(re_str, contents_str)
                if ret:
                    match_str = ret.group(0)
                    match_str = match_str.replace("name = %s; path = " % references, "")
                    match_str = match_str.replace('"', "")
                    file_list.append(os.path.join(simulator_mac_project_path, match_str, IOS_MAC_PROJECT_SUFFIX))

        elif utils_cocos.os_is_win32():
            WIN32_PROJECT_TAG = "Project(\""
            project_file_path = os.path.join(self.simulator_abs_path, "frameworks/runtime-src/proj.win32/simulator.sln")
            simulator_win32_project_path = os.path.dirname(project_file_path)

            content_str = self.get_content_from_file(project_file_path)
            lines = content_str.split('\n')
            for l in lines:
                if l.startswith(WIN32_PROJECT_TAG):
                    ret = re.compile('"(.*?)"').findall(l.split(',')[1])
                    if ret:
                        path = self.convert_path_to_win32(os.path.join(simulator_win32_project_path, ret[0]))
                        file_list.append(path)

        return file_list
Exemplo n.º 13
0
    def get_keywords(self):
        osx_keyword = {
            "CC_TARGET_OS_IPHONE,":"CC_TARGET_OS_IPHONE,\n\"COCOS2D_DEBUG=1\",",
            "CC_TARGET_OS_MAC,":"CC_TARGET_OS_MAC,\n\"COCOS2D_DEBUG=1\",",
            "COCOS2D_DEBUG=0":"COCOS2D_DEBUG=1",
        }

        win_keyword = {
            "_WINDOWS":"_WINDOWS;COCOS2D_DEBUG=1",
        }

        if utils_cocos.os_is_mac():
            return osx_keyword
        if utils_cocos.os_is_win32():
            return win_keyword

        return {}
Exemplo n.º 14
0
    def get_keywords(self):
        osx_keyword = {
            "CC_TARGET_OS_IPHONE,":
            "CC_TARGET_OS_IPHONE,\n\"COCOS2D_DEBUG=1\",",
            "CC_TARGET_OS_MAC,": "CC_TARGET_OS_MAC,\n\"COCOS2D_DEBUG=1\",",
            "COCOS2D_DEBUG=0": "COCOS2D_DEBUG=1",
        }

        win_keyword = {
            "_WINDOWS": "_WINDOWS;COCOS2D_DEBUG=1",
        }

        if utils_cocos.os_is_mac():
            return osx_keyword
        if utils_cocos.os_is_win32():
            return win_keyword

        return {}
Exemplo n.º 15
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.º 16
0
    def do_compile(self):
        if self.platform == 'all':
            self.compile_all()
            return

        if utils_cocos.os_is_mac():
            support_platforms = SimulatorCompiler.SUPPORT_PLATFORMS['mac']
        elif utils_cocos.os_is_win32():
            support_platforms = SimulatorCompiler.SUPPORT_PLATFORMS['win']
        else:
            support_platforms = SimulatorCompiler.SUPPORT_PLATFORMS['other']

        if self.platform not in support_platforms:
            raise CustomError('%s is not support in current system.' % self.platform,
                              CustomError.ERROR_WRONG_ARGS)

        if self.platform == 'win32':
            self.compile_for_win32()
        elif self.platform == 'android':
            self.compile_for_android()
        elif self.platform == 'ios':
            self.compile_for_ios()
        elif self.platform == 'mac':
            self.compile_for_osx()
Exemplo n.º 17
0
    def compile_win(self):
        if not utils_cocos.os_is_win32():
            print("this is not win platform, needn't compile")
            return

        # get the VS versions will be used for compiling
        support_vs_versions = self.cfg_info[CocosLibsCompiler.KEY_SUPPORT_VS_VERSIONS]
        compile_vs_versions = support_vs_versions
        if self.vs_version is not None:
            if self.vs_version not in support_vs_versions:
                raise CustomError('Not support VS%d' % self.vs_version)
            else:
                compile_vs_versions = [ self.vs_version ]

        vs_cmd_info = {}
        for vs_version in compile_vs_versions:
            # get the vs command with specified version
            vs_command = utils_cocos.get_vs_cmd_path(vs_version)
            if vs_command is None:
                Logging.warning('Not found VS%d' % vs_version)
            else:
                vs_cmd_info[vs_version] = vs_command

        if len(vs_cmd_info) == 0:
            raise CustomError('Not found available VS.', CustomError.ERROR_TOOLS_NOT_FOUND)

        cocos2d_proj_file = os.path.join(self.repo_x, 'cocos/2d/libcocos2d.vcxproj')

        # get the VS projects info
        win32_proj_info = self.cfg_info[CocosLibsCompiler.KEY_VS_PROJS_INFO]
        for vs_version in compile_vs_versions:
            if not vs_version in vs_cmd_info.keys():
                continue

            # rename the cocos2d project out dll name
            f = open(cocos2d_proj_file, 'r')
            old_file_content = f.read()
            f.close()

            new_file_content = old_file_content.replace('$(OutDir)$(ProjectName).dll', '$(OutDir)$(ProjectName)_%d.dll' % vs_version)
            f = open(cocos2d_proj_file, 'w')
            f.write(new_file_content)
            f.close()

            try:
                vs_command = vs_cmd_info[vs_version]
                for key in win32_proj_info.keys():
                    # clean solutions
                    proj_path = os.path.join(self.repo_x, key)
                    clean_cmd = " ".join([
                        "\"%s\"" % vs_command,
                        "\"%s\"" % proj_path,
                        "/t:Clean /p:Configuration=Release"
                    ])
                    utils_cocos.execute_command(clean_cmd)

                for key in win32_proj_info.keys():
                    output_dir = os.path.join(self.lib_dir, "win32")
                    proj_path = os.path.join(self.repo_x, key)

                    # get the build folder & win32 output folder
                    build_folder_path = os.path.join(os.path.dirname(proj_path), "Release.win32")
                    win32_output_dir = os.path.join(self.repo_x, output_dir)
                    if not os.path.exists(win32_output_dir):
                        os.makedirs(win32_output_dir)

                    # build project
                    if self.use_incredibuild:
                        # use incredibuild, build whole sln
                        build_cmd = " ".join([
                            "BuildConsole",
                            "%s" % proj_path,
                            "/build",
                            "/cfg=\"Release|Win32\""
                        ])
                        utils_cocos.execute_command(build_cmd)
                    else:
                        for proj_name in win32_proj_info[key][CocosLibsCompiler.KEY_VS_BUILD_TARGETS]:
                            # build the projects
                            self.build_win32_proj(vs_command, proj_path, proj_name)

                    # copy the libs into prebuilt dir
                    for file_name in os.listdir(build_folder_path):
                        name, ext = os.path.splitext(file_name)
                        if ext != ".lib" and ext != ".dll":
                            continue

                        file_path = os.path.join(build_folder_path, file_name)
                        shutil.copy(file_path, win32_output_dir)

                    # rename the specified libs
                    suffix = "_%d" % vs_version
                    for proj_name in win32_proj_info[key][CocosLibsCompiler.KEY_VS_RENAME_TARGETS]:
                        src_name = os.path.join(win32_output_dir, "%s.lib" % proj_name)
                        dst_name = os.path.join(win32_output_dir, "%s%s.lib" % (proj_name, suffix))
                        if not os.path.exists(src_name):
                            raise Exception("Library %s not generated as expected!" % src_name)

                        if os.path.exists(dst_name):
                            os.remove(dst_name)
                        os.rename(src_name, dst_name)
            except Exception as e:
                raise e
            finally:
                f = open(cocos2d_proj_file, 'w')
                f.write(old_file_content)
                f.close()


        print("Win32 build succeeded.")
Exemplo n.º 18
0
    def compile_android(self):
        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")

        # build the simulator project
        proj_path = os.path.join(engine_dir, 'tools/simulator')
        build_cmd = "%s compile -s %s -p android --ndk-mode release --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'))
Exemplo n.º 19
0
    def compile_win(self):
        if not utils_cocos.os_is_win32():
            print("this is not win platform, needn't compile")
            return

        # get the VS versions will be used for compiling
        support_vs_versions = self.cfg_info[
            CocosLibsCompiler.KEY_SUPPORT_VS_VERSIONS]
        compile_vs_versions = support_vs_versions
        if self.vs_version is not None:
            if self.vs_version not in support_vs_versions:
                raise CustomError('Not support VS%d' % self.vs_version)
            else:
                compile_vs_versions = [self.vs_version]

        vs_cmd_info = {}
        for vs_version in compile_vs_versions:
            # get the vs command with specified version
            vs_command = utils_cocos.get_vs_cmd_path(vs_version)
            if vs_command is None:
                Logging.warning('Not found VS%d' % vs_version)
            else:
                vs_cmd_info[vs_version] = vs_command

        if len(vs_cmd_info) == 0:
            raise CustomError('Not found available VS.',
                              CustomError.ERROR_TOOLS_NOT_FOUND)

        cocos2d_proj_file = os.path.join(self.repo_x,
                                         'cocos/2d/libcocos2d.vcxproj')

        # get the VS projects info
        win32_proj_info = self.cfg_info[CocosLibsCompiler.KEY_VS_PROJS_INFO]
        for vs_version in compile_vs_versions:
            if not vs_version in vs_cmd_info.keys():
                continue

            # rename the cocos2d project out dll name
            f = open(cocos2d_proj_file, 'r')
            old_file_content = f.read()
            f.close()

            new_file_content = old_file_content.replace(
                '$(OutDir)$(ProjectName).dll',
                '$(OutDir)$(ProjectName)_%d.dll' % vs_version)
            f = open(cocos2d_proj_file, 'w')
            f.write(new_file_content)
            f.close()

            try:
                vs_command = vs_cmd_info[vs_version]
                for key in win32_proj_info.keys():
                    # clean solutions
                    proj_path = os.path.join(self.repo_x, key)
                    clean_cmd = " ".join([
                        "\"%s\"" % vs_command,
                        "\"%s\"" % proj_path, "/clean \"Release|Win32\""
                    ])
                    utils_cocos.execute_command(clean_cmd)

                for key in win32_proj_info.keys():
                    output_dir = os.path.join(self.lib_dir, "win32")
                    proj_path = os.path.join(self.repo_x, key)

                    # get the build folder & win32 output folder
                    build_folder_path = os.path.join(
                        os.path.dirname(proj_path), "Release.win32")
                    win32_output_dir = os.path.join(self.repo_x, output_dir)
                    if not os.path.exists(win32_output_dir):
                        os.makedirs(win32_output_dir)

                    # build project
                    if self.use_incredibuild:
                        # use incredibuild, build whole sln
                        build_cmd = " ".join([
                            "BuildConsole",
                            "%s" % proj_path, "/build",
                            "/cfg=\"Release|Win32\""
                        ])
                        utils_cocos.execute_command(build_cmd)
                    else:
                        for proj_name in win32_proj_info[key][
                                CocosLibsCompiler.KEY_VS_BUILD_TARGETS]:
                            # build the projects
                            self.build_win32_proj(vs_command, proj_path,
                                                  proj_name, "build")

                            lib_file_path = os.path.join(
                                build_folder_path, "%s.lib" % proj_name)
                            if not os.path.exists(lib_file_path):
                                # if the lib is not generated, rebuild the project
                                self.build_win32_proj(vs_command, proj_path,
                                                      proj_name, "rebuild")

                            if not os.path.exists(lib_file_path):
                                raise Exception(
                                    "Library %s not generated as expected!" %
                                    lib_file_path)

                    # copy the libs into prebuilt dir
                    for file_name in os.listdir(build_folder_path):
                        name, ext = os.path.splitext(file_name)
                        if ext != ".lib" and ext != ".dll":
                            continue

                        file_path = os.path.join(build_folder_path, file_name)
                        shutil.copy(file_path, win32_output_dir)

                    # rename the specified libs
                    suffix = "_%d" % vs_version
                    for proj_name in win32_proj_info[key][
                            CocosLibsCompiler.KEY_VS_RENAME_TARGETS]:
                        src_name = os.path.join(win32_output_dir,
                                                "%s.lib" % proj_name)
                        dst_name = os.path.join(
                            win32_output_dir, "%s%s.lib" % (proj_name, suffix))
                        if os.path.exists(src_name):
                            if os.path.exists(dst_name):
                                os.remove(dst_name)
                            os.rename(src_name, dst_name)
            except Exception as e:
                raise e
            finally:
                f = open(cocos2d_proj_file, 'w')
                f.write(old_file_content)
                f.close()

        print("Win32 build succeeded.")
Exemplo n.º 20
0
    def compile_android(self):
        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")

        # build the simulator project
        proj_path = os.path.join(engine_dir, 'tools/simulator')
        build_cmd = "%s compile -s %s -p android --ndk-mode release --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'))