<s> import os <EOL> import re <EOL> import subprocess <EOL> import _winreg <EOL> import yaku . task <EOL> from yaku . tools . mscommon . common import read_values , read_value , get_output <EOL> def _exec_command_factory ( saved ) : <EOL> def msvc_exec_command ( self , cmd , cwd , env = None ) : <EOL> new_cmd = [ ] <EOL> carry = "<STR_LIT>" <EOL> for c in cmd : <EOL> if c in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> carry = c <EOL> else : <EOL> c = carry + c <EOL> carry = "<STR_LIT>" <EOL> new_cmd . append ( c ) <EOL> env = dict ( os . environ ) <EOL> env . update ( PATH = os . pathsep . join ( self . env [ "<STR_LIT>" ] ) ) <EOL> saved ( self , new_cmd , cwd , env = env ) <EOL> return msvc_exec_command <EOL> _ARCH_TO_CANONICAL = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> _HOST_TARGET_ARCH_TO_BAT_ARCH = { <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) : "<STR_LIT>" , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) : "<STR_LIT>" , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) : "<STR_LIT>" , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) : "<STR_LIT>" , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) : "<STR_LIT>" <EOL> } <EOL> _VCVER = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> _VCVER_TO_PRODUCT_DIR = { <EOL> '<STR_LIT>' : [ <EOL> r'<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ <EOL> r'<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ <EOL> r'<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ <EOL> r'<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ <EOL> r'<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ <EOL> r'<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ <EOL> r'<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ <EOL> r'<STR_LIT>' ] <EOL> } <EOL> _is_win64 = None <EOL> def is_win64 ( ) : <EOL> """<STR_LIT>""" <EOL> global _is_win64 <EOL> if _is_win64 is None : <EOL> _is_win64 = False <EOL> if os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) != '<STR_LIT>' : <EOL> _is_win64 = True <EOL> if os . environ . get ( '<STR_LIT>' ) : <EOL> _is_win64 = True <EOL> if os . environ . get ( '<STR_LIT>' ) : <EOL> _is_win64 = True <EOL> return _is_win64 <EOL> def msvc_version_to_maj_min ( msvc_version ) : <EOL> msvc_version_numeric = '<STR_LIT>' . join ( [ x for x in msvc_version if x in string_digits + '<STR_LIT:.>' ] ) <EOL> t = msvc_version_numeric . split ( "<STR_LIT:.>" ) <EOL> if not len ( t ) == <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" % ( msvc_version , msvc_version_numeric ) ) <EOL> try : <EOL> maj = int ( t [ <NUM_LIT:0> ] ) <EOL> min = int ( t [ <NUM_LIT:1> ] ) <EOL> return maj , min <EOL> except ValueError , e : <EOL> raise ValueError ( "<STR_LIT>" % ( msvc_version , msvc_version_numeric ) ) <EOL> def is_host_target_supported ( host_target , msvc_version ) : <EOL> """<STR_LIT>""" <EOL> if host_target [ <NUM_LIT:1> ] != "<STR_LIT>" : <EOL> maj , min = msvc_version_to_maj_min ( msvc_version ) <EOL> if maj < <NUM_LIT:8> : <EOL> return False <EOL> return True <EOL> def find_vc_pdir ( msvc_version ) : <EOL> """<STR_LIT>""" <EOL> base = _winreg . HKEY_LOCAL_MACHINE <EOL> root = '<STR_LIT>' <EOL> if is_win64 ( ) : <EOL> root = root + '<STR_LIT>' <EOL> try : <EOL> hkeys = _VCVER_TO_PRODUCT_DIR [ msvc_version ] <EOL> except KeyError : <EOL> raise ValueError ( "<STR_LIT>" % msvc_version ) <EOL> for key in hkeys : <EOL> key = root + key <EOL> comps = read_value ( key ) <EOL> if comps is not None : <EOL> if os . path . exists ( comps ) : <EOL> return comps <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % comps ) <EOL> return None <EOL> def find_versions ( abi ) : <EOL> base = _winreg . HKEY_LOCAL_MACHINE <EOL> key = os . path . join ( _FC_ROOT [ abi ] , "<STR_LIT>" ) <EOL> availables = { } <EOL> versions = read_keys ( base , key ) <EOL> if versions is None : <EOL> return availables <EOL> for v in versions : <EOL> verk = os . path . join ( key , v ) <EOL> key = open_key ( verk ) <EOL> try : <EOL> maj = _winreg . QueryValueEx ( key , "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> min = _winreg . QueryValueEx ( key , "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> bld = _winreg . QueryValueEx ( key , "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> availables [ ( maj , min , bld ) ] = verk <EOL> finally : <EOL> close_key ( key ) <EOL> return availables <EOL> def _detect_msvc ( ctx ) : <EOL> from string import digits as string_digits <EOL> msvc_version_info = ( <NUM_LIT:9> , <NUM_LIT:0> ) <EOL> msvc_version = "<STR_LIT>" <EOL> pdir = find_vc_pdir ( msvc_version ) <EOL> if pdir is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> msvc_ver_numeric = '<STR_LIT>' . join ( [ x for x in msvc_version if x in string_digits + "<STR_LIT:.>" ] ) <EOL> vernum = float ( msvc_ver_numeric ) <EOL> if <NUM_LIT:7> <= vernum < <NUM_LIT:8> : <EOL> pdir = os . path . join ( pdir , os . pardir , "<STR_LIT>" , "<STR_LIT>" ) <EOL> batfilename = os . path . join ( pdir , "<STR_LIT>" ) <EOL> elif vernum < <NUM_LIT:7> : <EOL> pdir = os . path . join ( pdir , "<STR_LIT>" ) <EOL> batfilename = os . path . join ( pdir , "<STR_LIT>" ) <EOL> else : <EOL> batfilename = os . path . join ( pdir , "<STR_LIT>" ) <EOL> vc_paths = get_output ( ctx , batfilename , "<STR_LIT>" ) <EOL> cc = None <EOL> linker = None <EOL> lib = None <EOL> for p in vc_paths [ "<STR_LIT>" ] : <EOL> _cc = os . path . join ( p , "<STR_LIT>" ) <EOL> _linker = os . path . join ( p , "<STR_LIT>" ) <EOL> _lib = os . path . join ( p , "<STR_LIT>" ) <EOL> if os . path . exists ( _cc ) and os . path . exists ( _linker ) and os . path . exists ( _lib ) : <EOL> cc = _cc <EOL> linker = _linker <EOL> lib = _lib <EOL> break <EOL> if cc is None or linker is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> return cc , linker , lib , vc_paths , msvc_version_info <EOL> def setup ( ctx ) : <EOL> env = ctx . env <EOL> cc , linker , lib , vc_paths , msvc_version_info = _detect_msvc ( ctx ) <EOL> ctx . env [ "<STR_LIT>" ] = vc_paths [ "<STR_LIT>" ] [ : ] <EOL> ctx . env . prextend ( "<STR_LIT>" , vc_paths [ "<STR_LIT>" ] , create = True ) <EOL> ctx . env . prextend ( "<STR_LIT>" , vc_paths [ "<STR_LIT>" ] , create = True ) <EOL> ctx . env [ "<STR_LIT>" ] = [ cc ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> ctx . env [ "<STR_LIT>" ] = [ linker ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ linker , "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = [ linker , "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> ctx . env [ "<STR_LIT>" ] = [ lib ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> ctx . env [ "<STR_LIT>" ] = [ cc ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> if msvc_version_info >= ( <NUM_LIT:9> , <NUM_LIT:0> ) : <EOL> ctx . env . append ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ctx . env [ "<STR_LIT>" ] = [ linker ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = [ linker ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> ctx . env [ "<STR_LIT>" ] = [ ] <EOL> ctx . env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> ctx . env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> ctx . env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> ctx . env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> for k , v in vc_paths . items ( ) : <EOL> k = k . encode ( "<STR_LIT:ascii>" ) <EOL> if k in [ "<STR_LIT>" ] : <EOL> env . extend ( "<STR_LIT>" , v , create = True ) <EOL> elif k in [ "<STR_LIT>" ] : <EOL> env . extend ( k , v , create = True ) <EOL> for task_class in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> klass = yaku . task . task_factory ( task_class ) <EOL> saved = klass . exec_command <EOL> klass . exec_command = _exec_command_factory ( saved ) <EOL> def detect ( ctx ) : <EOL> _detect_msvc ( ctx ) <EOL> return True </s>
