<s> """<STR_LIT>""" <EOL> import os <EOL> import traceback <EOL> import build_rules <EOL> import console <EOL> from blade_util import relative_path <EOL> import cc_targets <EOL> import cu_targets <EOL> import gen_rule_target <EOL> import java_jar_target <EOL> import java_targets <EOL> import lex_yacc_target <EOL> import proto_library_target <EOL> import py_targets <EOL> import resource_library_target <EOL> import swig_library_target <EOL> import thrift_library <EOL> import fbthrift_library <EOL> class TargetAttributes ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , options ) : <EOL> self . _options = options <EOL> @ property <EOL> def bits ( self ) : <EOL> return int ( self . _options . m ) <EOL> @ property <EOL> def arch ( self ) : <EOL> if self . _options . m == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def is_debug ( self ) : <EOL> return self . _options . profile == '<STR_LIT>' <EOL> build_target = None <EOL> def _find_dir_depender ( dir , blade ) : <EOL> """<STR_LIT>""" <EOL> target_database = blade . get_target_database ( ) <EOL> for key in target_database : <EOL> for dkey in target_database [ key ] . expanded_deps : <EOL> if dkey [ <NUM_LIT:0> ] == dir : <EOL> return '<STR_LIT>' % ( target_database [ key ] . path , <EOL> target_database [ key ] . name ) <EOL> return None <EOL> def _report_not_exist ( source_dir , path , blade ) : <EOL> """<STR_LIT>""" <EOL> depender = _find_dir_depender ( source_dir , blade ) <EOL> if depender : <EOL> console . error_exit ( '<STR_LIT>' % ( path , depender ) ) <EOL> else : <EOL> console . error_exit ( '<STR_LIT>' % path ) <EOL> def enable_if ( cond , true_value , false_value = None ) : <EOL> """<STR_LIT>""" <EOL> if cond : <EOL> ret = true_value <EOL> else : <EOL> ret = false_value <EOL> if ret is None : <EOL> ret = [ ] <EOL> return ret <EOL> build_rules . register_function ( enable_if ) <EOL> IGNORE_IF_FAIL = <NUM_LIT:0> <EOL> WARN_IF_FAIL = <NUM_LIT:1> <EOL> ABORT_IF_FAIL = <NUM_LIT:2> <EOL> def _load_build_file ( source_dir , action_if_fail , processed_source_dirs , blade ) : <EOL> """<STR_LIT>""" <EOL> global build_target <EOL> if build_target is None : <EOL> build_target = TargetAttributes ( blade . get_options ( ) ) <EOL> build_rules . register_variable ( '<STR_LIT>' , build_target ) <EOL> source_dir = os . path . normpath ( source_dir ) <EOL> if source_dir in processed_source_dirs or source_dir == '<STR_LIT:#>' : <EOL> return <EOL> processed_source_dirs . add ( source_dir ) <EOL> if not os . path . exists ( source_dir ) : <EOL> _report_not_exist ( source_dir , source_dir , blade ) <EOL> old_current_source_path = blade . get_current_source_path ( ) <EOL> blade . set_current_source_path ( source_dir ) <EOL> build_file = os . path . join ( source_dir , '<STR_LIT>' ) <EOL> if os . path . exists ( build_file ) : <EOL> try : <EOL> execfile ( build_file , build_rules . get_all ( ) , None ) <EOL> except SystemExit : <EOL> console . error_exit ( '<STR_LIT>' % build_file ) <EOL> except : <EOL> console . error_exit ( '<STR_LIT>' % ( <EOL> build_file , traceback . format_exc ( ) ) ) <EOL> else : <EOL> if action_if_fail == ABORT_IF_FAIL : <EOL> _report_not_exist ( source_dir , build_file , blade ) <EOL> blade . set_current_source_path ( old_current_source_path ) <EOL> def _find_depender ( dkey , blade ) : <EOL> """<STR_LIT>""" <EOL> target_database = blade . get_target_database ( ) <EOL> for key in target_database : <EOL> if dkey in target_database [ key ] . expanded_deps : <EOL> return '<STR_LIT>' % ( target_database [ key ] . path , <EOL> target_database [ key ] . name ) <EOL> return None <EOL> def load_targets ( target_ids , working_dir , blade_root_dir , blade ) : <EOL> """<STR_LIT>""" <EOL> target_database = blade . get_target_database ( ) <EOL> cited_targets = set ( ) <EOL> related_targets = { } <EOL> source_dirs = [ ] <EOL> processed_source_dirs = set ( ) <EOL> direct_targets = [ ] <EOL> all_command_targets = [ ] <EOL> for target_id in target_ids : <EOL> if target_id . find ( '<STR_LIT::>' ) == - <NUM_LIT:1> : <EOL> source_dir , target_name = target_id , '<STR_LIT:*>' <EOL> else : <EOL> source_dir , target_name = target_id . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> source_dir = relative_path ( os . path . join ( working_dir , source_dir ) , <EOL> blade_root_dir ) <EOL> if target_name != '<STR_LIT:*>' and target_name != '<STR_LIT>' : <EOL> cited_targets . add ( ( source_dir , target_name ) ) <EOL> elif source_dir . endswith ( '<STR_LIT>' ) : <EOL> source_dir = source_dir [ : - <NUM_LIT:3> ] <EOL> if not source_dir : <EOL> source_dir = '<STR_LIT>' <EOL> source_dirs . append ( ( source_dir , WARN_IF_FAIL ) ) <EOL> for root , dirs , files in os . walk ( source_dir ) : <EOL> dirs [ : ] = [ d for d in dirs if not d . startswith ( '<STR_LIT:.>' ) ] <EOL> for d in dirs : <EOL> source_dirs . append ( ( os . path . join ( root , d ) , IGNORE_IF_FAIL ) ) <EOL> else : <EOL> source_dirs . append ( ( source_dir , ABORT_IF_FAIL ) ) <EOL> direct_targets = list ( cited_targets ) <EOL> for source_dir , action_if_fail in source_dirs : <EOL> _load_build_file ( source_dir , <EOL> action_if_fail , <EOL> processed_source_dirs , <EOL> blade ) <EOL> for key in target_database : <EOL> cited_targets . add ( key ) <EOL> all_command_targets = list ( cited_targets ) <EOL> while cited_targets : <EOL> source_dir , target_name = cited_targets . pop ( ) <EOL> target_id = ( source_dir , target_name ) <EOL> if target_id in related_targets : <EOL> continue <EOL> _load_build_file ( source_dir , <EOL> ABORT_IF_FAIL , <EOL> processed_source_dirs , <EOL> blade ) <EOL> if target_id not in target_database : <EOL> console . error_exit ( '<STR_LIT>' % ( <EOL> _find_depender ( target_id , blade ) , source_dir , target_name ) ) <EOL> related_targets [ target_id ] = target_database [ target_id ] <EOL> for key in related_targets [ target_id ] . expanded_deps : <EOL> if key not in related_targets : <EOL> cited_targets . add ( key ) <EOL> for path , name in related_targets : <EOL> root_dir = path . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] . strip ( ) <EOL> if root_dir not in blade . svn_root_dirs and '<STR_LIT:#>' not in root_dir : <EOL> blade . svn_root_dirs . append ( root_dir ) <EOL> return direct_targets , all_command_targets , related_targets <EOL> def find_blade_root_dir ( working_dir ) : <EOL> """<STR_LIT>""" <EOL> blade_root_dir = working_dir <EOL> if blade_root_dir . endswith ( '<STR_LIT:/>' ) : <EOL> blade_root_dir = blade_root_dir [ : - <NUM_LIT:1> ] <EOL> while blade_root_dir and blade_root_dir != '<STR_LIT:/>' : <EOL> if os . path . isfile ( os . path . join ( blade_root_dir , '<STR_LIT>' ) ) : <EOL> break <EOL> blade_root_dir = os . path . dirname ( blade_root_dir ) <EOL> if not blade_root_dir or blade_root_dir == '<STR_LIT:/>' : <EOL> console . error_exit ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return blade_root_dir </s>
