<s> """<STR_LIT>""" <EOL> import os <EOL> import string <EOL> import configparse <EOL> import console <EOL> from blade_util import var_to_list <EOL> class Target ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> name , <EOL> target_type , <EOL> srcs , <EOL> deps , <EOL> blade , <EOL> kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . blade = blade <EOL> self . build_path = self . blade . get_build_path ( ) <EOL> current_source_path = self . blade . get_current_source_path ( ) <EOL> self . target_database = self . blade . get_target_database ( ) <EOL> self . key = ( current_source_path , name ) <EOL> self . fullname = '<STR_LIT>' % self . key <EOL> self . name = name <EOL> self . path = current_source_path <EOL> self . type = target_type <EOL> self . srcs = srcs <EOL> self . deps = [ ] <EOL> self . expanded_deps = [ ] <EOL> self . data = { } <EOL> self . _check_name ( ) <EOL> self . _check_kwargs ( kwargs ) <EOL> self . _check_srcs ( ) <EOL> self . _check_deps_in_build_file ( deps ) <EOL> self . _init_target_deps ( deps ) <EOL> self . scons_rule_buf = [ ] <EOL> self . __cached_generate_header_files = None <EOL> def _clone_env ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _write_rule ( '<STR_LIT>' % self . _env_name ( ) ) <EOL> def _prepare_to_generate_rule ( self ) : <EOL> """<STR_LIT>""" <EOL> console . error_exit ( '<STR_LIT>' ) <EOL> def _check_name ( self ) : <EOL> if '<STR_LIT:/>' in self . name : <EOL> console . error_exit ( '<STR_LIT>' % ( <EOL> self . path , self . name ) ) <EOL> def _check_kwargs ( self , kwargs ) : <EOL> if kwargs : <EOL> console . error_exit ( '<STR_LIT>' % ( <EOL> self . path , self . name , kwargs ) ) <EOL> __src_target_map = { } <EOL> def _check_srcs ( self ) : <EOL> """<STR_LIT>""" <EOL> dups = [ ] <EOL> srcset = set ( ) <EOL> for s in self . srcs : <EOL> if s in srcset : <EOL> dups . append ( s ) <EOL> else : <EOL> srcset . add ( s ) <EOL> if dups : <EOL> console . error_exit ( '<STR_LIT>' % ( <EOL> self . path , self . name , dups ) ) <EOL> config = configparse . blade_config . get_config ( '<STR_LIT>' ) <EOL> action = config . get ( '<STR_LIT>' ) <EOL> allow_dup_src_type_list = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for s in self . srcs : <EOL> if '<STR_LIT:..>' in s or s . startswith ( '<STR_LIT:/>' ) : <EOL> console . error_exit ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( self . path , self . name , s ) ) <EOL> src_key = os . path . normpath ( '<STR_LIT>' % ( self . path , s ) ) <EOL> src_value = '<STR_LIT>' % ( <EOL> self . type , self . path , self . name ) <EOL> if src_key in Target . __src_target_map : <EOL> value_existed = Target . __src_target_map [ src_key ] <EOL> if ( value_existed != src_value and <EOL> not ( value_existed . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:0> ] in allow_dup_src_type_list and <EOL> self . type in allow_dup_src_type_list ) ) : <EOL> message = '<STR_LIT>' % ( <EOL> s , value_existed , src_value ) <EOL> if action == '<STR_LIT:error>' : <EOL> console . error_exit ( message ) <EOL> elif action == '<STR_LIT>' : <EOL> console . warning ( message ) <EOL> elif action == '<STR_LIT:none>' or not action : <EOL> pass <EOL> Target . __src_target_map [ src_key ] = src_value <EOL> def _add_hardcode_library ( self , hardcode_dep_list ) : <EOL> """<STR_LIT>""" <EOL> for dep in hardcode_dep_list : <EOL> dkey = self . _convert_string_to_target_helper ( dep ) <EOL> if dkey [ <NUM_LIT:0> ] == '<STR_LIT:#>' : <EOL> self . _add_system_library ( dkey , dep ) <EOL> if dkey not in self . expanded_deps : <EOL> self . expanded_deps . append ( dkey ) <EOL> def _add_system_library ( self , key , name ) : <EOL> """<STR_LIT>""" <EOL> if key not in self . target_database : <EOL> lib = SystemLibrary ( name , self . blade ) <EOL> self . blade . register_target ( lib ) <EOL> def _init_target_deps ( self , deps ) : <EOL> """<STR_LIT>""" <EOL> for d in deps : <EOL> if d [ <NUM_LIT:0> ] == '<STR_LIT::>' : <EOL> dkey = ( os . path . normpath ( self . path ) , d [ <NUM_LIT:1> : ] ) <EOL> elif d . startswith ( '<STR_LIT>' ) : <EOL> if not '<STR_LIT::>' in d : <EOL> raise Exception , '<STR_LIT>' % ( <EOL> self . path , self . name ) <EOL> ( path , lib ) = d [ <NUM_LIT:2> : ] . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> dkey = ( os . path . normpath ( path ) , lib ) <EOL> elif d . startswith ( '<STR_LIT:#>' ) : <EOL> dkey = ( '<STR_LIT:#>' , d [ <NUM_LIT:1> : ] ) <EOL> self . _add_system_library ( dkey , d ) <EOL> else : <EOL> if not '<STR_LIT::>' in d : <EOL> raise Exception , '<STR_LIT>' % ( <EOL> self . path , self . name ) <EOL> ( path , lib ) = d . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if '<STR_LIT:..>' in path : <EOL> raise Exception , "<STR_LIT>" <EOL> dkey = ( os . path . normpath ( '<STR_LIT>' % ( <EOL> self . path , path ) ) , lib ) <EOL> if dkey not in self . expanded_deps : <EOL> self . expanded_deps . append ( dkey ) <EOL> if dkey not in self . deps : <EOL> self . deps . append ( dkey ) <EOL> def _check_deps_in_build_file ( self , deps ) : <EOL> """<STR_LIT>""" <EOL> name = self . name <EOL> for dep in deps : <EOL> if not ( dep . startswith ( '<STR_LIT::>' ) or dep . startswith ( '<STR_LIT:#>' ) or <EOL> dep . startswith ( '<STR_LIT>' ) or dep . startswith ( '<STR_LIT>' ) ) : <EOL> console . error_exit ( '<STR_LIT>' % ( <EOL> self . path , name , dep ) ) <EOL> if dep . count ( '<STR_LIT::>' ) > <NUM_LIT:1> : <EOL> console . error_exit ( '<STR_LIT>' % <EOL> ( self . path , name , dep ) ) <EOL> def _check_deprecated_deps ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _regular_variable_name ( self , var ) : <EOL> """<STR_LIT>""" <EOL> return var . translate ( string . maketrans ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def _generate_variable_name ( self , path = '<STR_LIT>' , name = '<STR_LIT>' , suffix = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> suffix_str = '<STR_LIT>' <EOL> if suffix : <EOL> suffix_str = '<STR_LIT>' % suffix <EOL> return '<STR_LIT>' % ( self . _regular_variable_name ( path ) , <EOL> self . _regular_variable_name ( name ) , <EOL> suffix_str ) <EOL> def _env_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % self . _generate_variable_name ( self . path , <EOL> self . name ) <EOL> def __fill_path_name ( self , path , name ) : <EOL> """<STR_LIT>""" <EOL> if not path : <EOL> path = self . path <EOL> if not name : <EOL> name = self . name <EOL> return path , name <EOL> def _target_file_path ( self , path = '<STR_LIT>' , name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> new_path , new_name = self . __fill_path_name ( path , name ) <EOL> return os . path . join ( self . build_path , new_path , new_name ) <EOL> def __generate_header_files ( self ) : <EOL> for dkey in self . deps : <EOL> dep = self . target_database [ dkey ] <EOL> if dep . _generate_header_files ( ) : <EOL> return True <EOL> return False <EOL> def _generate_header_files ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __cached_generate_header_files is None : <EOL> self . __cached_generate_header_files = self . __generate_header_files ( ) <EOL> return self . __cached_generate_header_files <EOL> def _write_rule ( self , rule ) : <EOL> """<STR_LIT>""" <EOL> self . scons_rule_buf . append ( '<STR_LIT>' % rule ) <EOL> def scons_rules ( self ) : <EOL> """<STR_LIT>""" <EOL> console . error_exit ( '<STR_LIT>' % self . type ) <EOL> def get_rules ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . scons_rule_buf <EOL> def _convert_string_to_target_helper ( self , target_string ) : <EOL> """<STR_LIT>""" <EOL> bad_format = False <EOL> if target_string : <EOL> if target_string . startswith ( '<STR_LIT:#>' ) : <EOL> return ( '<STR_LIT:#>' , target_string [ <NUM_LIT:1> : ] ) <EOL> elif target_string . find ( '<STR_LIT::>' ) != - <NUM_LIT:1> : <EOL> path , name = target_string . split ( '<STR_LIT::>' ) <EOL> path = path . strip ( ) <EOL> if path . startswith ( '<STR_LIT>' ) : <EOL> path = path [ <NUM_LIT:2> : ] <EOL> return ( path , name . strip ( ) ) <EOL> else : <EOL> bad_format = True <EOL> else : <EOL> bad_format = True <EOL> if bad_format : <EOL> console . error_exit ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> target_string ) <EOL> class SystemLibrary ( Target ) : <EOL> def __init__ ( self , name , blade ) : <EOL> name = name [ <NUM_LIT:1> : ] <EOL> Target . __init__ ( self , name , '<STR_LIT>' , [ ] , [ ] , blade , { } ) <EOL> self . key = ( '<STR_LIT:#>' , name ) <EOL> self . fullname = '<STR_LIT>' % self . key <EOL> self . path = '<STR_LIT:#>' </s>
