def get_version_string(self) -> str: """Returns full version string of the C compiler.""" lines = execution.run_stdout([self.c_compiler, '--version']) # Example output: # Ubuntu 20.04 mingw: "x86_64-w64-mingw32-gcc (GCC) 9.3-win32 20200320" # Ubuntu 16.04 mingw: "x86_64-w64-mingw32-gcc (GCC) 5.3.1 20160211" return lines[0].strip()
def _parse_clang_version(c_compiler: str) -> Optional[Version]: args = [c_compiler, '--version'] ver_line = execution.run_stdout(args)[0] # Example output: # Ubuntu 20.04: clang version 10.0.0-4ubuntu1 # Ubuntu 18.04: clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final) # Ubuntu 16.04: clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) # Built from source: clang version 9.0.1 assert ver_line.startswith('clang version ') ver_str = ver_line.split(' ')[2] # Remove distribution suffix (if any) and convert to a tuple return _str_to_ver(ver_str.split('-')[0])
def get_lib_search_dirs(self) -> Set[str]: """Returns a set of paths where the toolchain runtime libraries can be found. """ lines = execution.run_stdout([self.c_compiler, '-print-search-dirs']) prefix = 'libraries: =' result = set() for line in lines: if not line.startswith(prefix): continue line = line[len(prefix):] for path in line.strip().split(':'): result.add(os.path.normpath(path)) assert result, ('Failed to parse "{} -print-search-dirs" ' 'output'.format(self.c_compiler)) return result
def _parse_clang_version(c_compiler: str) -> Optional[Version]: args = [c_compiler, '--version'] ver_line = execution.run_stdout(args)[0] # Example output: # Ubuntu 20.04: clang version 10.0.0-4ubuntu1 # Ubuntu 18.04: clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final) # Ubuntu 16.04: clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) # Debian testing (bullseye): Debian clang version 11.0.1-2 # Built from source: clang version 9.0.1 # Remove distribution suffix (if any) and convert to a tuple assert ver_line.startswith('clang version ') \ or ver_line.startswith('Debian clang version') \ or ver_line.startswith('Apple clang version') ver_match = re.search(r'version ([0-9.]+)', ver_line) assert ver_match is not None return _str_to_ver(ver_match.group(1))
def _check_tool(cfg: config.Config, bin_name: str, name: str, min_version: Version) -> bool: """Check availability and version of a tool.""" if not _check_availability(bin_name, name): return False bin_path = shutil.which(bin_name) assert bin_path is not None ver_line = execution.run_stdout([bin_name, '--version'])[0] assert '{} version'.format(bin_name) in ver_line ver = _str_to_ver(ver_line.split(' ')[-1]) if ver < min_version: _print_version_error(name, bin_path, ver, min_version) return False if cfg.verbose: logging.info('Found %s version %s', name, ver) return True
def _parse_gcc_version(c_compiler: str) -> Optional[Version]: args = [c_compiler, '--version'] ver_line = execution.run_stdout(args)[0] # Example output: # Ubuntu 20.04: "gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" # Ubuntu 16.04: "gcc (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010" # Ubuntu 20.04 mingw: "x86_64-w64-mingw32-gcc (GCC) 9.3-win32 20200320" # Ubuntu 16.04 mingw: "x86_64-w64-mingw32-gcc (GCC) 5.3.1 20160211" # RHEL 7.6: "gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)" ver_rex = re.compile(r'(\d+\.\d+(?:\.\d+)?)(?:-.*)') for part in ver_line.split(' '): match = ver_rex.match(part) if match is not None: ver_str = match.group(1) break else: logging.error('Failed to parse GCC version "%s"', ver_rex) return None return _str_to_ver(ver_str)