<s> import re <EOL> from subprocess import Popen , PIPE , STDOUT <EOL> import platform <EOL> from conans . client . output import Color <EOL> from conans . model . version import Version <EOL> import os <EOL> def _execute ( command ) : <EOL> proc = Popen ( command , shell = True , bufsize = <NUM_LIT:1> , stdout = PIPE , stderr = STDOUT ) <EOL> output_buffer = [ ] <EOL> while True : <EOL> line = proc . stdout . readline ( ) <EOL> if not line : <EOL> break <EOL> output_buffer . append ( line ) <EOL> proc . communicate ( ) <EOL> return proc . returncode , "<STR_LIT>" . join ( output_buffer ) <EOL> def _gcc_compiler ( output , compiler_exe = "<STR_LIT>" ) : <EOL> try : <EOL> _ , out = _execute ( '<STR_LIT>' % compiler_exe ) <EOL> compiler = "<STR_LIT>" <EOL> installed_version = re . search ( "<STR_LIT>" , out ) . group ( ) <EOL> if installed_version : <EOL> output . success ( "<STR_LIT>" % ( compiler , installed_version ) ) <EOL> return compiler , installed_version <EOL> except : <EOL> return None <EOL> def _clang_compiler ( output , compiler_exe = "<STR_LIT>" ) : <EOL> try : <EOL> _ , out = _execute ( '<STR_LIT>' % compiler_exe ) <EOL> if "<STR_LIT>" in out : <EOL> compiler = "<STR_LIT>" <EOL> elif "<STR_LIT>" in out : <EOL> compiler = "<STR_LIT>" <EOL> installed_version = re . search ( "<STR_LIT>" , out ) . group ( ) <EOL> if installed_version : <EOL> output . success ( "<STR_LIT>" % ( compiler , installed_version ) ) <EOL> return compiler , installed_version <EOL> except : <EOL> return None <EOL> def _visual_compiler ( output , version ) : <EOL> '<STR_LIT>' <EOL> from six . moves import winreg <EOL> try : <EOL> hKey = winreg . OpenKey ( winreg . HKEY_LOCAL_MACHINE , <EOL> r"<STR_LIT>" ) <EOL> winreg . QueryValueEx ( hKey , "<STR_LIT>" ) <EOL> is_64bits = True <EOL> except EnvironmentError : <EOL> is_64bits = False <EOL> finally : <EOL> winreg . CloseKey ( hKey ) <EOL> if is_64bits : <EOL> key_name = r'<STR_LIT>' <EOL> else : <EOL> key_name = r'<STR_LIT>' <EOL> try : <EOL> key = winreg . OpenKey ( winreg . HKEY_LOCAL_MACHINE , key_name ) <EOL> winreg . QueryValueEx ( key , version ) <EOL> installed_version = Version ( version ) . major ( fill = False ) <EOL> compiler = "<STR_LIT>" <EOL> output . success ( "<STR_LIT>" % ( compiler , installed_version ) ) <EOL> return compiler , installed_version <EOL> except EnvironmentError : <EOL> return None <EOL> def _visual_compiler_last ( output ) : <EOL> last_version = None <EOL> for version in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> vs = _visual_compiler ( output , version ) <EOL> last_version = vs or last_version <EOL> return last_version <EOL> def _get_default_compiler ( output ) : <EOL> cc = os . environ . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> cxx = os . environ . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if cc or cxx : <EOL> output . info ( "<STR_LIT>" % ( cc or "<STR_LIT:None>" , cxx or "<STR_LIT:None>" ) ) <EOL> command = cc or cxx <EOL> if "<STR_LIT>" in command : <EOL> return _gcc_compiler ( output , command ) <EOL> if "<STR_LIT>" in command . lower ( ) : <EOL> return _clang_compiler ( output , command ) <EOL> output . error ( "<STR_LIT>" % command ) <EOL> return None <EOL> if platform . system ( ) == "<STR_LIT>" : <EOL> vs = _visual_compiler_last ( output ) <EOL> gcc = _gcc_compiler ( output ) <EOL> clang = _clang_compiler ( output ) <EOL> if platform . system ( ) == "<STR_LIT>" : <EOL> return vs or gcc or clang <EOL> elif platform . system ( ) == "<STR_LIT>" : <EOL> return clang or gcc <EOL> else : <EOL> return gcc or clang <EOL> def _detect_compiler_version ( result , output ) : <EOL> try : <EOL> compiler , version = _get_default_compiler ( output ) <EOL> except : <EOL> compiler , version = None , None <EOL> if not compiler or not version : <EOL> output . error ( "<STR_LIT>" ) <EOL> else : <EOL> result . append ( ( "<STR_LIT>" , compiler ) ) <EOL> result . append ( ( "<STR_LIT>" , version ) ) <EOL> if compiler == "<STR_LIT>" : <EOL> result . append ( ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> elif compiler == "<STR_LIT>" : <EOL> result . append ( ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> elif compiler == "<STR_LIT>" or "<STR_LIT>" in compiler : <EOL> result . append ( ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> def _detect_os_arch ( result , output ) : <EOL> architectures = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> systems = { '<STR_LIT>' : '<STR_LIT>' } <EOL> result . append ( ( "<STR_LIT>" , systems . get ( platform . system ( ) , platform . system ( ) ) ) ) <EOL> arch = architectures . get ( platform . machine ( ) . lower ( ) , platform . machine ( ) . lower ( ) ) <EOL> if arch . startswith ( '<STR_LIT>' ) : <EOL> for a in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if arch . startswith ( a ) : <EOL> arch = a <EOL> break <EOL> else : <EOL> output . error ( "<STR_LIT>" <EOL> "<STR_LIT>" % arch ) <EOL> result . append ( ( "<STR_LIT>" , arch ) ) <EOL> def detect_defaults_settings ( output ) : <EOL> """<STR_LIT>""" <EOL> output . writeln ( "<STR_LIT>" , Color . BRIGHT_YELLOW ) <EOL> output . writeln ( "<STR_LIT>" , Color . BRIGHT_YELLOW ) <EOL> result = [ ] <EOL> _detect_os_arch ( result , output ) <EOL> _detect_compiler_version ( result , output ) <EOL> result . append ( ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> output . writeln ( "<STR_LIT>" , Color . BRIGHT_YELLOW ) <EOL> output . writeln ( "<STR_LIT:\n>" . join ( [ "<STR_LIT>" % ( k , v ) for ( k , v ) in result ] ) , Color . BRIGHT_YELLOW ) <EOL> output . writeln ( "<STR_LIT>" , Color . BRIGHT_MAGENTA ) <EOL> output . writeln ( "<STR_LIT>" , Color . BRIGHT_MAGENTA ) <EOL> return result </s>
