<s> """<STR_LIT>""" <EOL> import os <EOL> import blade <EOL> import console <EOL> import build_rules <EOL> import java_jar_target <EOL> import py_targets <EOL> from cc_targets import CcTarget <EOL> class SwigLibrary ( CcTarget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> name , <EOL> srcs , <EOL> deps , <EOL> warning , <EOL> java_package , <EOL> java_lib_packed , <EOL> optimize , <EOL> extra_swigflags , <EOL> blade , <EOL> kwargs ) : <EOL> """<STR_LIT>""" <EOL> CcTarget . __init__ ( self , <EOL> name , <EOL> '<STR_LIT>' , <EOL> srcs , <EOL> deps , <EOL> warning , <EOL> [ ] , [ ] , [ ] , optimize , extra_swigflags , [ ] , <EOL> blade , <EOL> kwargs ) <EOL> self . data [ '<STR_LIT>' ] = warning <EOL> self . data [ '<STR_LIT>' ] = java_package <EOL> self . data [ '<STR_LIT>' ] = java_lib_packed <EOL> self . data [ '<STR_LIT>' ] = [ ] <EOL> self . data [ '<STR_LIT>' ] = [ ] <EOL> self . data [ '<STR_LIT>' ] = [ ] <EOL> self . data [ '<STR_LIT>' ] = [ ] <EOL> scons_platform = self . blade . get_scons_platform ( ) <EOL> self . php_inc_list = scons_platform . get_php_include ( ) <EOL> self . options = self . blade . get_options ( ) <EOL> def _pyswig_gen_python_file ( self , path , src ) : <EOL> """<STR_LIT>""" <EOL> swig_name = src [ : - <NUM_LIT:2> ] <EOL> return os . path . join ( self . build_path , path , '<STR_LIT>' % swig_name ) <EOL> def _pyswig_gen_file ( self , path , src ) : <EOL> """<STR_LIT>""" <EOL> swig_name = src [ : - <NUM_LIT:2> ] <EOL> return os . path . join ( self . build_path , path , '<STR_LIT>' % swig_name ) <EOL> def _javaswig_gen_file ( self , path , src ) : <EOL> """<STR_LIT>""" <EOL> swig_name = src [ : - <NUM_LIT:2> ] <EOL> return os . path . join ( self . build_path , path , '<STR_LIT>' % swig_name ) <EOL> def _phpswig_gen_file ( self , path , src ) : <EOL> """<STR_LIT>""" <EOL> swig_name = src [ : - <NUM_LIT:2> ] <EOL> return os . path . join ( self . build_path , path , '<STR_LIT>' % swig_name ) <EOL> def _swig_extract_dependency_files ( self , src ) : <EOL> dep = [ ] <EOL> for line in open ( src ) : <EOL> if line . startswith ( '<STR_LIT>' ) or line . startswith ( '<STR_LIT>' ) : <EOL> line = line . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:1> ] . strip ( """<STR_LIT>""" ) <EOL> if not ( '<STR_LIT:<>' in line or line in dep ) : <EOL> dep . append ( line ) <EOL> return [ i for i in dep if os . path . exists ( i ) ] <EOL> def _swig_library_rules_py ( self ) : <EOL> """<STR_LIT>""" <EOL> env_name = self . _env_name ( ) <EOL> var_name = self . _generate_variable_name ( self . path , <EOL> self . name , <EOL> '<STR_LIT>' ) <EOL> obj_names_py = [ ] <EOL> flag_list = [ ] <EOL> warning = self . data . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> flag_list . append ( ( '<STR_LIT>' , warning ) ) <EOL> pyswig_flags = '<STR_LIT>' <EOL> for flag in flag_list : <EOL> if flag [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> if flag [ <NUM_LIT:1> ] == '<STR_LIT:yes>' : <EOL> pyswig_flags += '<STR_LIT>' <EOL> builder_name = '<STR_LIT>' % var_name <EOL> builder_alias = '<STR_LIT>' % var_name <EOL> swig_bld_cmd = '<STR_LIT>' % ( <EOL> pyswig_flags , self . build_path ) <EOL> self . _write_rule ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> builder_name , swig_bld_cmd ) ) <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , builder_alias , builder_name ) ) <EOL> self . _setup_cc_flags ( ) <EOL> dep_files = [ ] <EOL> dep_files_map = { } <EOL> for src in self . srcs : <EOL> pyswig_src = self . _pyswig_gen_file ( self . path , src ) <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , <EOL> builder_alias , <EOL> pyswig_src , <EOL> os . path . join ( self . path , src ) ) ) <EOL> self . data [ '<STR_LIT>' ] . append ( <EOL> self . _pyswig_gen_python_file ( self . path , src ) ) <EOL> obj_name_py = '<STR_LIT>' % self . _generate_variable_name ( <EOL> self . path , src , '<STR_LIT>' ) <EOL> obj_names_py . append ( obj_name_py ) <EOL> self . _write_rule ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( obj_name_py , <EOL> env_name , <EOL> pyswig_src , <EOL> pyswig_src ) ) <EOL> self . data [ '<STR_LIT>' ] . append ( obj_name_py ) <EOL> dep_files = self . _swig_extract_dependency_files ( <EOL> os . path . join ( self . path , src ) ) <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , <EOL> pyswig_src , <EOL> dep_files ) ) <EOL> dep_files_map [ os . path . join ( self . path , src ) ] = dep_files <EOL> objs_name = self . _objs_name ( ) <EOL> objs_name_py = '<STR_LIT>' % objs_name <EOL> self . _write_rule ( '<STR_LIT>' % ( objs_name_py , '<STR_LIT:U+002C>' . join ( obj_names_py ) ) ) <EOL> target_path = self . _target_file_path ( ) <EOL> target_lib = os . path . basename ( target_path ) <EOL> if not target_lib . startswith ( '<STR_LIT:_>' ) : <EOL> target_lib = '<STR_LIT>' % target_lib <EOL> target_path_py = os . path . join ( os . path . dirname ( target_path ) , target_lib ) <EOL> ( link_all_symbols_lib_list , <EOL> lib_str , <EOL> whole_link_flags ) = self . _get_static_deps_lib_list ( ) <EOL> if whole_link_flags : <EOL> self . _write_rule ( <EOL> '<STR_LIT>' % ( env_name , whole_link_flags ) ) <EOL> if self . srcs or self . expanded_deps : <EOL> self . _write_rule ( '<STR_LIT>' <EOL> % ( var_name , <EOL> env_name , <EOL> target_path_py , <EOL> objs_name_py , <EOL> lib_str ) ) <EOL> self . data [ '<STR_LIT>' ] . append ( '<STR_LIT>' % target_path_py ) <EOL> self . data [ '<STR_LIT>' ] . append ( var_name ) <EOL> if link_all_symbols_lib_list : <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , var_name , '<STR_LIT:U+002CU+0020>' . join ( link_all_symbols_lib_list ) ) ) <EOL> return dep_files_map <EOL> def _swig_library_rules_java ( self , dep_files_map ) : <EOL> """<STR_LIT>""" <EOL> env_name = self . _env_name ( ) <EOL> var_name = self . _generate_variable_name ( self . path , <EOL> self . name , <EOL> '<STR_LIT>' ) <EOL> self . _write_rule ( '<STR_LIT>' % env_name ) <EOL> build_jar = self . data . get ( '<STR_LIT>' ) <EOL> flag_list = [ ] <EOL> flag_list . append ( ( '<STR_LIT>' , self . data . get ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> flag_list . append ( ( '<STR_LIT>' , self . data . get ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> java_lib_packed = self . data . get ( '<STR_LIT>' , False ) <EOL> flag_list . append ( ( '<STR_LIT>' , java_lib_packed ) ) <EOL> javaswig_flags = '<STR_LIT>' <EOL> depend_outdir = False <EOL> out_dir = os . path . join ( self . build_path , self . path ) <EOL> for flag in flag_list : <EOL> if flag [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> if flag [ <NUM_LIT:1> ] == '<STR_LIT:yes>' : <EOL> javaswig_flags += '<STR_LIT>' <EOL> if flag [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> if flag [ <NUM_LIT:1> ] : <EOL> java_lib_packed = True <EOL> if flag [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> if flag [ <NUM_LIT:1> ] : <EOL> javaswig_flags += '<STR_LIT>' % flag [ <NUM_LIT:1> ] <EOL> package_dir = flag [ <NUM_LIT:1> ] . replace ( '<STR_LIT:.>' , '<STR_LIT:/>' ) <EOL> out_dir = os . path . join ( self . build_path , <EOL> self . path , package_dir ) <EOL> out_dir_dummy = os . path . join ( out_dir , '<STR_LIT>' ) <EOL> javaswig_flags += '<STR_LIT>' % out_dir <EOL> swig_outdir_cmd = '<STR_LIT>' % var_name <EOL> if not os . path . exists ( out_dir ) : <EOL> depend_outdir = True <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> swig_outdir_cmd , <EOL> env_name , <EOL> out_dir_dummy , <EOL> out_dir ) ) <EOL> self . data [ '<STR_LIT>' ] . append ( swig_outdir_cmd ) <EOL> if build_jar : <EOL> self . data [ '<STR_LIT>' ] = ( <EOL> out_dir , <EOL> os . path . join ( self . build_path , self . path ) , <EOL> self . name ) <EOL> builder_name = '<STR_LIT>' % var_name <EOL> builder_alias = '<STR_LIT>' % var_name <EOL> swig_bld_cmd = '<STR_LIT>' % ( <EOL> javaswig_flags , self . build_path ) <EOL> self . _write_rule ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> builder_name , swig_bld_cmd ) ) <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , builder_alias , builder_name ) ) <EOL> self . _swig_library_rules_java_helper ( depend_outdir , build_jar , <EOL> java_lib_packed , out_dir , <EOL> builder_alias , dep_files_map ) <EOL> def _swig_library_rules_java_helper ( self , <EOL> dep_outdir , <EOL> java_build_jar , <EOL> lib_packed , <EOL> out_dir , <EOL> builder_alias , <EOL> dep_files_map ) : <EOL> env_name = self . _env_name ( ) <EOL> var_name = self . _generate_variable_name ( self . path , <EOL> self . name , <EOL> '<STR_LIT>' ) <EOL> depend_outdir = dep_outdir <EOL> build_jar = java_build_jar <EOL> java_lib_packed = lib_packed <EOL> env_name = self . _env_name ( ) <EOL> out_dir_dummy = os . path . join ( out_dir , '<STR_LIT>' ) <EOL> obj_names_java = [ ] <EOL> scons_platform = self . blade . get_scons_platform ( ) <EOL> java_includes = scons_platform . get_java_include ( ) <EOL> if java_includes : <EOL> self . _write_rule ( '<STR_LIT>' % ( env_name , java_includes ) ) <EOL> dep_files = [ ] <EOL> for src in self . srcs : <EOL> javaswig_src = self . _javaswig_gen_file ( self . path , src ) <EOL> src_basename = os . path . basename ( src ) <EOL> javaswig_var = '<STR_LIT>' % ( <EOL> var_name , self . _regular_variable_name ( src_basename ) ) <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> javaswig_var , <EOL> env_name , <EOL> builder_alias , <EOL> javaswig_src , <EOL> os . path . join ( self . path , src ) ) ) <EOL> self . data [ '<STR_LIT>' ] . append ( javaswig_src ) <EOL> if depend_outdir : <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , <EOL> javaswig_var , <EOL> out_dir_dummy ) ) <EOL> self . data [ '<STR_LIT>' ] . append ( javaswig_var ) <EOL> obj_name_java = '<STR_LIT>' % self . _generate_variable_name ( <EOL> self . path , src , '<STR_LIT>' ) <EOL> obj_names_java . append ( obj_name_java ) <EOL> self . _write_rule ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> obj_name_java , <EOL> env_name , <EOL> javaswig_src , <EOL> javaswig_src ) ) <EOL> dep_key = os . path . join ( self . path , src ) <EOL> if dep_key in dep_files_map : <EOL> dep_files = dep_files_map [ dep_key ] <EOL> else : <EOL> dep_files = self . _swig_extract_dependency_files ( dep_key ) <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , <EOL> javaswig_src , <EOL> dep_files ) ) <EOL> objs_name = self . _objs_name ( ) <EOL> objs_name_java = '<STR_LIT>' % objs_name <EOL> self . _write_rule ( '<STR_LIT>' % ( objs_name_java , <EOL> '<STR_LIT:U+002C>' . join ( obj_names_java ) ) ) <EOL> target_path_java = '<STR_LIT>' % self . _target_file_path ( ) <EOL> ( link_all_symbols_lib_list , <EOL> lib_str , <EOL> whole_link_flags ) = self . _get_static_deps_lib_list ( ) <EOL> if self . srcs or self . expanded_deps : <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> var_name , <EOL> env_name , <EOL> target_path_java , <EOL> objs_name_java , <EOL> lib_str ) ) <EOL> if link_all_symbols_lib_list : <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , var_name , '<STR_LIT:U+002CU+0020>' . join ( link_all_symbols_lib_list ) ) ) <EOL> if build_jar and java_lib_packed : <EOL> lib_dir = os . path . dirname ( target_path_java ) <EOL> lib_name = os . path . basename ( target_path_java ) <EOL> lib_name = '<STR_LIT>' % lib_name <EOL> self . data [ '<STR_LIT>' ] = ( <EOL> os . path . join ( lib_dir , lib_name ) , self . name ) <EOL> def _swig_library_rules_php ( self , dep_files_map ) : <EOL> env_name = self . _env_name ( ) <EOL> var_name = self . _generate_variable_name ( self . path , self . name ) <EOL> obj_names_php = [ ] <EOL> flag_list = [ ] <EOL> warning = self . data . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> flag_list . append ( ( '<STR_LIT>' , warning ) ) <EOL> self . phpswig_flags = '<STR_LIT>' <EOL> phpswig_flags = '<STR_LIT>' <EOL> for flag in flag_list : <EOL> if flag [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> if flag [ <NUM_LIT:1> ] == '<STR_LIT:yes>' : <EOL> phpswig_flags += '<STR_LIT>' <EOL> self . phpswig_flags = phpswig_flags <EOL> builder_name = '<STR_LIT>' % self . _regular_variable_name ( self . name ) <EOL> builder_alias = '<STR_LIT>' % self . _regular_variable_name ( self . name ) <EOL> swig_bld_cmd = '<STR_LIT>' % ( <EOL> phpswig_flags , self . build_path ) <EOL> self . _write_rule ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> builder_name , swig_bld_cmd ) ) <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , builder_alias , builder_name ) ) <EOL> if self . php_inc_list : <EOL> self . _write_rule ( '<STR_LIT>' % ( env_name , self . php_inc_list ) ) <EOL> dep_files = [ ] <EOL> dep_files_map = { } <EOL> for src in self . srcs : <EOL> phpswig_src = self . _phpswig_gen_file ( self . path , src ) <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , <EOL> builder_alias , <EOL> phpswig_src , <EOL> os . path . join ( self . path , src ) ) ) <EOL> obj_name_php = '<STR_LIT>' % self . _generate_variable_name ( <EOL> self . path , src , '<STR_LIT>' ) <EOL> obj_names_php . append ( obj_name_php ) <EOL> self . _write_rule ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( obj_name_php , <EOL> env_name , <EOL> phpswig_src , <EOL> phpswig_src ) ) <EOL> dep_key = os . path . join ( self . path , src ) <EOL> if dep_key in dep_files_map : <EOL> dep_files = dep_files_map [ dep_key ] <EOL> else : <EOL> dep_files = self . _swig_extract_dependency_files ( dep_key ) <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , <EOL> phpswig_src , <EOL> dep_files ) ) <EOL> objs_name = self . _objs_name ( ) <EOL> objs_name_php = '<STR_LIT>' % objs_name <EOL> self . _write_rule ( '<STR_LIT>' % ( objs_name_php , '<STR_LIT:U+002C>' . join ( obj_names_php ) ) ) <EOL> target_path = self . _target_file_path ( self . path , self . name ) <EOL> target_lib = os . path . basename ( target_path ) <EOL> target_path_php = os . path . join ( os . path . dirname ( target_path ) , target_lib ) <EOL> ( link_all_symbols_lib_list , <EOL> lib_str , <EOL> whole_link_flags ) = self . _get_static_deps_lib_list ( ) <EOL> if self . srcs or self . expanded_deps : <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> var_name , <EOL> env_name , <EOL> target_path_php , <EOL> objs_name_php , <EOL> lib_str ) ) <EOL> if link_all_symbols_lib_list : <EOL> self . _write_rule ( '<STR_LIT>' % ( <EOL> env_name , var_name , '<STR_LIT:U+002CU+0020>' . join ( link_all_symbols_lib_list ) ) ) <EOL> def scons_rules ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _prepare_to_generate_rule ( ) <EOL> dep_files_map = { } <EOL> dep_files_map = self . _swig_library_rules_py ( ) <EOL> if ( getattr ( self . options , '<STR_LIT>' , False ) or <EOL> self . data . get ( '<STR_LIT>' ) ) : <EOL> self . _swig_library_rules_java ( dep_files_map ) <EOL> if getattr ( self . options , '<STR_LIT>' , False ) : <EOL> if not self . php_inc_list : <EOL> console . error_exit ( '<STR_LIT>' % ( <EOL> self . path , self . name ) ) <EOL> else : <EOL> self . _swig_library_rules_php ( dep_files_map ) <EOL> def swig_library ( name , <EOL> srcs = [ ] , <EOL> deps = [ ] , <EOL> warning = '<STR_LIT>' , <EOL> java_package = '<STR_LIT>' , <EOL> java_lib_packed = False , <EOL> optimize = [ ] , <EOL> extra_swigflags = [ ] , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> target = SwigLibrary ( name , <EOL> srcs , <EOL> deps , <EOL> warning , <EOL> java_package , <EOL> java_lib_packed , <EOL> optimize , <EOL> extra_swigflags , <EOL> blade . blade , <EOL> kwargs ) <EOL> blade . blade . register_target ( target ) <EOL> build_rules . register_function ( swig_library ) </s>
