<s> """<STR_LIT>""" <EOL> import os <EOL> import shutil <EOL> import signal <EOL> import string <EOL> import subprocess <EOL> import sys <EOL> import tempfile <EOL> import SCons <EOL> import SCons . Action <EOL> import SCons . Builder <EOL> import SCons . Scanner <EOL> import SCons . Scanner . Prog <EOL> import blade_util <EOL> import console <EOL> option_verbose = False <EOL> linking_tmp_dir = '<STR_LIT>' <EOL> def generate_python_binary ( target , source , env ) : <EOL> setup_file = '<STR_LIT>' <EOL> if not str ( source [ <NUM_LIT:0> ] ) . endswith ( '<STR_LIT>' ) : <EOL> console . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> str ( target [ <NUM_LIT:0> ] ) ) <EOL> else : <EOL> setup_file = str ( source [ <NUM_LIT:0> ] ) <EOL> init_file = '<STR_LIT>' <EOL> source_index = <NUM_LIT:2> <EOL> if not setup_file : <EOL> source_index = <NUM_LIT:1> <EOL> init_file = str ( source [ <NUM_LIT:0> ] ) <EOL> else : <EOL> init_file = str ( source [ <NUM_LIT:1> ] ) <EOL> init_file_dir = os . path . dirname ( init_file ) <EOL> dep_source_list = [ ] <EOL> for s in source [ source_index : ] : <EOL> dep_source_list . append ( str ( s ) ) <EOL> target_file = str ( target [ <NUM_LIT:0> ] ) <EOL> target_file_dir_list = target_file . split ( '<STR_LIT:/>' ) <EOL> target_profile = target_file_dir_list [ <NUM_LIT:0> ] <EOL> target_dir = '<STR_LIT:/>' . join ( target_file_dir_list [ <NUM_LIT:0> : - <NUM_LIT:1> ] ) <EOL> if not os . path . exists ( target_dir ) : <EOL> os . makedirs ( target_dir ) <EOL> if setup_file : <EOL> shutil . copyfile ( setup_file , os . path . join ( target_dir , '<STR_LIT>' ) ) <EOL> else : <EOL> target_name = os . path . basename ( init_file_dir ) <EOL> if not target_name : <EOL> console . error_exit ( '<STR_LIT>' % str ( target [ <NUM_LIT:0> ] ) ) <EOL> setup_str = """<STR_LIT>""" % target_name <EOL> default_setup_file = open ( os . path . join ( target_dir , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> default_setup_file . write ( setup_str ) <EOL> default_setup_file . close ( ) <EOL> package_dir = os . path . join ( target_profile , init_file_dir ) <EOL> if os . path . exists ( package_dir ) : <EOL> shutil . rmtree ( package_dir , ignore_errors = True ) <EOL> cmd = '<STR_LIT>' % ( init_file_dir , target_dir ) <EOL> p = subprocess . Popen ( <EOL> cmd , <EOL> env = { } , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = True , <EOL> universal_newlines = True ) <EOL> std_out , std_err = p . communicate ( ) <EOL> if p . returncode : <EOL> console . info ( std_out ) <EOL> console . info ( std_err ) <EOL> console . error_exit ( '<STR_LIT>' % ( <EOL> init_file_dir , target_dir ) ) <EOL> return p . returncode <EOL> for f in dep_source_list : <EOL> dep_file_basename = os . path . basename ( f ) <EOL> dep_file_dir = os . path . dirname ( f ) <EOL> sub_dir = '<STR_LIT>' <EOL> sub_dir_list = dep_file_dir . split ( '<STR_LIT:/>' ) <EOL> if len ( sub_dir_list ) > <NUM_LIT:1> : <EOL> sub_dir = '<STR_LIT:/>' . join ( dep_file_dir . split ( '<STR_LIT:/>' ) [ <NUM_LIT:1> : ] ) <EOL> if sub_dir : <EOL> package_sub_dir = os . path . join ( package_dir , sub_dir ) <EOL> if not os . path . exists ( package_sub_dir ) : <EOL> os . makedirs ( package_sub_dir ) <EOL> sub_init_file = os . path . join ( package_sub_dir , '<STR_LIT>' ) <EOL> if not os . path . exists ( sub_init_file ) : <EOL> sub_f = open ( sub_init_file , '<STR_LIT:w>' ) <EOL> sub_f . close ( ) <EOL> shutil . copyfile ( f , os . path . join ( package_sub_dir , dep_file_basename ) ) <EOL> make_egg_cmd = '<STR_LIT>' <EOL> p = subprocess . Popen ( <EOL> make_egg_cmd , <EOL> env = { } , <EOL> cwd = target_dir , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = True , <EOL> universal_newlines = True ) <EOL> std_out , std_err = p . communicate ( ) <EOL> if p . returncode : <EOL> console . info ( std_out ) <EOL> console . info ( std_err ) <EOL> console . error_exit ( '<STR_LIT>' % target_dir ) <EOL> return p . returncode <EOL> return <NUM_LIT:0> <EOL> def generate_resource_index ( target , source , env ) : <EOL> res_source_path = str ( target [ <NUM_LIT:0> ] ) <EOL> res_header_path = str ( target [ <NUM_LIT:1> ] ) <EOL> if not os . path . exists ( os . path . dirname ( res_header_path ) ) : <EOL> os . mkdir ( os . path . dirname ( res_header_path ) ) <EOL> h = open ( res_header_path , '<STR_LIT:w>' ) <EOL> c = open ( res_source_path , '<STR_LIT:w>' ) <EOL> source_path = env [ "<STR_LIT>" ] <EOL> full_name = blade_util . regular_variable_name ( "<STR_LIT>" % ( source_path , env [ "<STR_LIT>" ] ) ) <EOL> guard_name = '<STR_LIT>' % full_name . upper ( ) <EOL> print >> h , '<STR_LIT>' % ( guard_name , guard_name ) <EOL> print >> h , '''<STR_LIT>''' <EOL> res_index_name = '<STR_LIT>' % full_name <EOL> print >> c , '<STR_LIT>' <EOL> print >> c , '<STR_LIT>' % res_header_path <EOL> print >> c , '<STR_LIT>' % res_index_name <EOL> for s in source : <EOL> src = str ( s ) <EOL> var_name = blade_util . regular_variable_name ( src ) <EOL> org_src = blade_util . relative_path ( src , source_path ) <EOL> print >> h , '<STR_LIT>' % org_src <EOL> print >> h , '<STR_LIT>' % ( var_name , s . get_size ( ) ) <EOL> print >> h , '<STR_LIT>' % var_name <EOL> print >> c , '<STR_LIT>' % ( org_src , var_name , s . get_size ( ) ) <EOL> print >> c , '<STR_LIT>' <EOL> print >> c , '<STR_LIT>' % ( res_index_name , len ( source ) ) <EOL> print >> h , '<STR_LIT>' <EOL> print >> h , '<STR_LIT>' % res_index_name <EOL> print >> h , '<STR_LIT>' % res_index_name <EOL> print >> h , '<STR_LIT>' <EOL> print >> h , '<STR_LIT>' % guard_name <EOL> c . close ( ) <EOL> h . close ( ) <EOL> def generate_resource_file ( target , source , env ) : <EOL> src_path = str ( source [ <NUM_LIT:0> ] ) <EOL> new_src_path = str ( target [ <NUM_LIT:0> ] ) <EOL> cmd = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % ( <EOL> src_path , new_src_path ) <EOL> p = subprocess . Popen ( <EOL> cmd , <EOL> env = { } , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = True , <EOL> universal_newlines = True ) <EOL> std_out , std_err = p . communicate ( ) <EOL> if p . returncode or std_err : <EOL> error = '<STR_LIT>' <EOL> if std_err : <EOL> error = error + '<STR_LIT>' + std_err <EOL> console . error_exit ( error ) <EOL> return p . returncode <EOL> def MakeAction ( cmd , cmdstr ) : <EOL> global option_verbose <EOL> if option_verbose : <EOL> return SCons . Action . Action ( cmd ) <EOL> else : <EOL> return SCons . Action . Action ( cmd , cmdstr ) <EOL> _ERRORS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> _WARNINGS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def error_colorize ( message ) : <EOL> colored_message = [ ] <EOL> for t in message . splitlines ( True ) : <EOL> color = '<STR_LIT>' <EOL> if t . strip ( ) . startswith ( '<STR_LIT>' ) : <EOL> color = '<STR_LIT>' <EOL> else : <EOL> for w in _WARNINGS : <EOL> if w in t : <EOL> color = '<STR_LIT>' <EOL> break <EOL> for w in _ERRORS : <EOL> if w in t : <EOL> color = '<STR_LIT>' <EOL> break <EOL> colored_message . append ( console . colors ( color ) ) <EOL> colored_message . append ( t ) <EOL> colored_message . append ( console . colors ( '<STR_LIT:end>' ) ) <EOL> return console . inerasable ( '<STR_LIT>' . join ( colored_message ) ) <EOL> def echospawn ( sh , escape , cmd , args , env ) : <EOL> asciienv = { } <EOL> for key , value in env . iteritems ( ) : <EOL> asciienv [ key ] = str ( value ) <EOL> cmdline = '<STR_LIT:U+0020>' . join ( args ) <EOL> p = subprocess . Popen ( <EOL> cmdline , <EOL> env = asciienv , <EOL> stderr = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> shell = True , <EOL> universal_newlines = True ) <EOL> ( stdout , stderr ) = p . communicate ( ) <EOL> if p . returncode : <EOL> if p . returncode != - signal . SIGINT : <EOL> sys . stdout . write ( error_colorize ( stdout ) ) <EOL> sys . stderr . write ( error_colorize ( stderr ) ) <EOL> else : <EOL> if stderr : <EOL> sys . stdout . write ( error_colorize ( stdout ) ) <EOL> sys . stderr . write ( error_colorize ( stderr ) ) <EOL> else : <EOL> sys . stdout . write ( stdout ) <EOL> return p . returncode <EOL> def _blade_action_postfunc ( closing_message ) : <EOL> """<STR_LIT>""" <EOL> console . info ( closing_message ) <EOL> SCons . SConsign . write ( ) <EOL> def _fast_link_helper ( target , source , env , link_com ) : <EOL> """<STR_LIT>""" <EOL> target_file = str ( target [ <NUM_LIT:0> ] ) <EOL> prefix_str = '<STR_LIT>' % target_file . replace ( '<STR_LIT:/>' , '<STR_LIT:_>' ) . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) <EOL> fd , temporary_file = tempfile . mkstemp ( suffix = '<STR_LIT>' , <EOL> prefix = prefix_str , <EOL> dir = linking_tmp_dir ) <EOL> os . close ( fd ) <EOL> sources = [ ] <EOL> for s in source : <EOL> sources . append ( str ( s ) ) <EOL> link_com_str = link_com . substitute ( <EOL> FL_TARGET = temporary_file , <EOL> FL_SOURCE = '<STR_LIT:U+0020>' . join ( sources ) ) <EOL> p = subprocess . Popen ( <EOL> link_com_str , <EOL> env = os . environ , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = True , <EOL> universal_newlines = True ) <EOL> std_out , std_err = p . communicate ( ) <EOL> if std_out : <EOL> print std_out <EOL> if std_err : <EOL> print std_err <EOL> if p . returncode == <NUM_LIT:0> : <EOL> shutil . move ( temporary_file , target_file ) <EOL> if not os . path . exists ( target_file ) : <EOL> console . warning ( '<STR_LIT>' % target_file ) <EOL> else : <EOL> _blade_action_postfunc ( '<STR_LIT>' ) <EOL> return p . returncode <EOL> def fast_link_sharelib_action ( target , source , env ) : <EOL> link_com = string . Template ( '<STR_LIT>' % ( <EOL> env . subst ( '<STR_LIT>' ) , <EOL> env . subst ( '<STR_LIT>' ) , <EOL> env . subst ( '<STR_LIT>' ) , <EOL> env . subst ( '<STR_LIT>' ) , <EOL> env . subst ( '<STR_LIT>' ) ) ) <EOL> return _fast_link_helper ( target , source , env , link_com ) <EOL> def fast_link_prog_action ( target , source , env ) : <EOL> link_com = string . Template ( '<STR_LIT>' % ( <EOL> env . subst ( '<STR_LIT>' ) , <EOL> env . subst ( '<STR_LIT>' ) , <EOL> env . subst ( '<STR_LIT>' ) , <EOL> env . subst ( '<STR_LIT>' ) , <EOL> env . subst ( '<STR_LIT>' ) ) ) <EOL> return _fast_link_helper ( target , source , env , link_com ) <EOL> def create_fast_link_prog_builder ( env ) : <EOL> """<STR_LIT>""" <EOL> new_link_action = MakeAction ( fast_link_prog_action , '<STR_LIT>' ) <EOL> program = SCons . Builder . Builder ( action = new_link_action , <EOL> emitter = '<STR_LIT>' , <EOL> prefix = '<STR_LIT>' , <EOL> suffix = '<STR_LIT>' , <EOL> src_suffix = '<STR_LIT>' , <EOL> src_builder = '<STR_LIT>' , <EOL> target_scanner = SCons . Scanner . Prog . ProgramScanner ( ) ) <EOL> env [ '<STR_LIT>' ] [ '<STR_LIT>' ] = program <EOL> def create_fast_link_sharelib_builder ( env ) : <EOL> """<STR_LIT>""" <EOL> new_link_actions = [ ] <EOL> new_link_actions . append ( SCons . Defaults . SharedCheck ) <EOL> new_link_actions . append ( MakeAction ( fast_link_sharelib_action , '<STR_LIT>' ) ) <EOL> sharedlib = SCons . Builder . Builder ( action = new_link_actions , <EOL> emitter = '<STR_LIT>' , <EOL> prefix = '<STR_LIT>' , <EOL> suffix = '<STR_LIT>' , <EOL> target_scanner = SCons . Scanner . Prog . ProgramScanner ( ) , <EOL> src_suffix = '<STR_LIT>' , <EOL> src_builder = '<STR_LIT>' ) <EOL> env [ '<STR_LIT>' ] [ '<STR_LIT>' ] = sharedlib <EOL> def create_fast_link_builders ( env ) : <EOL> """<STR_LIT>""" <EOL> acquire_temp_place = "<STR_LIT>" <EOL> p = subprocess . Popen ( <EOL> acquire_temp_place , <EOL> env = os . environ , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = True , <EOL> universal_newlines = True ) <EOL> std_out , std_err = p . communicate ( ) <EOL> if p . returncode : <EOL> console . warning ( '<STR_LIT>' ) <EOL> return <EOL> if not std_out : <EOL> console . warning ( '<STR_LIT>' ) <EOL> return <EOL> global linking_tmp_dir <EOL> usage , linking_tmp_dir = tuple ( std_out . splitlines ( False ) [ <NUM_LIT:0> ] . split ( ) ) <EOL> usage = int ( usage . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) ) <EOL> if usage > <NUM_LIT> : <EOL> console . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> linking_tmp_dir ) <EOL> return <EOL> console . info ( '<STR_LIT>' ) <EOL> create_fast_link_sharelib_builder ( env ) <EOL> create_fast_link_prog_builder ( env ) </s>
