<s> """<STR_LIT>""" <EOL> import os <EOL> def WriteList ( fp , list , prefix = '<STR_LIT>' , <EOL> separator = '<STR_LIT>' , <EOL> preamble = None , <EOL> postamble = None ) : <EOL> fp . write ( preamble or '<STR_LIT>' ) <EOL> fp . write ( ( separator or '<STR_LIT:U+0020>' ) . join ( [ prefix + l for l in list ] ) ) <EOL> fp . write ( postamble or '<STR_LIT>' ) <EOL> class TargetBase ( object ) : <EOL> """<STR_LIT>""" <EOL> is_ignored = False <EOL> target_prefix = '<STR_LIT>' <EOL> target_suffix = '<STR_LIT>' <EOL> def __init__ ( self , spec ) : <EOL> self . spec = spec <EOL> def full_product_name ( self ) : <EOL> """<STR_LIT>""" <EOL> suffix = self . target_suffix <EOL> product_extension = self . spec . get ( '<STR_LIT>' ) <EOL> if product_extension : <EOL> suffix = '<STR_LIT:.>' + product_extension <EOL> prefix = self . spec . get ( '<STR_LIT>' , self . target_prefix ) <EOL> name = self . spec [ '<STR_LIT>' ] <EOL> name = prefix + self . spec . get ( '<STR_LIT>' , name ) + suffix <EOL> product_dir = self . spec . get ( '<STR_LIT>' ) <EOL> if product_dir : <EOL> name = os . path . join ( product_dir , name ) <EOL> else : <EOL> name = os . path . join ( self . out_dir , name ) <EOL> return name <EOL> def write_input_files ( self , fp ) : <EOL> """<STR_LIT>""" <EOL> sources = self . spec . get ( '<STR_LIT>' ) <EOL> if not sources : <EOL> fp . write ( '<STR_LIT>' ) <EOL> return <EOL> preamble = '<STR_LIT>' <EOL> postamble = '<STR_LIT>' <EOL> WriteList ( fp , map ( repr , sources ) , preamble = preamble , postamble = postamble ) <EOL> def builder_call ( self ) : <EOL> """<STR_LIT>""" <EOL> name = self . full_product_name ( ) <EOL> return '<STR_LIT>' % ( self . builder_name , name ) <EOL> def write_target ( self , fp , src_dir = '<STR_LIT>' , pre = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> fp . write ( '<STR_LIT:\n>' + pre ) <EOL> fp . write ( '<STR_LIT>' % self . builder_call ( ) ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> class NoneTarget ( TargetBase ) : <EOL> """<STR_LIT>""" <EOL> def write_target ( self , fp , src_dir = '<STR_LIT>' , pre = '<STR_LIT>' ) : <EOL> fp . write ( '<STR_LIT>' ) <EOL> class SettingsTarget ( TargetBase ) : <EOL> """<STR_LIT>""" <EOL> is_ignored = True <EOL> compilable_sources_template = """<STR_LIT>""" <EOL> class CompilableSourcesTargetBase ( TargetBase ) : <EOL> """<STR_LIT>""" <EOL> intermediate_builder_name = None <EOL> def write_target ( self , fp , src_dir = '<STR_LIT>' , pre = '<STR_LIT>' ) : <EOL> if self . intermediate_builder_name is None : <EOL> raise NotImplementedError <EOL> if src_dir and not src_dir . endswith ( '<STR_LIT:/>' ) : <EOL> src_dir += '<STR_LIT:/>' <EOL> variables = { <EOL> '<STR_LIT>' : src_dir , <EOL> '<STR_LIT:name>' : self . intermediate_builder_name , <EOL> } <EOL> fp . write ( compilable_sources_template % variables ) <EOL> super ( CompilableSourcesTargetBase , self ) . write_target ( fp ) <EOL> class ProgramTarget ( CompilableSourcesTargetBase ) : <EOL> """<STR_LIT>""" <EOL> builder_name = '<STR_LIT>' <EOL> intermediate_builder_name = '<STR_LIT>' <EOL> target_prefix = '<STR_LIT>' <EOL> target_suffix = '<STR_LIT>' <EOL> out_dir = '<STR_LIT>' <EOL> class StaticLibraryTarget ( CompilableSourcesTargetBase ) : <EOL> """<STR_LIT>""" <EOL> builder_name = '<STR_LIT>' <EOL> intermediate_builder_name = '<STR_LIT>' <EOL> target_prefix = '<STR_LIT>' <EOL> target_suffix = '<STR_LIT>' <EOL> out_dir = '<STR_LIT>' <EOL> class SharedLibraryTarget ( CompilableSourcesTargetBase ) : <EOL> """<STR_LIT>""" <EOL> builder_name = '<STR_LIT>' <EOL> intermediate_builder_name = '<STR_LIT>' <EOL> target_prefix = '<STR_LIT>' <EOL> target_suffix = '<STR_LIT>' <EOL> out_dir = '<STR_LIT>' <EOL> class LoadableModuleTarget ( CompilableSourcesTargetBase ) : <EOL> """<STR_LIT>""" <EOL> builder_name = '<STR_LIT>' <EOL> intermediate_builder_name = '<STR_LIT>' <EOL> target_prefix = '<STR_LIT>' <EOL> target_suffix = '<STR_LIT>' <EOL> out_dir = '<STR_LIT>' <EOL> TargetMap = { <EOL> None : NoneTarget , <EOL> '<STR_LIT:none>' : NoneTarget , <EOL> '<STR_LIT>' : SettingsTarget , <EOL> '<STR_LIT>' : ProgramTarget , <EOL> '<STR_LIT>' : StaticLibraryTarget , <EOL> '<STR_LIT>' : SharedLibraryTarget , <EOL> '<STR_LIT>' : LoadableModuleTarget , <EOL> } <EOL> def Target ( spec ) : <EOL> return TargetMap [ spec . get ( '<STR_LIT:type>' ) ] ( spec ) </s>
