def get_win32_os_info_from_cygwin(): """Get operating system information for windows from cygwin. """ platform_str = unversioned_platform() if platform_str != 'cygwin': raise blderror.UnsupportedPlatformError( 'Function can only be called in a cygwin environment.') os_type = 'windows' os_name = 'windows_nt' out = shell_command('echo $(cmd /c ver)') m = re.match(r'\s*Microsoft\s+Windows\s+\[Version\s+(\d+\.\d+)[^\]]+\]', out) if not m: raise blderror.UnsupportedPlatformError( 'Invalid Windows version string "%s".' % out) os_ver = m.group(1) # Make the assumption that we are on a X86 system. if is_64bit_system(): cpu_type = 'amd64' else: cpu_type = 'x86' return os_type, os_name, cpu_type, os_ver
def get_os_info(): """Return the operating system information part of the UPLID. Returns: os_type, os_name, cpu_type, os_ver """ def get_linux_os_info(): os_type = 'unix' os_name = 'linux' uname = os.uname() cpu_type = uname[4] os_ver = uname[2] # os_ver can contain a '-flavor' part, strip it os_ver = os_ver.split('-', 1)[0] if cpu_type == 'ppc64': cpu_type = 'powerpc' return os_type, os_name, cpu_type, os_ver def get_aix_os_info(): os_type = 'unix' os_name = 'aix' cpu_type = shell_command(['/bin/uname', '-p']).rstrip() uname = os.uname() os_ver = '%s.%s' % (uname[3], uname[2]) return os_type, os_name, cpu_type, os_ver def get_sunos_os_info(): os_type = 'unix' os_name = 'sunos' cpu_type = shell_command(['/bin/uname', '-p']).rstrip() uname = os.uname() os_ver = uname[2] return os_type, os_name, cpu_type, os_ver def get_darwin_os_info(): os_type = 'unix' os_name = 'darwin' uname = os.uname() cpu_type = uname[4] os_ver = uname[2] # os_ver can contain a '-flavor' part, strip it os_ver = os_ver.split('-', 1)[0] return os_type, os_name, cpu_type, os_ver def get_windows_os_info(): os_type = 'windows' os_name = 'windows_nt' import platform uname = platform.uname() os_ver = '.'.join(uname[3].split('.')[0:2]) # Make the assumption that we are on a X86 system. if is_64bit_system(): cpu_type = 'x86_64' else: cpu_type = 'x86' return os_type, os_name, cpu_type, os_ver platform_str = unversioned_platform() os_info_getters = { 'linux': get_linux_os_info, 'aix': get_aix_os_info, 'sunos': get_sunos_os_info, 'darwin': get_darwin_os_info, 'win32': get_windows_os_info } if platform_str not in os_info_getters: raise blderror.UnsupportedPlatformError('Unsupported platform %s' % platform_str) return os_info_getters[platform_str]()
def get_comp_info(ctx): """Return the compiler information part of the UPLID. See sysutil.get_os_info() which gets the operating system part of the UPLID. Args: ctx (ConfigurationContext): The waf configuration context. Returns: comp_type, compiler_version """ def sanitize_comp_info(comp_type, comp_ver): """Correct problematic compiler information. waf sets `CXX` to `gcc` for both `clang` and `gcc`. This function changes the `cxx_name-cxx_version` combination for `clang` to distinctly identify `clang` when invoked as `gcc` and indicate the `clang` compiler version that `waf` correctly extracts into `CC_VERSION`. """ if comp_type != 'gcc': return comp_type, comp_ver cmd = ctx.env.CXX + ['-dM', '-E', '-'] env = ctx.env.env or None try: p = Utils.subprocess.Popen(cmd, stdin=Utils.subprocess.PIPE, stdout=Utils.subprocess.PIPE, stderr=Utils.subprocess.PIPE, env=env) p.stdin.write('\n'.encode()) out = p.communicate()[0] except Exception: ctx.conf.fatal('Could not determine the compiler version %r' % cmd) if not isinstance(out, str): out = out.decode(sys.stdout.encoding or 'iso8859-1') if out.find("__clang__ 1") < 0: return comp_type, comp_ver return 'clang', '.'.join(ctx.env.CC_VERSION) def get_linux_comp_info(ctx): return ctx.env.CXX_NAME, '.'.join(ctx.env.CC_VERSION) def get_aix_comp_info(ctx): cxx_name = ctx.env.CXX_NAME if cxx_name == 'xlc++': cxx_name = 'xlc' return cxx_name, '.'.join(ctx.env.CC_VERSION) def get_sunos_comp_info(ctx): cxx_name = ctx.env.CXX_NAME if cxx_name == 'sun': cxx_name = 'cc' return cxx_name, '.'.join(ctx.env.CC_VERSION) def get_darwin_comp_info(ctx): return ctx.env.CXX_NAME, '.'.join(ctx.env.CC_VERSION) def get_windows_comp_info(ctx): env = dict(ctx.environ) env.update(PATH=';'.join(ctx.env['PATH'])) err = ctx.cmd_and_log(ctx.env['CXX'], output=Context.STDERR, env=env) m = re.search(r'Compiler Version ([0-9]+\.[0-9]+).*? for (\S*)', err) if m: compiler = 'cl' compilerversion = m.group(1) return compiler, compilerversion def get_freebsd_comp_info(ctx): return ctx.env.CXX_NAME, '.'.join(ctx.env.CC_VERSION) platform_str = sysutil.unversioned_platform() comp_info_getters = { 'linux': get_linux_comp_info, 'aix': get_aix_comp_info, 'sunos': get_sunos_comp_info, 'darwin': get_darwin_comp_info, 'win32': get_windows_comp_info, 'freebsd': get_freebsd_comp_info } if platform_str not in comp_info_getters: raise blderror.UnsupportedPlatformError('Unsupported platform %s' % platform_str) uplid = sanitize_comp_info(*comp_info_getters[platform_str](ctx)) return uplid
def get_os_info(): """Return the operating system information part of the UPLID. Returns: os_type, os_name, cpu_type, os_ver """ def get_linux_os_info(): os_type = "unix" os_name = "linux" uname = os.uname() cpu_type = uname[4] os_ver = uname[2] # os_ver can contain a '-flavor' part, strip it os_ver = os_ver.split("-", 1)[0] if cpu_type == "ppc64": cpu_type = "powerpc" return os_type, os_name, cpu_type, os_ver def get_aix_os_info(): os_type = "unix" os_name = "aix" cpu_type = shell_command(["/bin/uname", "-p"]).rstrip() uname = os.uname() os_ver = "%s.%s" % (uname[3], uname[2]) return os_type, os_name, cpu_type, os_ver def get_sunos_os_info(): os_type = "unix" os_name = "sunos" cpu_type = shell_command(["/bin/uname", "-p"]).rstrip() uname = os.uname() os_ver = uname[2] return os_type, os_name, cpu_type, os_ver def get_darwin_os_info(): os_type = "unix" os_name = "darwin" uname = os.uname() cpu_type = uname[4] os_ver = uname[2] # os_ver can contain a '-flavor' part, strip it os_ver = os_ver.split("-", 1)[0] return os_type, os_name, cpu_type, os_ver def get_windows_os_info(): os_type = "windows" os_name = "windows_nt" import platform uname = platform.uname() os_ver = ".".join(uname[3].split(".")[0:2]) # Make the assumption that we are on a X86 system. if is_64bit_system(): cpu_type = "x86_64" else: cpu_type = "x86" return os_type, os_name, cpu_type, os_ver def get_freebsd_os_info(): os_type = "unix" os_name = "freebsd" uname = os.uname() cpu_type = ("x86_64" if uname[4] == "amd64" else "x86" if uname[4] == "i386" else uname[4]) os_ver = uname[2].split("-", 1)[0] return os_type, os_name, cpu_type, os_ver platform_str = unversioned_platform() os_info_getters = { "linux": get_linux_os_info, "aix": get_aix_os_info, "sunos": get_sunos_os_info, "darwin": get_darwin_os_info, "win32": get_windows_os_info, "freebsd": get_freebsd_os_info, } if platform_str not in os_info_getters: raise blderror.UnsupportedPlatformError("Unsupported platform %s" % platform_str) return os_info_getters[platform_str]()