<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import shutil <EOL> import subprocess <EOL> import stat <EOL> import string <EOL> import sys <EOL> BASE_DIR = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> _LINK_EXE_OUT_ARG = re . compile ( '<STR_LIT>' , re . IGNORECASE ) <EOL> def main ( args ) : <EOL> executor = WinTool ( ) <EOL> exit_code = executor . Dispatch ( args ) <EOL> if exit_code is not None : <EOL> sys . exit ( exit_code ) <EOL> class WinTool ( object ) : <EOL> """<STR_LIT>""" <EOL> def _UseSeparateMspdbsrv ( self , env , args ) : <EOL> """<STR_LIT>""" <EOL> if len ( args ) < <NUM_LIT:1> : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if args [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> return <EOL> endpoint_name = None <EOL> for arg in args : <EOL> m = _LINK_EXE_OUT_ARG . match ( arg ) <EOL> if m : <EOL> endpoint_name = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % ( m . group ( '<STR_LIT>' ) , os . getpid ( ) ) ) <EOL> break <EOL> if endpoint_name is None : <EOL> return <EOL> env [ '<STR_LIT>' ] = endpoint_name <EOL> def Dispatch ( self , args ) : <EOL> """<STR_LIT>""" <EOL> if len ( args ) < <NUM_LIT:1> : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> method = "<STR_LIT>" % self . _CommandifyName ( args [ <NUM_LIT:0> ] ) <EOL> return getattr ( self , method ) ( * args [ <NUM_LIT:1> : ] ) <EOL> def _CommandifyName ( self , name_string ) : <EOL> """<STR_LIT>""" <EOL> return name_string . title ( ) . replace ( '<STR_LIT:->' , '<STR_LIT>' ) <EOL> def _GetEnv ( self , arch ) : <EOL> """<STR_LIT>""" <EOL> pairs = open ( arch ) . read ( ) [ : - <NUM_LIT:2> ] . split ( '<STR_LIT>' ) <EOL> kvs = [ item . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) for item in pairs ] <EOL> return dict ( kvs ) <EOL> def ExecStamp ( self , path ) : <EOL> """<STR_LIT>""" <EOL> open ( path , '<STR_LIT:w>' ) . close ( ) <EOL> def ExecRecursiveMirror ( self , source , dest ) : <EOL> """<STR_LIT>""" <EOL> if os . path . exists ( dest ) : <EOL> if os . path . isdir ( dest ) : <EOL> def _on_error ( fn , path , excinfo ) : <EOL> if not os . access ( path , os . W_OK ) : <EOL> os . chmod ( path , stat . S_IWRITE ) <EOL> fn ( path ) <EOL> shutil . rmtree ( dest , onerror = _on_error ) <EOL> else : <EOL> if not os . access ( dest , os . W_OK ) : <EOL> os . chmod ( dest , stat . S_IWRITE ) <EOL> os . unlink ( dest ) <EOL> if os . path . isdir ( source ) : <EOL> shutil . copytree ( source , dest ) <EOL> else : <EOL> shutil . copy2 ( source , dest ) <EOL> def ExecLinkWrapper ( self , arch , use_separate_mspdbsrv , * args ) : <EOL> """<STR_LIT>""" <EOL> env = self . _GetEnv ( arch ) <EOL> if use_separate_mspdbsrv == '<STR_LIT:True>' : <EOL> self . _UseSeparateMspdbsrv ( env , args ) <EOL> link = subprocess . Popen ( [ args [ <NUM_LIT:0> ] . replace ( '<STR_LIT:/>' , '<STR_LIT:\\>' ) ] + list ( args [ <NUM_LIT:1> : ] ) , <EOL> shell = True , <EOL> env = env , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . STDOUT ) <EOL> out , _ = link . communicate ( ) <EOL> for line in out . splitlines ( ) : <EOL> if ( not line . startswith ( '<STR_LIT>' ) and <EOL> not line . startswith ( '<STR_LIT>' ) and <EOL> not line . startswith ( '<STR_LIT>' ) ) : <EOL> print line <EOL> return link . returncode <EOL> def ExecLinkWithManifests ( self , arch , embed_manifest , out , ldcmd , resname , <EOL> mt , rc , intermediate_manifest , * manifests ) : <EOL> """<STR_LIT>""" <EOL> variables = { <EOL> '<STR_LIT>' : sys . executable , <EOL> '<STR_LIT>' : arch , <EOL> '<STR_LIT>' : out , <EOL> '<STR_LIT>' : ldcmd , <EOL> '<STR_LIT>' : resname , <EOL> '<STR_LIT>' : mt , <EOL> '<STR_LIT>' : rc , <EOL> '<STR_LIT>' : intermediate_manifest , <EOL> '<STR_LIT>' : '<STR_LIT:U+0020>' . join ( manifests ) , <EOL> } <EOL> add_to_ld = '<STR_LIT>' <EOL> if manifests : <EOL> subprocess . check_call ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % variables ) <EOL> if embed_manifest == '<STR_LIT:True>' : <EOL> subprocess . check_call ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % variables ) <EOL> subprocess . check_call ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % variables ) <EOL> add_to_ld = '<STR_LIT>' % variables <EOL> subprocess . check_call ( ldcmd + add_to_ld ) <EOL> if manifests : <EOL> subprocess . check_call ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % variables ) <EOL> assert_manifest = '<STR_LIT>' % variables <EOL> our_manifest = '<STR_LIT>' % variables <EOL> with open ( our_manifest , '<STR_LIT:rb>' ) as our_f : <EOL> with open ( assert_manifest , '<STR_LIT:rb>' ) as assert_f : <EOL> our_data = our_f . read ( ) . translate ( None , string . whitespace ) <EOL> assert_data = assert_f . read ( ) . translate ( None , string . whitespace ) <EOL> if our_data != assert_data : <EOL> os . unlink ( out ) <EOL> def dump ( filename ) : <EOL> sys . stderr . write ( '<STR_LIT>' % filename ) <EOL> with open ( filename , '<STR_LIT:rb>' ) as f : <EOL> sys . stderr . write ( f . read ( ) + '<STR_LIT>' ) <EOL> dump ( intermediate_manifest ) <EOL> dump ( our_manifest ) <EOL> dump ( assert_manifest ) <EOL> sys . stderr . write ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> intermediate_manifest , our_manifest , assert_manifest ) ) <EOL> return <NUM_LIT:1> <EOL> def ExecManifestWrapper ( self , arch , * args ) : <EOL> """<STR_LIT>""" <EOL> env = self . _GetEnv ( arch ) <EOL> popen = subprocess . Popen ( args , shell = True , env = env , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) <EOL> out , _ = popen . communicate ( ) <EOL> for line in out . splitlines ( ) : <EOL> if line and '<STR_LIT>' not in line : <EOL> print line <EOL> return popen . returncode <EOL> def ExecManifestToRc ( self , arch , * args ) : <EOL> """<STR_LIT>""" <EOL> manifest_path , resource_path , resource_name = args <EOL> with open ( resource_path , '<STR_LIT:wb>' ) as output : <EOL> output . write ( '<STR_LIT>' % ( <EOL> resource_name , <EOL> os . path . abspath ( manifest_path ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) ) ) <EOL> def ExecMidlWrapper ( self , arch , outdir , tlb , h , dlldata , iid , proxy , idl , <EOL> * flags ) : <EOL> """<STR_LIT>""" <EOL> args = [ '<STR_LIT>' , '<STR_LIT>' ] + list ( flags ) + [ <EOL> '<STR_LIT>' , outdir , <EOL> '<STR_LIT>' , tlb , <EOL> '<STR_LIT>' , h , <EOL> '<STR_LIT>' , dlldata , <EOL> '<STR_LIT>' , iid , <EOL> '<STR_LIT>' , proxy , <EOL> idl ] <EOL> env = self . _GetEnv ( arch ) <EOL> popen = subprocess . Popen ( args , shell = True , env = env , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) <EOL> out , _ = popen . communicate ( ) <EOL> lines = out . splitlines ( ) <EOL> prefixes = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> processing = set ( os . path . basename ( x ) <EOL> for x in lines if x . startswith ( prefixes ) ) <EOL> for line in lines : <EOL> if not line . startswith ( prefixes ) and line not in processing : <EOL> print line <EOL> return popen . returncode <EOL> def ExecAsmWrapper ( self , arch , * args ) : <EOL> """<STR_LIT>""" <EOL> env = self . _GetEnv ( arch ) <EOL> popen = subprocess . Popen ( args , shell = True , env = env , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) <EOL> out , _ = popen . communicate ( ) <EOL> for line in out . splitlines ( ) : <EOL> if ( not line . startswith ( '<STR_LIT>' ) and <EOL> not line . startswith ( '<STR_LIT>' ) and <EOL> not line . startswith ( '<STR_LIT>' ) and <EOL> line ) : <EOL> print line <EOL> return popen . returncode <EOL> def ExecRcWrapper ( self , arch , * args ) : <EOL> """<STR_LIT>""" <EOL> env = self . _GetEnv ( arch ) <EOL> popen = subprocess . Popen ( args , shell = True , env = env , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) <EOL> out , _ = popen . communicate ( ) <EOL> for line in out . splitlines ( ) : <EOL> if ( not line . startswith ( '<STR_LIT>' ) and <EOL> not line . startswith ( '<STR_LIT>' ) and <EOL> line ) : <EOL> print line <EOL> return popen . returncode <EOL> def ExecActionWrapper ( self , arch , rspfile , * dir ) : <EOL> """<STR_LIT>""" <EOL> env = self . _GetEnv ( arch ) <EOL> for k , v in os . environ . iteritems ( ) : <EOL> if k not in env : <EOL> env [ k ] = v <EOL> args = open ( rspfile ) . read ( ) <EOL> dir = dir [ <NUM_LIT:0> ] if dir else None <EOL> return subprocess . call ( args , shell = True , env = env , cwd = dir ) <EOL> def ExecClCompile ( self , project_dir , selected_files ) : <EOL> """<STR_LIT>""" <EOL> project_dir = os . path . relpath ( project_dir , BASE_DIR ) <EOL> selected_files = selected_files . split ( '<STR_LIT:;>' ) <EOL> ninja_targets = [ os . path . join ( project_dir , filename ) + '<STR_LIT>' <EOL> for filename in selected_files ] <EOL> cmd = [ '<STR_LIT>' ] <EOL> cmd . extend ( ninja_targets ) <EOL> return subprocess . call ( cmd , shell = True , cwd = BASE_DIR ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main ( sys . argv [ <NUM_LIT:1> : ] ) ) </s>
