<s> """<STR_LIT>""" <EOL> import os , shlex , sys , time <EOL> try : import cPickle <EOL> except ImportError : import pickle as cPickle <EOL> import Environment , Utils , Options , Logs <EOL> from Logs import warn <EOL> from Constants import * <EOL> try : <EOL> from urllib import request <EOL> except : <EOL> from urllib import urlopen <EOL> else : <EOL> urlopen = request . urlopen <EOL> conf_template = '''<STR_LIT>''' <EOL> class ConfigurationError ( Utils . WscriptError ) : <EOL> pass <EOL> autoconfig = False <EOL> "<STR_LIT>" <EOL> def find_file ( filename , path_list ) : <EOL> """<STR_LIT>""" <EOL> for directory in Utils . to_list ( path_list ) : <EOL> if os . path . exists ( os . path . join ( directory , filename ) ) : <EOL> return directory <EOL> return '<STR_LIT>' <EOL> def find_program_impl ( env , filename , path_list = [ ] , var = None , environ = None ) : <EOL> """<STR_LIT>""" <EOL> if not environ : <EOL> environ = os . environ <EOL> try : path_list = path_list . split ( ) <EOL> except AttributeError : pass <EOL> if var : <EOL> if env [ var ] : return env [ var ] <EOL> if var in environ : env [ var ] = environ [ var ] <EOL> if not path_list : path_list = environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( os . pathsep ) <EOL> ext = ( Options . platform == '<STR_LIT:win32>' ) and '<STR_LIT>' or '<STR_LIT>' <EOL> for y in [ filename + x for x in ext . split ( '<STR_LIT:U+002C>' ) ] : <EOL> for directory in path_list : <EOL> x = os . path . join ( directory , y ) <EOL> if os . path . isfile ( x ) : <EOL> if var : env [ var ] = x <EOL> return x <EOL> return '<STR_LIT>' <EOL> class ConfigurationContext ( Utils . Context ) : <EOL> tests = { } <EOL> error_handlers = [ ] <EOL> def __init__ ( self , env = None , blddir = '<STR_LIT>' , srcdir = '<STR_LIT>' ) : <EOL> self . env = None <EOL> self . envname = '<STR_LIT>' <EOL> self . environ = dict ( os . environ ) <EOL> self . line_just = <NUM_LIT> <EOL> self . blddir = blddir <EOL> self . srcdir = srcdir <EOL> self . all_envs = { } <EOL> self . cwd = self . curdir = os . getcwd ( ) <EOL> self . tools = [ ] <EOL> self . setenv ( DEFAULT ) <EOL> self . lastprog = '<STR_LIT>' <EOL> self . hash = <NUM_LIT:0> <EOL> self . files = [ ] <EOL> self . tool_cache = [ ] <EOL> if self . blddir : <EOL> self . post_init ( ) <EOL> def post_init ( self ) : <EOL> self . cachedir = os . path . join ( self . blddir , CACHE_DIR ) <EOL> path = os . path . join ( self . blddir , WAF_CONFIG_LOG ) <EOL> try : os . unlink ( path ) <EOL> except ( OSError , IOError ) : pass <EOL> try : <EOL> self . log = open ( path , '<STR_LIT:w>' ) <EOL> except ( OSError , IOError ) : <EOL> self . fatal ( '<STR_LIT>' % path ) <EOL> app = Utils . g_module . APPNAME <EOL> if app : <EOL> ver = getattr ( Utils . g_module , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if ver : <EOL> app = "<STR_LIT>" % ( app , ver ) <EOL> now = time . ctime ( ) <EOL> pyver = sys . hexversion <EOL> systype = sys . platform <EOL> args = "<STR_LIT:U+0020>" . join ( sys . argv ) <EOL> wafver = WAFVERSION <EOL> abi = ABI <EOL> self . log . write ( conf_template % vars ( ) ) <EOL> def __del__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) and self . log : <EOL> self . log . close ( ) <EOL> def fatal ( self , msg ) : <EOL> raise ConfigurationError ( msg ) <EOL> def check_tool ( self , input , tooldir = None , funs = None ) : <EOL> "<STR_LIT>" <EOL> tools = Utils . to_list ( input ) <EOL> if tooldir : tooldir = Utils . to_list ( tooldir ) <EOL> for tool in tools : <EOL> tool = tool . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if tool == '<STR_LIT>' : tool = '<STR_LIT>' <EOL> if tool . lower ( ) == '<STR_LIT>' : tool = '<STR_LIT>' <EOL> mag = ( tool , id ( self . env ) , funs ) <EOL> if mag in self . tool_cache : <EOL> continue <EOL> self . tool_cache . append ( mag ) <EOL> if not tooldir : <EOL> _Tools = Options . tooldir [ <NUM_LIT:0> ] <EOL> _3rdparty = os . sep . join ( ( _Tools , '<STR_LIT:..>' , '<STR_LIT>' ) ) <EOL> for d in ( _Tools , _3rdparty ) : <EOL> lst = os . listdir ( d ) <EOL> if tool + '<STR_LIT>' in lst : <EOL> break <EOL> else : <EOL> for x in Utils . to_list ( Options . remote_repo ) : <EOL> for sub in [ '<STR_LIT>' % WAFVERSION , '<STR_LIT>' ] : <EOL> url = '<STR_LIT:/>' . join ( ( x , sub , tool + '<STR_LIT>' ) ) <EOL> try : <EOL> web = urlopen ( url ) <EOL> if web . getcode ( ) != <NUM_LIT:200> : <EOL> continue <EOL> except Exception , e : <EOL> continue <EOL> else : <EOL> try : <EOL> loc = open ( _3rdparty + os . sep + tool + '<STR_LIT>' , '<STR_LIT:wb>' ) <EOL> loc . write ( web . read ( ) ) <EOL> web . close ( ) <EOL> finally : <EOL> loc . close ( ) <EOL> Logs . warn ( '<STR_LIT>' % ( tool , url ) ) <EOL> else : <EOL> break <EOL> module = Utils . load_tool ( tool , tooldir ) <EOL> if funs is not None : <EOL> self . eval_rules ( funs ) <EOL> else : <EOL> func = getattr ( module , '<STR_LIT>' , None ) <EOL> if func : <EOL> if type ( func ) is type ( find_file ) : func ( self ) <EOL> else : self . eval_rules ( func ) <EOL> self . tools . append ( { '<STR_LIT>' : tool , '<STR_LIT>' : tooldir , '<STR_LIT>' : funs } ) <EOL> def sub_config ( self , k ) : <EOL> "<STR_LIT>" <EOL> self . recurse ( k , name = '<STR_LIT>' ) <EOL> def pre_recurse ( self , name_or_mod , path , nexdir ) : <EOL> return { '<STR_LIT>' : self , '<STR_LIT>' : self } <EOL> def post_recurse ( self , name_or_mod , path , nexdir ) : <EOL> if not autoconfig : <EOL> return <EOL> self . hash = hash ( ( self . hash , getattr ( name_or_mod , '<STR_LIT>' , name_or_mod ) ) ) <EOL> self . files . append ( path ) <EOL> def store ( self , file = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> if not os . path . isdir ( self . cachedir ) : <EOL> os . makedirs ( self . cachedir ) <EOL> if not file : <EOL> file = open ( os . path . join ( self . cachedir , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> file . write ( '<STR_LIT>' % HEXVERSION ) <EOL> file . write ( '<STR_LIT>' % self . tools ) <EOL> file . close ( ) <EOL> if not self . all_envs : <EOL> self . fatal ( '<STR_LIT>' ) <EOL> for key in self . all_envs : <EOL> tmpenv = self . all_envs [ key ] <EOL> tmpenv . store ( os . path . join ( self . cachedir , key + CACHE_SUFFIX ) ) <EOL> def set_env_name ( self , name , env ) : <EOL> "<STR_LIT>" <EOL> self . all_envs [ name ] = env <EOL> return env <EOL> def retrieve ( self , name , fromenv = None ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> env = self . all_envs [ name ] <EOL> except KeyError : <EOL> env = Environment . Environment ( ) <EOL> env [ '<STR_LIT>' ] = os . path . abspath ( os . path . expanduser ( Options . options . prefix ) ) <EOL> self . all_envs [ name ] = env <EOL> else : <EOL> if fromenv : warn ( "<STR_LIT>" % name ) <EOL> return env <EOL> def setenv ( self , name ) : <EOL> "<STR_LIT>" <EOL> self . env = self . retrieve ( name ) <EOL> self . envname = name <EOL> def add_os_flags ( self , var , dest = None ) : <EOL> try : self . env . append_value ( dest or var , Utils . to_list ( self . environ [ var ] ) ) <EOL> except KeyError : pass <EOL> def check_message_1 ( self , sr ) : <EOL> self . line_just = max ( self . line_just , len ( sr ) ) <EOL> for x in ( '<STR_LIT:\n>' , self . line_just * '<STR_LIT:->' , '<STR_LIT:\n>' , sr , '<STR_LIT:\n>' ) : <EOL> self . log . write ( x ) <EOL> Utils . pprint ( '<STR_LIT>' , "<STR_LIT>" % sr . ljust ( self . line_just ) , sep = '<STR_LIT>' ) <EOL> def check_message_2 ( self , sr , color = '<STR_LIT>' ) : <EOL> self . log . write ( sr ) <EOL> self . log . write ( '<STR_LIT:\n>' ) <EOL> Utils . pprint ( color , sr ) <EOL> def check_message ( self , th , msg , state , option = '<STR_LIT>' ) : <EOL> sr = '<STR_LIT>' % ( th , msg ) <EOL> self . check_message_1 ( sr ) <EOL> p = self . check_message_2 <EOL> if state : p ( '<STR_LIT>' + str ( option ) ) <EOL> else : p ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def check_message_custom ( self , th , msg , custom , option = '<STR_LIT>' , color = '<STR_LIT>' ) : <EOL> sr = '<STR_LIT>' % ( th , msg ) <EOL> self . check_message_1 ( sr ) <EOL> self . check_message_2 ( custom , color ) <EOL> def find_program ( self , filename , path_list = [ ] , var = None , mandatory = False ) : <EOL> "<STR_LIT>" <EOL> ret = None <EOL> if var : <EOL> if self . env [ var ] : <EOL> ret = self . env [ var ] <EOL> elif var in os . environ : <EOL> ret = os . environ [ var ] <EOL> if not isinstance ( filename , list ) : filename = [ filename ] <EOL> if not ret : <EOL> for x in filename : <EOL> ret = find_program_impl ( self . env , x , path_list , var , environ = self . environ ) <EOL> if ret : break <EOL> self . check_message_1 ( '<STR_LIT>' % '<STR_LIT>' . join ( filename ) ) <EOL> self . log . write ( '<STR_LIT>' % ( filename , path_list , var , ret ) ) <EOL> if ret : <EOL> Utils . pprint ( '<STR_LIT>' , str ( ret ) ) <EOL> else : <EOL> Utils . pprint ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if mandatory : <EOL> self . fatal ( '<STR_LIT>' % filename ) <EOL> if var : <EOL> self . env [ var ] = ret <EOL> return ret <EOL> def cmd_to_list ( self , cmd ) : <EOL> "<STR_LIT>" <EOL> if isinstance ( cmd , str ) and cmd . find ( '<STR_LIT:U+0020>' ) : <EOL> try : <EOL> os . stat ( cmd ) <EOL> except OSError : <EOL> return shlex . split ( cmd ) <EOL> else : <EOL> return [ cmd ] <EOL> return cmd <EOL> def __getattr__ ( self , name ) : <EOL> r = self . __class__ . __dict__ . get ( name , None ) <EOL> if r : return r <EOL> if name and name . startswith ( '<STR_LIT>' ) : <EOL> for k in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> n = name . replace ( '<STR_LIT>' , k ) <EOL> ret = self . __class__ . __dict__ . get ( n , None ) <EOL> if ret : <EOL> def run ( * k , ** kw ) : <EOL> r = ret ( self , * k , ** kw ) <EOL> if not r : <EOL> self . fatal ( '<STR_LIT>' ) <EOL> return r <EOL> return run <EOL> self . fatal ( '<STR_LIT>' % name ) <EOL> def eval_rules ( self , rules ) : <EOL> self . rules = Utils . to_list ( rules ) <EOL> for x in self . rules : <EOL> f = getattr ( self , x ) <EOL> if not f : self . fatal ( "<STR_LIT>" % x ) <EOL> try : <EOL> f ( ) <EOL> except Exception , e : <EOL> ret = self . err_handler ( x , e ) <EOL> if ret == BREAK : <EOL> break <EOL> elif ret == CONTINUE : <EOL> continue <EOL> else : <EOL> self . fatal ( e ) <EOL> def err_handler ( self , fun , error ) : <EOL> pass <EOL> def conf ( f ) : <EOL> "<STR_LIT>" <EOL> setattr ( ConfigurationContext , f . __name__ , f ) <EOL> return f <EOL> def conftest ( f ) : <EOL> "<STR_LIT>" <EOL> ConfigurationContext . tests [ f . __name__ ] = f <EOL> return conf ( f ) </s>
