<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import SCons . Environment <EOL> from SCons . Variables import * <EOL> from SCons . Errors import * <EOL> from SCons . Util import is_List , make_path_relative <EOL> from SCons . Warnings import warn , Warning <EOL> import os , imp <EOL> import SCons . Defaults <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def Tag ( env , target , source , * more_tags , ** kw_tags ) : <EOL> """<STR_LIT>""" <EOL> if not target : <EOL> target = source <EOL> first_tag = None <EOL> else : <EOL> first_tag = source <EOL> if first_tag : <EOL> kw_tags [ first_tag [ <NUM_LIT:0> ] ] = '<STR_LIT>' <EOL> if len ( kw_tags ) == <NUM_LIT:0> and len ( more_tags ) == <NUM_LIT:0> : <EOL> raise UserError , "<STR_LIT>" <EOL> for x in more_tags : <EOL> kw_tags [ x ] = '<STR_LIT>' <EOL> if not SCons . Util . is_List ( target ) : <EOL> target = [ target ] <EOL> else : <EOL> target = env . Flatten ( target ) <EOL> for t in target : <EOL> for ( k , v ) in kw_tags . items ( ) : <EOL> if k [ : <NUM_LIT:10> ] != '<STR_LIT>' : <EOL> k = '<STR_LIT>' + k <EOL> setattr ( t , k , v ) <EOL> def Package ( env , target = None , source = None , ** kw ) : <EOL> """<STR_LIT>""" <EOL> if not source : <EOL> source = env . FindInstalledFiles ( ) <EOL> if len ( source ) == <NUM_LIT:0> : <EOL> raise UserError , "<STR_LIT>" <EOL> try : kw [ '<STR_LIT>' ] = env [ '<STR_LIT>' ] <EOL> except KeyError : pass <EOL> if not kw . get ( '<STR_LIT>' ) : <EOL> from SCons . Script import GetOption <EOL> kw [ '<STR_LIT>' ] = GetOption ( '<STR_LIT>' ) <EOL> if kw [ '<STR_LIT>' ] == None : <EOL> if env [ '<STR_LIT>' ] . has_key ( '<STR_LIT>' ) : <EOL> kw [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> elif env [ '<STR_LIT>' ] . has_key ( '<STR_LIT>' ) : <EOL> kw [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> raise UserError , "<STR_LIT>" <EOL> PACKAGETYPE = kw [ '<STR_LIT>' ] <EOL> if not is_List ( PACKAGETYPE ) : <EOL> PACKAGETYPE = string . split ( PACKAGETYPE , '<STR_LIT:U+002C>' ) <EOL> def load_packager ( type ) : <EOL> try : <EOL> file , path , desc = imp . find_module ( type , __path__ ) <EOL> return imp . load_module ( type , file , path , desc ) <EOL> except ImportError , e : <EOL> raise EnvironmentError ( "<STR_LIT>" % ( type , str ( e ) ) ) <EOL> packagers = map ( load_packager , PACKAGETYPE ) <EOL> try : <EOL> if not target : target = [ ] <EOL> size_diff = len ( PACKAGETYPE ) - len ( target ) <EOL> default_name = "<STR_LIT>" <EOL> if size_diff > <NUM_LIT:0> : <EOL> default_target = default_name % kw <EOL> target . extend ( [ default_target ] * size_diff ) <EOL> if not kw . has_key ( '<STR_LIT>' ) : <EOL> kw [ '<STR_LIT>' ] = default_name % kw <EOL> except KeyError , e : <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" % e . args [ <NUM_LIT:0> ] ) <EOL> source = env . arg2nodes ( source , env . fs . Entry ) <EOL> targets = [ ] <EOL> try : <EOL> for packager in packagers : <EOL> t = [ target . pop ( <NUM_LIT:0> ) ] <EOL> t = apply ( packager . package , [ env , t , source ] , kw ) <EOL> targets . extend ( t ) <EOL> assert ( len ( target ) == <NUM_LIT:0> ) <EOL> except KeyError , e : <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" % ( e . args [ <NUM_LIT:0> ] , packager . __name__ ) ) <EOL> except TypeError , e : <EOL> from inspect import getargspec <EOL> args , varargs , varkw , defaults = getargspec ( packager . package ) <EOL> if defaults != None : <EOL> args = args [ : - len ( defaults ) ] <EOL> map ( args . remove , '<STR_LIT>' . split ( ) ) <EOL> args = filter ( lambda x , kw = kw : not kw . has_key ( x ) , args ) <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> raise <EOL> elif len ( args ) == <NUM_LIT:1> : <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" % ( args [ <NUM_LIT:0> ] , packager . __name__ ) ) <EOL> else : <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" % ( "<STR_LIT:U+002CU+0020>" . join ( args ) , packager . __name__ ) ) <EOL> target = env . arg2nodes ( target , env . fs . Entry ) <EOL> targets . extend ( env . Alias ( '<STR_LIT>' , targets ) ) <EOL> return targets <EOL> added = None <EOL> def generate ( env ) : <EOL> from SCons . Script import AddOption <EOL> global added <EOL> if not added : <EOL> added = <NUM_LIT:1> <EOL> AddOption ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> default = None , <EOL> type = "<STR_LIT:string>" , <EOL> action = "<STR_LIT:store>" , <EOL> help = '<STR_LIT>' ) <EOL> try : <EOL> env [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> env [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> env [ '<STR_LIT>' ] [ '<STR_LIT>' ] = Package <EOL> env [ '<STR_LIT>' ] [ '<STR_LIT>' ] = Tag <EOL> def exists ( env ) : <EOL> return <NUM_LIT:1> <EOL> def options ( opts ) : <EOL> opts . AddVariables ( <EOL> EnumVariable ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> None , allowed_values = map ( str , __all__ ) , <EOL> ignorecase = <NUM_LIT:2> <EOL> ) <EOL> ) <EOL> def copy_attr ( f1 , f2 ) : <EOL> """<STR_LIT>""" <EOL> copyit = lambda x , f2 = f2 : not hasattr ( f2 , x ) and x [ : <NUM_LIT:10> ] == '<STR_LIT>' <EOL> pattrs = filter ( copyit , dir ( f1 ) ) <EOL> for attr in pattrs : <EOL> setattr ( f2 , attr , getattr ( f1 , attr ) ) <EOL> def putintopackageroot ( target , source , env , pkgroot , honor_install_location = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if SCons . Util . is_String ( pkgroot ) : pkgroot = env . Dir ( pkgroot ) <EOL> if not SCons . Util . is_List ( source ) : source = [ source ] <EOL> new_source = [ ] <EOL> for file in source : <EOL> if SCons . Util . is_String ( file ) : file = env . File ( file ) <EOL> if file . is_under ( pkgroot ) : <EOL> new_source . append ( file ) <EOL> else : <EOL> if hasattr ( file , '<STR_LIT>' ) and honor_install_location : <EOL> new_name = make_path_relative ( file . PACKAGING_INSTALL_LOCATION ) <EOL> else : <EOL> new_name = make_path_relative ( file . get_path ( ) ) <EOL> new_file = pkgroot . File ( new_name ) <EOL> new_file = env . CopyAs ( new_file , file ) [ <NUM_LIT:0> ] <EOL> copy_attr ( file , new_file ) <EOL> new_source . append ( new_file ) <EOL> return ( target , new_source ) <EOL> def stripinstallbuilder ( target , source , env ) : <EOL> """<STR_LIT>""" <EOL> def has_no_install_location ( file ) : <EOL> return not ( file . has_builder ( ) and hasattr ( file . builder , '<STR_LIT:name>' ) and ( file . builder . name == "<STR_LIT>" or file . builder . name == "<STR_LIT>" ) ) <EOL> if len ( filter ( has_no_install_location , source ) ) : <EOL> warn ( Warning , "<STR_LIT>" ) <EOL> n_source = [ ] <EOL> for s in source : <EOL> if has_no_install_location ( s ) : <EOL> n_source . append ( s ) <EOL> else : <EOL> for ss in s . sources : <EOL> n_source . append ( ss ) <EOL> copy_attr ( s , ss ) <EOL> setattr ( ss , '<STR_LIT>' , s . get_path ( ) ) <EOL> return ( target , n_source ) </s>
