Ejemplo n.º 1
0
    def write_content_to_file(self,content, file_path):
        if not os.path.isfile(file_path):
            raise CCPluginError(MultiLanguage.get_string('GEN_SIM_ERROR_FILE_NOT_FOUND_FMT', file_path),
                                CCPluginError.ERROR_PATH_NOT_FOUND)

        with open(file_path, 'w') as f:
            f.write(content)
Ejemplo n.º 2
0
    def get_content_from_file(self,file_path):
        if not os.path.isfile(file_path):
            raise CCPluginError(MultiLanguage.get_string('GEN_SIM_ERROR_FILE_NOT_FOUND_FMT', file_path),
                                CCPluginError.ERROR_PATH_NOT_FOUND)

        with open(file_path) as f:
            return f.read()
Ejemplo n.º 3
0
    def init(self, args):
        if getattr(sys, 'frozen', None):
            self.cur_dir = os.path.realpath(os.path.dirname(sys.executable))
            self.default_engine_path = os.path.join(self.cur_dir, os.pardir, os.pardir, os.pardir)
        else:
            self.cur_dir = os.path.realpath(os.path.dirname(__file__))
            self.default_engine_path = os.path.join(self.cur_dir, os.pardir, os.pardir, os.pardir, os.pardir)
        self.default_engine_path = os.path.normpath(self.default_engine_path)

        if args.engine_path is None:
            self.repo_x = self.default_engine_path
        else:
            engine_path = os.path.expanduser(args.engine_path)
            if os.path.isabs(engine_path):
                self.repo_x = os.path.normpath(engine_path)
            else:
                self.repo_x = os.path.normpath(os.path.abspath(engine_path))

        if not os.path.isdir(self.repo_x):
            raise CCPluginError(MultiLanguage.get_string('GEN_LIBS_ERROR_WRONG_PATH_FMT', self.repo_x),
                                CCPluginError.ERROR_WRONG_ARGS)

        self.cfg_file_path = os.path.join(self.cur_dir, LibsCompiler.CFG_FILE)
        self.parse_config()

        # arguments check and set
        self.clean = args.clean
        self.mode = args.compile_mode
        self._verbose = True

        if args.platform is None:
            self.build_ios = True
            self.build_mac = True
            self.build_win = True
            self.build_android = True
        else:
            self.build_ios = False
            self.build_mac = False
            self.build_win = False
            self.build_android = False
            if 'win32' in args.platform:
                self.build_win = True
            if 'ios' in args.platform:
                self.build_ios = True
            if 'mac' in args.platform:
                self.build_mac = True
            if 'android' in args.platform:
                self.build_android = True

        self.disable_strip = args.disable_strip
        self.vs_version = args.vs_version
        self.use_incredibuild = False
        if args.app_abi is None:
            self.app_abi = 'armeabi'
        else:
            self.app_abi = args.app_abi
        self.android_platform = args.android_platform

        self.lib_dir = os.path.normpath(os.path.join(self.repo_x, self.cfg_info[LibsCompiler.KEY_LIBS_OUTPUT]))
Ejemplo n.º 4
0
    def parse_config(self):
        if not os.path.isfile(self.cfg_file_path):
            raise CCPluginError(MultiLanguage.get_string('GEN_LIBS_ERROR_WRONG_FILE_FMT', self.cfg_file_path),
                                CCPluginError.ERROR_PATH_NOT_FOUND)

        try:
            f = open(self.cfg_file_path)
            self.cfg_info = json.load(f)
            f.close()
        except:
            raise CCPluginError(MultiLanguage.get_string('GEN_LIBS_ERROR_PARSE_FILE_FMT', self.cfg_file_path),
                                CCPluginError.ERROR_PARSE_FILE)

        for k in LibsCompiler.CHECK_KEYS:
            if k not in self.cfg_info.keys():
                raise CCPluginError(MultiLanguage.get_string('GEN_LIBS_ERROR_KEY_NOT_FOUND_FMT', (k, self.cfg_file_path)),
                                    CCPluginError.ERROR_WRONG_CONFIG)
Ejemplo n.º 5
0
    def get_version_from_source(self):
        src_engine_path = self.engine_path
        version_file_path = os.path.join(src_engine_path, "cocos/cocos2d.cpp")
        pattern = r".*return[ \t]+\"(.*)\";"

        # restore the version of engine
        ver = ""
        f = open(version_file_path)
        for line in f.readlines():
            match = re.match(pattern, line)
            if match:
                ver = match.group(1)
                break
        f.close()

        if len(ver) <= 0:
            raise CCPluginError(MultiLanguage.get_string('GEN_TEMP_ERROR_VER_NOT_FOUND_FMT', version_file_path),
                                CCPluginError.ERROR_PARSE_FILE)

        return ver
Ejemplo n.º 6
0
    def compile_win(self):
        if self.mode == 'debug':
            mode_str = 'Debug'
        else:
            mode_str = 'Release'

        # get the VS versions will be used for compiling
        support_vs_versions = self.cfg_info[
            LibsCompiler.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 CCPluginError(
                    MultiLanguage.get_string(
                        'GEN_LIBS_ERROR_NOT_SUPPORT_VS_FMT', self.vs_version),
                    CCPluginError.ERROR_WRONG_ARGS)
            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.get_msbuild_path(vs_version)
            if vs_command is None:
                Logging.warning(
                    MultiLanguage.get_string(
                        'GEN_LIBS_WARNING_VS_NOT_FOUND_FMT', vs_version))
            else:
                vs_cmd_info[vs_version] = vs_command

        if len(vs_cmd_info) == 0:
            raise CCPluginError(
                MultiLanguage.get_string('GEN_LIBS_ERROR_VS_NOT_FOUND'),
                CCPluginError.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[LibsCompiler.KEY_VS_PROJS_INFO]
        proj_path = win32_proj_info['proj_path']
        for vs_version in compile_vs_versions:
            if not vs_version in vs_cmd_info.keys():
                continue

            try:
                vs_command = vs_cmd_info[vs_version]
                # clean solutions
                full_proj_path = os.path.join(self.repo_x, proj_path)
                clean_cmd = " ".join([
                    "\"%s\"" % vs_command,
                    "\"%s\"" % full_proj_path,
                    "/t:Clean /p:Configuration=%s" % mode_str
                ])
                self._run_cmd(clean_cmd)

                output_dir = os.path.join(self.lib_dir, "win32")

                # get the build folder & win32 output folder
                build_folder_path = os.path.join(os.path.dirname(proj_path),
                                                 "%s.win32" % mode_str)
                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=\"%s|Win32\"" % mode_str
                    ])
                    self._run_cmd(build_cmd)
                else:
                    for proj_name in win32_proj_info[self.language][
                            LibsCompiler.KEY_VS_BUILD_TARGETS]:
                        # build the projects
                        self.build_win32_proj(vs_command, proj_path, proj_name,
                                              mode_str)

                # 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)

            except Exception as e:
                raise e
Ejemplo n.º 7
0
    def compile_win(self):
        if self.mode == 'debug':
            mode_str = 'Debug'
        else:
            mode_str = 'Release'

        # get the VS versions will be used for compiling
        support_vs_versions = self.cfg_info[
            LibsCompiler.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 CCPluginError(
                    MultiLanguage.get_string(
                        'GEN_LIBS_ERROR_NOT_SUPPORT_VS_FMT', self.vs_version),
                    CCPluginError.ERROR_WRONG_ARGS)
            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.get_msbuild_path(vs_version)
            if vs_command is None:
                Logging.warning(
                    MultiLanguage.get_string(
                        'GEN_LIBS_WARNING_VS_NOT_FOUND_FMT', vs_version))
            else:
                vs_cmd_info[vs_version] = vs_command

        if len(vs_cmd_info) == 0:
            raise CCPluginError(
                MultiLanguage.get_string('GEN_LIBS_ERROR_VS_NOT_FOUND'),
                CCPluginError.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[LibsCompiler.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=%s" % mode_str
                    ])
                    self._run_cmd(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), "%s.win32" % mode_str)
                    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=\"%s|Win32\"" % mode_str
                        ])
                        self._run_cmd(build_cmd)
                    else:
                        for proj_name in win32_proj_info[key][
                                LibsCompiler.KEY_VS_BUILD_TARGETS]:
                            # build the projects
                            self.build_win32_proj(vs_command, proj_path,
                                                  proj_name, mode_str)

                    # 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][
                            LibsCompiler.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 CCPluginError(
                                MultiLanguage.get_string(
                                    'GEN_LIBS_ERROR_LIB_NOT_GEN_FMT',
                                    src_name),
                                CCPluginError.ERROR_PATH_NOT_FOUND)

                        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()
Ejemplo n.º 8
0
    def init(self, args):
        if getattr(sys, 'frozen', None):
            self.cur_dir = os.path.realpath(os.path.dirname(sys.executable))
            self.default_engine_path = os.path.join(self.cur_dir, os.pardir, os.pardir, os.pardir)
        else:
            self.cur_dir = os.path.realpath(os.path.dirname(__file__))
            self.default_engine_path = os.path.join(self.cur_dir, os.pardir, os.pardir, os.pardir, os.pardir)
        self.default_engine_path = os.path.normpath(self.default_engine_path)

        if args.engine_path is None:
            self.engine_root = self.default_engine_path
        else:
            engine_path = os.path.expanduser(args.engine_path)
            if os.path.isabs(engine_path):
                self.engine_root = os.path.normpath(engine_path)
            else:
                self.engine_root = os.path.normpath(os.path.abspath(engine_path))

        if not os.path.isdir(self.engine_root):
            raise CCPluginError(MultiLanguage.get_string('GEN_SIM_ERROR_WRONG_PATH_FMT', self.engine_root),
                                CCPluginError.ERROR_WRONG_ARGS)

        self.simulator_abs_path = os.path.join(self.engine_root, SimulatorCompiler.SIMULATOR_PROJ_PATH)
        self.cocos_bin = os.path.join(self.engine_root, SimulatorCompiler.COCOS_CMD_PATH)
        engine_version = utils.get_engine_version(self.engine_root)
        # get the short version after "cocos2d-x-"
        self.engine_version = engine_version[10:]

        # get the full path of output dir.
        if args.out_dir is None:
            self.simulator_output_dir = os.path.join(self.engine_root, SimulatorCompiler.DEFAULT_OUTPUT_FOLDER_NAME)
        else:
            out_dir = os.path.expanduser(args.out_dir)
            if os.path.isabs(out_dir):
                self.simulator_output_dir = os.path.normpath(out_dir)
            else:
                self.simulator_output_dir = os.path.normpath(os.path.abspath(out_dir))

        # get arguments
        self.is_clean_before_build = args.do_clean
        if args.compile_mode is None:
            self.mode = 'debug'
        else:
            self.mode = args.compile_mode

        if args.platform is None:
            self.build_ios = True
            self.build_mac = True
            self.build_win = True
            self.build_android = True
        else:
            self.build_ios = False
            self.build_mac = False
            self.build_win = False
            self.build_android = False
            if 'win32' in args.platform:
                self.build_win = True
            if 'ios' in args.platform:
                self.build_ios = True
            if 'mac' in args.platform:
                self.build_mac = True
            if 'android' in args.platform:
                self.build_android = True

        self.build_log = ""
        self.vs_version = args.vs_version
        self._verbose = True