예제 #1
0
    def find_xap_deploy_tool(self):
        import _winreg
        import re
        if cocos.os_is_32bit_windows():
            reg_flag_list = [_winreg.KEY_WOW64_32KEY]
        else:
            reg_flag_list = [_winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY]

        pattern = re.compile(r"v(\d+).(\d+)")
        find_ret = None
        find_major = -1
        find_minor = -1
        for reg_flag in reg_flag_list:
            cocos.Logging.info(
                MultiLanguage.get_string(
                    'DEPLOY_INFO_FIND_XAP_FMT',
                    ("32bit"
                     if reg_flag == _winreg.KEY_WOW64_32KEY else "64bit")))
            try:
                wp = _winreg.OpenKey(
                    _winreg.HKEY_LOCAL_MACHINE,
                    r"SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone", 0,
                    _winreg.KEY_READ | reg_flag)
            except:
                # windows phone not found, continue
                continue

            i = 0
            while True:
                try:
                    version = _winreg.EnumKey(wp, i)
                except:
                    break

                i += 1
                match = re.match(pattern, version)
                if match:
                    major = int(match.group(1))
                    minor = int(match.group(2))
                    if major > 7:
                        try:
                            key = _winreg.OpenKey(wp,
                                                  "%s\Install Path" % version)
                            value, type = _winreg.QueryValueEx(
                                key, "Install Path")
                            tool_path = os.path.join(value, "Tools",
                                                     "XAP Deployment",
                                                     "XapDeployCmd.exe")
                            if os.path.isfile(tool_path):
                                if (find_ret is
                                        None) or (major > find_major) or (
                                            major == find_major
                                            and minor > find_minor):
                                    find_ret = tool_path
                                    find_major = major
                                    find_minor = minor
                        except:
                            pass

        return find_ret
예제 #2
0
def get_devenv_path(vs_version):
    if cocos.os_is_win32():
        import _winreg
    else:
        return None

    if isinstance(vs_version, int):
        # The value of vs_version is int. such as : 2013, 2015
        if vs_version in VS_VERSION_MAP.keys():
            vs_ver = VS_VERSION_MAP[vs_version]
        else:
            # not supported VS version
            return None
    elif isinstance(vs_version, str):
        # The value of vs_version is string. such as: "12.0", "14.0"
        vs_ver = vs_version
    else:
        return None

    # If the system is 64bit, find VS in both 32bit & 64bit registry
    # If the system is 32bit, only find VS in 32bit registry
    if cocos.os_is_32bit_windows():
        reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
    else:
        reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]

    devenv_path = None
    for reg_flag in reg_flag_list:
        try:
            vs = _winreg.OpenKey(
                _winreg.HKEY_LOCAL_MACHINE,
                r"SOFTWARE\Microsoft\VisualStudio",
                0,
                _winreg.KEY_READ | reg_flag
            )
        except:
            continue

        # find specified VS
        try:
            key = _winreg.OpenKey(vs, r"SxS\VS7")
            devenv_path, type = _winreg.QueryValueEx(key, vs_ver)
        except:
            pass

        if devenv_path is not None:
            devenv_path = os.path.join(devenv_path, "Common7", "IDE", "devenv.com")
            if os.path.exists(devenv_path):
                break
            else:
                devenv_path = None

    return devenv_path
예제 #3
0
def get_devenv_path(vs_version):
    if cocos.os_is_win32():
        import _winreg
    else:
        return None

    if isinstance(vs_version, int):
        # The value of vs_version is int. such as : 2013, 2015
        if vs_version in VS_VERSION_MAP.keys():
            vs_ver = VS_VERSION_MAP[vs_version]
        else:
            # not supported VS version
            return None
    elif isinstance(vs_version, str):
        # The value of vs_version is string. such as: "12.0", "14.0"
        vs_ver = vs_version
    else:
        return None

    # If the system is 64bit, find VS in both 32bit & 64bit registry
    # If the system is 32bit, only find VS in 32bit registry
    if cocos.os_is_32bit_windows():
        reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
    else:
        reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]

    devenv_path = None
    for reg_flag in reg_flag_list:
        try:
            vs = _winreg.OpenKey(
                _winreg.HKEY_LOCAL_MACHINE,
                r"SOFTWARE\Microsoft\VisualStudio",
                0,
                _winreg.KEY_READ | reg_flag
            )
        except:
            continue

        # find specified VS
        try:
            key = _winreg.OpenKey(vs, r"SxS\VS7")
            devenv_path, type = _winreg.QueryValueEx(key, vs_ver)
        except:
            pass

        if devenv_path is not None:
            devenv_path = os.path.join(devenv_path, "Common7", "IDE", "devenv.com")
            if os.path.exists(devenv_path):
                break
            else:
                devenv_path = None

    return devenv_path
예제 #4
0
    def find_xap_deploy_tool(self):
        import _winreg
        import re
        if cocos.os_is_32bit_windows():
            reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
        else:
            reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]

        pattern = re.compile(r"v(\d+).(\d+)")
        find_ret = None
        find_major = -1
        find_minor = -1
        for reg_flag in reg_flag_list:
            cocos.Logging.info(cocos.MultiLanguage.get_string('DEPLOY_INFO_FIND_XAP_FMT') %
                               ("32bit" if reg_flag == _winreg.KEY_WOW64_32KEY else "64bit"))
            try:
                wp = _winreg.OpenKey(
                    _winreg.HKEY_LOCAL_MACHINE,
                    r"SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone",
                    0,
                    _winreg.KEY_READ | reg_flag
                )
            except:
                # windows phone not found, continue
                continue

            i = 0
            while True:
                try:
                    version = _winreg.EnumKey(wp, i)
                except:
                    break

                i += 1
                match = re.match(pattern, version)
                if match:
                    major = int(match.group(1))
                    minor = int(match.group(2))
                    if major > 7:
                        try:
                            key = _winreg.OpenKey(wp, "%s\Install Path" % version)
                            value, type = _winreg.QueryValueEx(key, "Install Path")
                            tool_path = os.path.join(value, "Tools", "XAP Deployment", "XapDeployCmd.exe")
                            if os.path.isfile(tool_path):
                                if (find_ret is None) or (major > find_major) or (major == find_major and minor > find_minor):
                                    find_ret = tool_path
                                    find_major = major
                                    find_minor = minor
                        except:
                            pass

        return find_ret
예제 #5
0
def get_msbuild_path(vs_version):
    if cocos.os_is_win32():
        import _winreg
    else:
        return None

    if isinstance(vs_version, int):
        # The value of vs_version is int. such as : 2013, 2015
        if vs_version in VS_VERSION_MAP.keys():
            vs_ver = VS_VERSION_MAP[vs_version]
        else:
            # not supported VS version
            return None
    elif isinstance(vs_version, str):
        # The value of vs_version is string. such as: "12.0", "14.0"
        vs_ver = vs_version
    else:
        return None

    # If the system is 64bit, find VS in both 32bit & 64bit registry
    # If the system is 32bit, only find VS in 32bit registry
    if cocos.os_is_32bit_windows():
        reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
    else:
        reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]

    # Find VS path
    msbuild_path = None
    for reg_flag in reg_flag_list:
        try:
            vs = _winreg.OpenKey(
                _winreg.HKEY_LOCAL_MACHINE,
                r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\%s" % vs_ver,
                0,
                _winreg.KEY_READ | reg_flag
            )
            msbuild_path, type = _winreg.QueryValueEx(vs, 'MSBuildToolsPath')
        except:
            continue

        if msbuild_path is not None:
            msbuild_path = os.path.join(msbuild_path, "MSBuild.exe")
            if os.path.exists(msbuild_path):
                break
            else:
                msbuild_path = None

    return msbuild_path
예제 #6
0
def get_msbuild_path(vs_version):
    if cocos.os_is_win32():
        import _winreg
    else:
        return None

    if isinstance(vs_version, int):
        # The value of vs_version is int. such as : 2013, 2015
        if vs_version in VS_VERSION_MAP.keys():
            vs_ver = VS_VERSION_MAP[vs_version]
        else:
            # not supported VS version
            return None
    elif isinstance(vs_version, str):
        # The value of vs_version is string. such as: "12.0", "14.0"
        vs_ver = vs_version
    else:
        return None

    # If the system is 64bit, find VS in both 32bit & 64bit registry
    # If the system is 32bit, only find VS in 32bit registry
    if cocos.os_is_32bit_windows():
        reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
    else:
        reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]

    # Find VS path
    msbuild_path = None
    for reg_flag in reg_flag_list:
        try:
            vs = _winreg.OpenKey(
                _winreg.HKEY_LOCAL_MACHINE,
                r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\%s" % vs_ver,
                0,
                _winreg.KEY_READ | reg_flag
            )
            msbuild_path, type = _winreg.QueryValueEx(vs, 'MSBuildToolsPath')
        except:
            continue

        if msbuild_path is not None:
            msbuild_path = os.path.join(msbuild_path, "MSBuild.exe")
            if os.path.exists(msbuild_path):
                break
            else:
                msbuild_path = None

    return msbuild_path
예제 #7
0
def get_system_info():
    if cocos.os_is_win32():
        ret_str = "windows"
        ret_str += "_%s" % platform.release()
        if cocos.os_is_32bit_windows():
            ret_str += "_%s" % "32bit"
        else:
            ret_str += "_%s" % "64bit"
    elif cocos.os_is_mac():
        ret_str = "mac_%s" % (platform.mac_ver()[0]).replace(".", "_")
    elif cocos.os_is_linux():
        ret_str = "linux_%s" % platform.linux_distribution()[0]
    else:
        ret_str = "unknown"

    return ret_str
예제 #8
0
def get_system_info():
    if cocos.os_is_win32():
        ret_str = "windows"
        ret_str += "_%s" % platform.release()
        if cocos.os_is_32bit_windows():
            ret_str += "_%s" % "32bit"
        else:
            ret_str += "_%s" % "64bit"
    elif cocos.os_is_mac():
        ret_str = "mac_%s" % (platform.mac_ver()[0]).replace('.', '_')
    elif cocos.os_is_linux():
        ret_str = "linux_%s" % platform.linux_distribution()[0]
    else:
        ret_str = "unknown"

    return ret_str
예제 #9
0
def get_vs_versions():
    # Get the VS versions
    ret = []
    if cocos.os_is_win32():
        import _winreg
    else:
        return ret

    # If the system is 64bit, find VS in both 32bit & 64bit registry
    # If the system is 32bit, only find VS in 32bit registry
    if cocos.os_is_32bit_windows():
        reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
    else:
        reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]

    version_pattern = re.compile(r'(\d+)\.(\d+)')
    for reg_flag in reg_flag_list:
        try:
            vs = _winreg.OpenKey(
                _winreg.HKEY_LOCAL_MACHINE,
                r"SOFTWARE\Microsoft\VisualStudio",
                0,
                _winreg.KEY_READ | reg_flag
            )
        except:
            continue

        i = 0
        while True:
            # enum the keys in vs reg
            try:
                version = _winreg.EnumKey(vs, i)
            except:
                break
            i += 1

            match = re.match(version_pattern, version)
            if match is None:
                continue

            ver_str = '%s.%s' % (match.group(1), match.group(2))
            if ver_str not in ret:
                ret.append(ver_str)

    return ret
예제 #10
0
def get_vs_versions():
    # Get the VS versions
    ret = []
    if cocos.os_is_win32():
        import _winreg
    else:
        return ret

    # If the system is 64bit, find VS in both 32bit & 64bit registry
    # If the system is 32bit, only find VS in 32bit registry
    if cocos.os_is_32bit_windows():
        reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
    else:
        reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]

    version_pattern = re.compile(r'(\d+)\.(\d+)')
    for reg_flag in reg_flag_list:
        try:
            vs = _winreg.OpenKey(
                _winreg.HKEY_LOCAL_MACHINE,
                r"SOFTWARE\Microsoft\VisualStudio",
                0,
                _winreg.KEY_READ | reg_flag
            )
        except:
            continue

        i = 0
        while True:
            # enum the keys in vs reg
            try:
                version = _winreg.EnumKey(vs, i)
            except:
                break
            i += 1

            match = re.match(version_pattern, version)
            if match is None:
                continue

            ver_str = '%s.%s' % (match.group(1), match.group(2))
            if ver_str not in ret:
                ret.append(ver_str)

    return ret
예제 #11
0
def get_msbuild_path(vs_version):
    if cocos.os_is_win32():
        import _winreg
    else:
        return None

    if vs_version == 2013:
        vs_ver = "12.0"
    elif vs_version == 2015:
        vs_ver = "14.0"
    else:
        # not supported VS version
        return None

    # If the system is 64bit, find VS in both 32bit & 64bit registry
    # If the system is 32bit, only find VS in 32bit registry
    if cocos.os_is_32bit_windows():
        reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
    else:
        reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]

    # Find VS path
    msbuild_path = None
    for reg_flag in reg_flag_list:
        try:
            vs = _winreg.OpenKey(
                _winreg.HKEY_LOCAL_MACHINE,
                r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\%s" % vs_ver,
                0,
                _winreg.KEY_READ | reg_flag
            )
            msbuild_path, type = _winreg.QueryValueEx(vs, 'MSBuildToolsPath')
        except:
            continue

        if msbuild_path is not None and os.path.exists(msbuild_path):
            break

    # generate msbuild path
    if msbuild_path is not None:
        commandPath = os.path.join(msbuild_path, "MSBuild.exe")
    else:
        commandPath = None

    return commandPath
def get_user_agent():
    ret_str = None
    if cocos.os_is_win32():
        ver_info = sys.getwindowsversion()
        ver_str = '%d.%d' % (ver_info[0], ver_info[1])
        if cocos.os_is_32bit_windows():
            arch_str = "WOW32"
        else:
            arch_str = "WOW64"
        ret_str = "Mozilla/5.0 (Windows NT %s; %s) Chrome/33.0.1750.154 Safari/537.36" % (ver_str, arch_str)
    elif cocos.os_is_mac():
        ver_str = (platform.mac_ver()[0]).replace('.', '_')
        ret_str = "Mozilla/5.0 (Macintosh; Intel Mac OS X %s) Chrome/35.0.1916.153 Safari/537.36" % ver_str
    elif cocos.os_is_linux():
        arch_str = platform.machine()
        ret_str = "Mozilla/5.0 (X11; Linux %s) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1636.0 Safari/537.36" % arch_str

    return ret_str
예제 #13
0
def get_user_agent():
    ret_str = None
    if cocos.os_is_win32():
        ver_info = sys.getwindowsversion()
        ver_str = '%d.%d' % (ver_info[0], ver_info[1])
        if cocos.os_is_32bit_windows():
            arch_str = "WOW32"
        else:
            arch_str = "WOW64"
        ret_str = "Mozilla/5.0 (Windows NT %s; %s) Chrome/33.0.1750.154 Safari/537.36" % (ver_str, arch_str)
    elif cocos.os_is_mac():
        ver_str = (platform.mac_ver()[0]).replace('.', '_')
        ret_str = "Mozilla/5.0 (Macintosh; Intel Mac OS X %s) Chrome/35.0.1916.153 Safari/537.36" % ver_str
    elif cocos.os_is_linux():
        arch_str = platform.machine()
        ret_str = "Mozilla/5.0 (X11; Linux %s) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1636.0 Safari/537.36" % arch_str

    return ret_str
def get_bi_params(events, event_value, multi_events=False, engine_versio=''):
    if cocos.os_is_win32():
        system_str = 'windows'
        ver_info = sys.getwindowsversion()
        ver_str = '%d.%d' % (ver_info[0], ver_info[1])
        if cocos.os_is_32bit_windows():
            arch_str = "_32bit"
        else:
            arch_str = "_64bit"
        system_ver = '%s%s' % (ver_str, arch_str)
    elif cocos.os_is_mac():
        system_str = 'mac'
        system_ver = (platform.mac_ver()[0])
    elif cocos.os_is_linux():
        system_str = 'linux'
        system_ver = platform.machine()
    else:
        system_str = 'unknown'
        system_ver = 'unknown'

    events_param = []
    if multi_events:
        for e in events:
            events_param.append(gen_bi_event(e, event_value))
    else:
        events_param.append(gen_bi_event(events, event_value))

    params = {
        'device': {
            '10' : system_ver,
            '11' : system_str
        },
        'app': {
            '7' : BI_APPID,
            '8' : engine_version,
            '9' : get_language()
        },
        'time' : get_time_stamp(),
        'events' : events_param
    }

    return params
예제 #15
0
def get_bi_params(events, event_value, multi_events=False):
    if cocos.os_is_win32():
        system_str = 'windows'
        ver_info = sys.getwindowsversion()
        ver_str = '%d.%d' % (ver_info[0], ver_info[1])
        if cocos.os_is_32bit_windows():
            arch_str = "_32bit"
        else:
            arch_str = "_64bit"
        system_ver = '%s%s' % (ver_str, arch_str)
    elif cocos.os_is_mac():
        system_str = 'mac'
        system_ver = (platform.mac_ver()[0])
    elif cocos.os_is_linux():
        system_str = 'linux'
        system_ver = platform.machine()
    else:
        system_str = 'unknown'
        system_ver = 'unknown'

    events_param = []
    if multi_events:
        for e in events:
            events_param.append(gen_bi_event(e, event_value))
    else:
        events_param.append(gen_bi_event(events, event_value))

    params = {
        'device': {
            '10': system_ver,
            '11': system_str
        },
        'app': {
            '7': BI_APPID,
            '8': cocos.COCOS2D_CONSOLE_VERSION,
            '9': get_language()
        },
        'time': get_time_stamp(),
        'events': events_param
    }

    return params
예제 #16
0
    def compile_android(self):
        # 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 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 %s --app-abi %s" % (cmd_path, proj_path, self.mode, self.app_abi)
        if self.android_platform is not None:
            build_cmd += ' --ap %s' % self.android_platform
        self._run_cmd(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$"
            ]
        }
        cocos.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 cocos.os_is_win32():
                if cocos.os_is_32bit_windows():
                    check_bits = [ "", "-x86_64" ]
                else:
                    check_bits = [ "-x86_64", "" ]

                sys_folder_name = "windows"
                for bit_str in check_bits:
                    check_folder_name = "windows%s" % bit_str
                    check_path = os.path.join(ndk_root, "toolchains/arm-linux-androideabi-4.8/prebuilt/%s" % check_folder_name)
                    if os.path.isdir(check_path):
                        sys_folder_name = check_folder_name
                        break
            elif cocos.os_is_mac():
                sys_folder_name = "darwin-x86_64"
            else:
                sys_folder_name = "linux-x86_64"

            # set strip execute file name
            if 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 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 arm64-v8a libs
            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))
            if os.path.exists(strip_cmd_path) and os.path.exists(os.path.join(android_out_dir, "arm64-v8a")):
                self.trip_libs(strip_cmd_path, os.path.join(android_out_dir, 'arm64-v8a'))

            # 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'))
예제 #17
0
    def compile_android(self):
        # build .so for android
        CONSOLE_PATH = "tools/cocos2d-console/bin"
        ANDROID_A_PATH = "frameworks/runtime-src/proj.android/obj/local"
        if self.use_studio is not None:
            ANDROID_A_PATH = "frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/" + self.mode + "/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)
        cocos_py_path = os.path.join(console_dir, 'cocos.py')

        # build the simulator project
        proj_path = os.path.join(engine_dir, 'tools/simulator')
        python_path = cocos.check_environment_variable('COCOS_PYTHON_HOME',
                                                       raise_error=False)
        if python_path is None:
            python_path = 'python'
        else:
            python_path = os.path.join(python_path, 'python')
        build_cmd = "\"%s\" \"%s\" compile -s %s -p android --ndk-mode %s --app-abi %s -m %s" % (
            python_path, cocos_py_path, proj_path, self.mode, self.app_abi,
            self.mode)
        if self.android_platform is not None:
            build_cmd += ' --ap %s' % self.android_platform
        if self.use_studio is not None:
            build_cmd += ' --android-studio'

        env_param = ExtendEnv.get_extend_env_str()
        if env_param and len(env_param) > 0:
            build_cmd += (' --env "%s"' % env_param)
        self._run_cmd(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$"]
        }
        cocos.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)

        if not self.disable_strip:
            # strip the android libs
            ndk_root = cocos.check_environment_variable("NDK_ROOT")
            if cocos.os_is_win32():
                if cocos.os_is_32bit_windows():
                    check_bits = ["", "-x86_64"]
                else:
                    check_bits = ["-x86_64", ""]

                sys_folder_name = "windows"
                for bit_str in check_bits:
                    check_folder_name = "windows%s" % bit_str
                    check_path = os.path.join(
                        ndk_root,
                        "toolchains/arm-linux-androideabi-4.9/prebuilt/%s" %
                        check_folder_name)
                    if os.path.isdir(check_path):
                        sys_folder_name = check_folder_name
                        break
            elif cocos.os_is_mac():
                sys_folder_name = "darwin-x86_64"
            else:
                sys_folder_name = "linux-x86_64"

            # set strip execute file name
            if 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.9/prebuilt/%s/arm-linux-androideabi/bin/%s"
                % (sys_folder_name, 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))
            else:
                raise Exception("(%s) wasn't found." % strip_cmd_path)

            # strip arm64-v8a libs
            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))
            if os.path.exists(strip_cmd_path):
                if os.path.exists(os.path.join(android_out_dir, "arm64-v8a")):
                    self.trip_libs(strip_cmd_path,
                                   os.path.join(android_out_dir, 'arm64-v8a'))
            else:
                raise Exception("(%s) wasn't found." % strip_cmd_path)

            # strip x86 libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/x86-4.9/prebuilt/%s/i686-linux-android/bin/%s" %
                (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path):
                if os.path.exists(os.path.join(android_out_dir, "x86")):
                    self.trip_libs(strip_cmd_path,
                                   os.path.join(android_out_dir, 'x86'))
            else:
                raise Exception("(%s) wasn't found." % strip_cmd_path)
예제 #18
0
    def compile_android(self):
        # build .so for android
        cmd_path = self._get_cocos_cmd_path()
        engine_dir = self.repo_x

        # build the simulator project
        proj_path = os.path.join(engine_dir, 'tests/cpp-empty-test')
        if self.language == 'lua':
            proj_path = os.path.join(engine_dir, 'tests/lua-empty-test')
        elif self.language == 'js':
            proj_path = os.path.join(engine_dir, 'tests/js-tests')

        build_cmd = "%s compile -s %s -p android --ndk-mode %s --app-abi %s" % (
            cmd_path, proj_path, self.mode, self.app_abi)
        if self.android_platform is not None:
            build_cmd += ' --ap %s' % self.android_platform
        self._run_cmd(build_cmd)

        # copy .a to prebuilt dir
        ANDROID_A_PATH = "proj.android/app/build/intermediates/ndkBuild/%s/obj/local/%s" % (
            self.mode, self.app_abi)
        if self.language != 'cpp':
            ANDROID_A_PATH = 'project/' + ANDROID_A_PATH

        android_out_dir = os.path.join(self.lib_dir, "android")
        obj_dir = os.path.join(proj_path, ANDROID_A_PATH)
        copy_cfg = {
            "from": obj_dir,
            "to": android_out_dir,
            "include": ["*.a$"]
        }
        cocos.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 cocos.os_is_win32():
                if cocos.os_is_32bit_windows():
                    check_bits = ["", "-x86_64"]
                else:
                    check_bits = ["-x86_64", ""]

                sys_folder_name = "windows"
                for bit_str in check_bits:
                    check_folder_name = "windows%s" % bit_str
                    check_path = os.path.join(
                        ndk_root,
                        "toolchains/arm-linux-androideabi-4.9/prebuilt/%s" %
                        check_folder_name)
                    if os.path.isdir(check_path):
                        sys_folder_name = check_folder_name
                        break
            elif cocos.os_is_mac():
                sys_folder_name = "darwin-x86_64"
            else:
                sys_folder_name = "linux-x86_64"

            # set strip execute file name
            if 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.9/prebuilt/%s/arm-linux-androideabi/bin/%s"
                % (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path):
                self.trip_libs(strip_cmd_path,
                               os.path.join(android_out_dir, "armeabi-v7a"))

            # strip arm64-v8a libs
            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))
            if os.path.exists(strip_cmd_path) and os.path.exists(
                    os.path.join(android_out_dir, "arm64-v8a")):
                self.trip_libs(strip_cmd_path,
                               os.path.join(android_out_dir, 'arm64-v8a'))

            # 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'))
예제 #19
0
    def compile_android(self):
        # 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 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 %s --app-abi %s" % (
            cmd_path, proj_path, self.mode, self.app_abi)

        env_param = ExtendEnv.get_extend_env_str()
        if env_param and len(env_param) > 0:
            build_cmd += (' --env "%s"' % env_param)
        self._run_cmd(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$"]
        }
        cocos.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)

        if not self.disable_strip:
            # strip the android libs
            ndk_root = cocos.check_environment_variable("NDK_ROOT")
            if cocos.os_is_win32():
                if cocos.os_is_32bit_windows():
                    check_bits = ["", "-x86_64"]
                else:
                    check_bits = ["-x86_64", ""]

                sys_folder_name = "windows"
                for bit_str in check_bits:
                    check_folder_name = "windows%s" % bit_str
                    check_path = os.path.join(
                        ndk_root,
                        "toolchains/arm-linux-androideabi-4.8/prebuilt/%s" %
                        check_folder_name)
                    if os.path.isdir(check_path):
                        sys_folder_name = check_folder_name
                        break
            elif cocos.os_is_mac():
                sys_folder_name = "darwin-x86_64"
            else:
                sys_folder_name = "linux-x86_64"

            # set strip execute file name
            if 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 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'))