<s> """<STR_LIT>""" <EOL> import os , traceback , copy <EOL> import Build , Task , Utils , Logs , Options <EOL> from Logs import debug , error , warn <EOL> from Constants import * <EOL> typos = { <EOL> '<STR_LIT>' : '<STR_LIT:source>' , <EOL> '<STR_LIT>' : '<STR_LIT:target>' , <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> class register_obj ( type ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( cls , name , bases , dict ) : <EOL> super ( register_obj , cls ) . __init__ ( name , bases , dict ) <EOL> name = cls . __name__ <EOL> suffix = '<STR_LIT>' <EOL> if name . endswith ( suffix ) : <EOL> task_gen . classes [ name . replace ( suffix , '<STR_LIT>' ) ] = cls <EOL> class task_gen ( object ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = register_obj <EOL> mappings = { } <EOL> mapped = { } <EOL> prec = Utils . DefaultDict ( list ) <EOL> traits = Utils . DefaultDict ( set ) <EOL> classes = { } <EOL> def __init__ ( self , * kw , ** kwargs ) : <EOL> self . prec = Utils . DefaultDict ( list ) <EOL> "<STR_LIT>" <EOL> self . source = '<STR_LIT>' <EOL> self . target = '<STR_LIT>' <EOL> self . meths = [ ] <EOL> self . mappings = { } <EOL> self . features = list ( kw ) <EOL> self . tasks = [ ] <EOL> self . default_chmod = O644 <EOL> self . default_install_path = None <EOL> self . allnodes = [ ] <EOL> self . bld = kwargs . get ( '<STR_LIT>' , Build . bld ) <EOL> self . env = self . bld . env . copy ( ) <EOL> self . path = self . bld . path <EOL> self . name = '<STR_LIT>' <EOL> self . idx = self . bld . idx [ self . path . id ] = self . bld . idx . get ( self . path . id , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> for key , val in kwargs . iteritems ( ) : <EOL> setattr ( self , key , val ) <EOL> self . bld . task_manager . add_task_gen ( self ) <EOL> self . bld . all_task_gen . append ( self ) <EOL> def __str__ ( self ) : <EOL> return ( "<STR_LIT>" <EOL> % ( self . name or self . target , self . __class__ . __name__ , str ( self . path ) ) ) <EOL> def __setattr__ ( self , name , attr ) : <EOL> real = typos . get ( name , name ) <EOL> if real != name : <EOL> warn ( '<STR_LIT>' % ( name , real ) ) <EOL> if Logs . verbose > <NUM_LIT:0> : <EOL> traceback . print_stack ( ) <EOL> object . __setattr__ ( self , real , attr ) <EOL> def to_list ( self , value ) : <EOL> "<STR_LIT>" <EOL> if isinstance ( value , str ) : return value . split ( ) <EOL> else : return value <EOL> def apply ( self ) : <EOL> "<STR_LIT>" <EOL> keys = set ( self . meths ) <EOL> self . features = Utils . to_list ( self . features ) <EOL> for x in self . features + [ '<STR_LIT:*>' ] : <EOL> st = task_gen . traits [ x ] <EOL> if not st : <EOL> warn ( '<STR_LIT>' % x ) <EOL> keys . update ( st ) <EOL> prec = { } <EOL> prec_tbl = self . prec or task_gen . prec <EOL> for x in prec_tbl : <EOL> if x in keys : <EOL> prec [ x ] = prec_tbl [ x ] <EOL> tmp = [ ] <EOL> for a in keys : <EOL> for x in prec . values ( ) : <EOL> if a in x : break <EOL> else : <EOL> tmp . append ( a ) <EOL> out = [ ] <EOL> while tmp : <EOL> e = tmp . pop ( ) <EOL> if e in keys : out . append ( e ) <EOL> try : <EOL> nlst = prec [ e ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> del prec [ e ] <EOL> for x in nlst : <EOL> for y in prec : <EOL> if x in prec [ y ] : <EOL> break <EOL> else : <EOL> tmp . append ( x ) <EOL> if prec : raise Utils . WafError ( "<STR_LIT>" % str ( prec ) ) <EOL> out . reverse ( ) <EOL> self . meths = out <EOL> debug ( '<STR_LIT>' , self , id ( self ) ) <EOL> for x in out : <EOL> try : <EOL> v = getattr ( self , x ) <EOL> except AttributeError : <EOL> raise Utils . WafError ( "<STR_LIT>" % x ) <EOL> debug ( '<STR_LIT>' , x , id ( self ) ) <EOL> v ( ) <EOL> def post ( self ) : <EOL> "<STR_LIT>" <EOL> if not self . name : <EOL> if isinstance ( self . target , list ) : <EOL> self . name = '<STR_LIT:U+0020>' . join ( self . target ) <EOL> else : <EOL> self . name = self . target <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> return <EOL> self . apply ( ) <EOL> debug ( '<STR_LIT>' , self . name ) <EOL> self . posted = True <EOL> def get_hook ( self , ext ) : <EOL> try : return self . mappings [ ext ] <EOL> except KeyError : <EOL> try : return task_gen . mappings [ ext ] <EOL> except KeyError : return None <EOL> def create_task ( self , name , src = None , tgt = None , env = None ) : <EOL> env = env or self . env <EOL> task = Task . TaskBase . classes [ name ] ( env . copy ( ) , generator = self ) <EOL> if src : <EOL> task . set_inputs ( src ) <EOL> if tgt : <EOL> task . set_outputs ( tgt ) <EOL> self . tasks . append ( task ) <EOL> return task <EOL> def name_to_obj ( self , name ) : <EOL> return self . bld . name_to_obj ( name , self . env ) <EOL> def find_sources_in_dirs ( self , dirnames , excludes = [ ] , exts = [ ] ) : <EOL> """<STR_LIT>""" <EOL> err_msg = "<STR_LIT>" <EOL> if not isinstance ( excludes , list ) : <EOL> raise Utils . WscriptError ( err_msg % '<STR_LIT>' ) <EOL> if not isinstance ( exts , list ) : <EOL> raise Utils . WscriptError ( err_msg % '<STR_LIT>' ) <EOL> lst = [ ] <EOL> dirnames = self . to_list ( dirnames ) <EOL> ext_lst = exts or list ( self . mappings . keys ( ) ) + list ( task_gen . mappings . keys ( ) ) <EOL> for name in dirnames : <EOL> anode = self . path . find_dir ( name ) <EOL> if not anode or not anode . is_child_of ( self . bld . srcnode ) : <EOL> raise Utils . WscriptError ( "<STR_LIT>" "<STR_LIT>" % ( name , self . bld . srcnode ) ) <EOL> self . bld . rescan ( anode ) <EOL> for name in self . bld . cache_dir_contents [ anode . id ] : <EOL> if name . startswith ( '<STR_LIT:.>' ) : <EOL> continue <EOL> ( base , ext ) = os . path . splitext ( name ) <EOL> if ext in ext_lst and not name in lst and not name in excludes : <EOL> lst . append ( ( anode . relpath_gen ( self . path ) or '<STR_LIT:.>' ) + os . path . sep + name ) <EOL> lst . sort ( ) <EOL> self . source = self . to_list ( self . source ) <EOL> if not self . source : self . source = lst <EOL> else : self . source += lst <EOL> def clone ( self , env ) : <EOL> "<STR_LIT>" <EOL> newobj = task_gen ( bld = self . bld ) <EOL> for x in self . __dict__ : <EOL> if x in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> continue <EOL> elif x in [ "<STR_LIT:path>" , "<STR_LIT>" ] : <EOL> setattr ( newobj , x , getattr ( self , x ) ) <EOL> else : <EOL> setattr ( newobj , x , copy . copy ( getattr ( self , x ) ) ) <EOL> newobj . __class__ = self . __class__ <EOL> if isinstance ( env , str ) : <EOL> newobj . env = self . bld . all_envs [ env ] . copy ( ) <EOL> else : <EOL> newobj . env = env . copy ( ) <EOL> return newobj <EOL> def get_inst_path ( self ) : <EOL> return getattr ( self , '<STR_LIT>' , getattr ( self , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def set_inst_path ( self , val ) : <EOL> self . _install_path = val <EOL> install_path = property ( get_inst_path , set_inst_path ) <EOL> def get_chmod ( self ) : <EOL> return getattr ( self , '<STR_LIT>' , getattr ( self , '<STR_LIT>' , O644 ) ) <EOL> def set_chmod ( self , val ) : <EOL> self . _chmod = val <EOL> chmod = property ( get_chmod , set_chmod ) <EOL> def declare_extension ( var , func ) : <EOL> try : <EOL> for x in Utils . to_list ( var ) : <EOL> task_gen . mappings [ x ] = func <EOL> except : <EOL> raise Utils . WscriptError ( '<STR_LIT>' % var ) <EOL> task_gen . mapped [ func . __name__ ] = func <EOL> def declare_order ( * k ) : <EOL> assert ( len ( k ) > <NUM_LIT:1> ) <EOL> n = len ( k ) - <NUM_LIT:1> <EOL> for i in xrange ( n ) : <EOL> f1 = k [ i ] <EOL> f2 = k [ i + <NUM_LIT:1> ] <EOL> if not f1 in task_gen . prec [ f2 ] : <EOL> task_gen . prec [ f2 ] . append ( f1 ) <EOL> def declare_chain ( name = '<STR_LIT>' , action = '<STR_LIT>' , ext_in = '<STR_LIT>' , ext_out = '<STR_LIT>' , reentrant = True , color = '<STR_LIT>' , <EOL> install = <NUM_LIT:0> , before = [ ] , after = [ ] , decider = None , rule = None , scan = None ) : <EOL> """<STR_LIT>""" <EOL> action = action or rule <EOL> if isinstance ( action , str ) : <EOL> act = Task . simple_task_type ( name , action , color = color ) <EOL> else : <EOL> act = Task . task_type_from_func ( name , action , color = color ) <EOL> act . ext_in = tuple ( Utils . to_list ( ext_in ) ) <EOL> act . ext_out = tuple ( Utils . to_list ( ext_out ) ) <EOL> act . before = Utils . to_list ( before ) <EOL> act . after = Utils . to_list ( after ) <EOL> act . scan = scan <EOL> def x_file ( self , node ) : <EOL> if decider : <EOL> ext = decider ( self , node ) <EOL> else : <EOL> ext = ext_out <EOL> if isinstance ( ext , str ) : <EOL> out_source = node . change_ext ( ext ) <EOL> if reentrant : <EOL> self . allnodes . append ( out_source ) <EOL> elif isinstance ( ext , list ) : <EOL> out_source = [ node . change_ext ( x ) for x in ext ] <EOL> if reentrant : <EOL> for i in xrange ( ( reentrant is True ) and len ( out_source ) or reentrant ) : <EOL> self . allnodes . append ( out_source [ i ] ) <EOL> else : <EOL> raise Utils . WafError ( "<STR_LIT>" % str ( ext ) ) <EOL> tsk = self . create_task ( name , node , out_source ) <EOL> if node . __class__ . bld . is_install : <EOL> tsk . install = install <EOL> declare_extension ( act . ext_in , x_file ) <EOL> def bind_feature ( name , methods ) : <EOL> lst = Utils . to_list ( methods ) <EOL> task_gen . traits [ name ] . update ( lst ) <EOL> """<STR_LIT>""" <EOL> def taskgen ( func ) : <EOL> setattr ( task_gen , func . __name__ , func ) <EOL> return func <EOL> def feature ( * k ) : <EOL> def deco ( func ) : <EOL> setattr ( task_gen , func . __name__ , func ) <EOL> for name in k : <EOL> task_gen . traits [ name ] . update ( [ func . __name__ ] ) <EOL> return func <EOL> return deco <EOL> def before ( * k ) : <EOL> def deco ( func ) : <EOL> setattr ( task_gen , func . __name__ , func ) <EOL> for fun_name in k : <EOL> if not func . __name__ in task_gen . prec [ fun_name ] : <EOL> task_gen . prec [ fun_name ] . append ( func . __name__ ) <EOL> return func <EOL> return deco <EOL> def after ( * k ) : <EOL> def deco ( func ) : <EOL> setattr ( task_gen , func . __name__ , func ) <EOL> for fun_name in k : <EOL> if not fun_name in task_gen . prec [ func . __name__ ] : <EOL> task_gen . prec [ func . __name__ ] . append ( fun_name ) <EOL> return func <EOL> return deco <EOL> def extension ( var ) : <EOL> def deco ( func ) : <EOL> setattr ( task_gen , func . __name__ , func ) <EOL> try : <EOL> for x in Utils . to_list ( var ) : <EOL> task_gen . mappings [ x ] = func <EOL> except : <EOL> raise Utils . WafError ( '<STR_LIT>' % var ) <EOL> task_gen . mapped [ func . __name__ ] = func <EOL> return func <EOL> return deco <EOL> def apply_core ( self ) : <EOL> """<STR_LIT>""" <EOL> find_resource = self . path . find_resource <EOL> for filename in self . to_list ( self . source ) : <EOL> x = self . get_hook ( filename ) <EOL> if x : <EOL> x ( self , filename ) <EOL> else : <EOL> node = find_resource ( filename ) <EOL> if not node : raise Utils . WafError ( "<STR_LIT>" % ( filename , str ( self . path ) ) ) <EOL> self . allnodes . append ( node ) <EOL> for node in self . allnodes : <EOL> x = self . get_hook ( node . suffix ( ) ) <EOL> if not x : <EOL> raise Utils . WafError ( "<STR_LIT>" % ( str ( node ) , self . __class__ . mappings . keys ( ) , self . __class__ ) ) <EOL> x ( self , node ) <EOL> feature ( '<STR_LIT:*>' ) ( apply_core ) <EOL> def exec_rule ( self ) : <EOL> """<STR_LIT>""" <EOL> if not getattr ( self , '<STR_LIT>' , None ) : <EOL> return <EOL> try : <EOL> self . meths . remove ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> pass <EOL> func = self . rule <EOL> vars2 = [ ] <EOL> if isinstance ( func , str ) : <EOL> ( func , vars2 ) = Task . compile_fun ( '<STR_LIT>' , self . rule , shell = getattr ( self , '<STR_LIT>' , True ) ) <EOL> func . code = self . rule <EOL> name = getattr ( self , '<STR_LIT:name>' , None ) or self . target or self . rule <EOL> if not isinstance ( name , str ) : <EOL> name = str ( self . idx ) <EOL> cls = Task . task_type_from_func ( name , func , getattr ( self , '<STR_LIT>' , vars2 ) ) <EOL> tsk = self . create_task ( name ) <EOL> dep_vars = getattr ( self , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> if dep_vars : <EOL> tsk . dep_vars = dep_vars <EOL> if isinstance ( self . rule , str ) : <EOL> tsk . env . ruledeps = self . rule <EOL> else : <EOL> tsk . env . ruledeps = Utils . h_fun ( self . rule ) <EOL> if getattr ( self , '<STR_LIT:target>' , None ) : <EOL> cls . quiet = True <EOL> tsk . outputs = [ self . path . find_or_declare ( x ) for x in self . to_list ( self . target ) ] <EOL> if getattr ( self , '<STR_LIT:source>' , None ) : <EOL> cls . quiet = True <EOL> tsk . inputs = [ ] <EOL> for x in self . to_list ( self . source ) : <EOL> y = self . path . find_resource ( x ) <EOL> if not y : <EOL> raise Utils . WafError ( '<STR_LIT>' % ( x , self . path . abspath ( ) ) ) <EOL> tsk . inputs . append ( y ) <EOL> if self . allnodes : <EOL> tsk . inputs . extend ( self . allnodes ) <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> cls . scan = self . scan <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> tsk . install_path = self . install_path <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> tsk . cwd = self . cwd <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> Task . update_outputs ( cls ) <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> Task . always_run ( cls ) <EOL> for x in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> setattr ( cls , x , getattr ( self , x , [ ] ) ) <EOL> feature ( '<STR_LIT:*>' ) ( exec_rule ) <EOL> before ( '<STR_LIT>' ) ( exec_rule ) <EOL> def sequence_order ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . meths and self . meths [ - <NUM_LIT:1> ] != '<STR_LIT>' : <EOL> self . meths . append ( '<STR_LIT>' ) <EOL> return <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> return <EOL> if getattr ( self . bld , '<STR_LIT>' , None ) : <EOL> self . bld . prev . post ( ) <EOL> for x in self . bld . prev . tasks : <EOL> for y in self . tasks : <EOL> y . set_run_after ( x ) <EOL> self . bld . prev = self <EOL> feature ( '<STR_LIT>' ) ( sequence_order ) </s>
