Exemplo n.º 1
0
    def test(self):
        fpath = os.path.join( autoconfig.data_directory, 'already_exposed_to_be_exported.hpp' )
        mb = module_builder.module_builder_t( [module_builder.create_source_fc( fpath )]
                                              , gccxml_path=autoconfig.gccxml.executable, compiler=pygccxml.utils.native_compiler.get_gccxml_compiler() )

        mb.global_ns.exclude()
        mb.namespace( 'already_exposed' ).include()
        mb.build_code_creator( 'already_exposed' )

        already_exposed_dir = os.path.join( autoconfig.build_directory, 'already_exposed' )
        mb.write_module( os.path.join( already_exposed_dir, 'already_exposed.cpp' ) )

        #-----------------------------------------------------------------------

        fpath = os.path.join( autoconfig.data_directory, 'already_exposed_2to_be_exported.hpp' )
        mb = module_builder.module_builder_t( [module_builder.create_source_fc( fpath )]
                                              , gccxml_path=autoconfig.gccxml.executable
                                              , compiler=pygccxml.utils.native_compiler.get_gccxml_compiler() )

        mb.global_ns.exclude()
        mb.namespace( 'to_be_exposed' ).include()
        mb.build_code_creator( 'to_be_exposed' )

        mb.register_module_dependency( already_exposed_dir )

        mb.build_code_creator( 'to_be_exposed' )
        to_be_exposed_dir = os.path.join( autoconfig.build_directory, 'to_be_exposed' )
        mb.write_module( os.path.join( to_be_exposed_dir, 'to_be_exposed.cpp' ) )

        body = mb.code_creator.body
        self.failUnless( 2 == len( body.creators ) )
        ae_derived_code = body.creators[0].create()
        self.failUnless( mb.class_( 'ae_base' ).decl_string in ae_derived_code )
Exemplo n.º 2
0
    def test(self):
        fpath = os.path.join( autoconfig.data_directory, 'already_exposed_to_be_exported.hpp' )
        mb = module_builder.module_builder_t( [module_builder.create_source_fc( fpath )]
                                              , xml_generator_config=autoconfig.xml_generator_config )

        mb.global_ns.exclude()
        mb.namespace( 'already_exposed' ).include()
        mb.build_code_creator( 'already_exposed' )

        already_exposed_dir = os.path.join( autoconfig.build_directory, 'already_exposed' )
        mb.write_module( os.path.join( already_exposed_dir, 'already_exposed.cpp' ) )

        #-----------------------------------------------------------------------

        fpath = os.path.join( autoconfig.data_directory, 'already_exposed_2to_be_exported.hpp' )
        mb = module_builder.module_builder_t( [module_builder.create_source_fc( fpath )]
                                              , xml_generator_config=autoconfig.xml_generator_config )

        mb.global_ns.exclude()
        mb.namespace( 'to_be_exposed' ).include()
        mb.build_code_creator( 'to_be_exposed' )

        mb.register_module_dependency( already_exposed_dir )

        mb.build_code_creator( 'to_be_exposed' )
        to_be_exposed_dir = os.path.join( autoconfig.build_directory, 'to_be_exposed' )
        mb.write_module( os.path.join( to_be_exposed_dir, 'to_be_exposed.cpp' ) )

        body = mb.code_creator.body
        self.assertTrue( 2 == len( body.creators ) )
        ae_derived_code = body.creators[0].create()
        self.assertTrue( mb.class_( 'ae_base' ).decl_string in ae_derived_code )
 def test(self):
     mb = module_builder.module_builder_t( self._get_files()
                                           , xml_generator_config=autoconfig.xml_generator_config
                                           , include_paths=[autoconfig.boost.include]
                                           , undefine_symbols=['__MINGW32__'] )
     writer = lambda decl: None
     module_builder.print_declarations( mb.global_ns, writer=writer )
    def _create_extension_source_file(self):
        global LICENSE
        
        #xml_file = os.path.split( self.__to_be_exported_header )[1]
        #xml_file = os.path.join( autoconfig.build_dir, xml_file + '.xml' )
        #xml_cached_fc = parser.create_cached_source_fc( self.__to_be_exported_header, xml_file )

        #mb = module_builder.module_builder_t( [xml_cached_fc]
        mb = module_builder.module_builder_t( [self.__to_be_exported_header]
                                              , gccxml_path=autoconfig.gccxml.executable
                                              , include_paths=[autoconfig.boost.include]
                                              , undefine_symbols=['__MINGW32__']
                                              , indexing_suite_version=self.__indexing_suite_version)
        for decl in mb.decls():
            decl.documentation = '"documentation"'
        self.customize( mb )
        doc_extractor = lambda decl: decl.documentation
        if not mb.has_code_creator():
            mb.build_code_creator( self.__module_name, doc_extractor=doc_extractor )
        mb.code_creator.std_directories.extend( autoconfig.scons_config.cpppath )
        mb.code_creator.user_defined_directories.append( autoconfig.data_directory )
        mb.code_creator.precompiled_header = "boost/python.hpp"
        mb.code_creator.license = LICENSE
        self.generate_source_files( mb )
        self.__test_already_exposed( mb )
Exemplo n.º 5
0
    def __init__(self):
        self.__file = os.path.join(random_settings.working_dir,
                                   'random_export.hpp')
        self.__mb = module_builder.module_builder_t(
            [
                parser.create_cached_source_fc(
                    self.__file,
                    os.path.join(random_settings.generated_files_dir,
                                 'random.xml'))
            ],
            gccxml_path=random_settings.gccxml.executable,
            include_paths=[random_settings.boost.include],
            define_symbols=random_settings.defined_symbols,
            undefine_symbols=random_settings.undefined_symbols,
            indexing_suite_version=2)
        self.generators = [
            "ecuyer1988", "hellekalek1995", "kreutzer1986",
            "lagged_fibonacci1279", "lagged_fibonacci19937",
            "lagged_fibonacci2281", "lagged_fibonacci23209",
            "lagged_fibonacci3217", "lagged_fibonacci4423",
            "lagged_fibonacci44497", "lagged_fibonacci607",
            "lagged_fibonacci9689", "minstd_rand", "minstd_rand0", "mt11213b",
            "mt19937", "ranlux3", "ranlux3_01", "ranlux4", "ranlux4_01",
            "ranlux64_3_01", "ranlux64_4_01", "taus88"
        ]

        self.no_min_max = [
            'py_cauchy_distribution', 'py_bernoulli_distribution',
            'py_binomial_distribution', 'py_poisson_distribution',
            'py_normal_distribution', 'py_gamma_distribution',
            'py_triangle_distribution', 'py_uniform_on_sphere',
            'py_exponential_distribution', 'py_geometric_distribution',
            'py_lognormal_distribution'
        ]
Exemplo n.º 6
0
def create_module():
    parser_config = parser.config_t( )

    fx_xml = os.path.join( settings.xml_files, 'fx.xml' )
    mb = module_builder.module_builder_t( [ parser.create_cached_source_fc( 'fx.h', fx_xml ) ]
                                          , gccxml_path=settings.gccxml_path
                                          , include_paths=[settings.boost_path, settings.tnfox_include_path]
                                          , define_symbols=settings.defined_symbols_gccxml )
    mb.run_query_optimizer()
    print 'filtering declarations'
    filter_decls( mb )
    print 'filtering declarations - done'
    print 'set call policies'
    set_call_policies( mb )
    print 'set call policies - done'
    print 'customize declarations'
    customize_decls( mb )
    print 'customize declarations - done'
    print 'creating module'
    mb.build_code_creator(settings.module_name )
    print 'creating module - done'
    print 'customizing module'
    customize_module( mb )
    print 'customizing module - done'
    return mb
Exemplo n.º 7
0
    def _generate_code(self):
        global save_header_name
        
        try:
            config = self._parser_configurator.parser_configuration()
            header_file = self._header_file_configurator.header_file()
            if not header_file or not os.path.isfile( header_file ):
                raise RuntimeError( 'Header file "%s" does not exist or should be valid file name.' % header_file )
            gui_config_t.save_header_name( header_file )
            config.include_paths.append( os.path.split( header_file )[0] )
            
            start_time = time.clock()        
            mb = module_builder.module_builder_t( 
                    [ header_file ]
                    , gccxml_path=config.gccxml_path
                    , working_directory=os.path.split( header_file )[0]
                    , include_paths=config.include_paths
                    , define_symbols=config.define_symbols )

            parsed_time = time.clock() - start_time

            mb.build_code_creator( "pyplusplus" )
            mb.code_creator.user_defined_directories.extend( config.include_paths )
            code = mb.code_creator.create()
            code = code.replace( '\n\r', '\n' )
            code = code.replace( '\r\n', '\n' )
            code_generated_time = time.clock() - start_time - parsed_time
            self._generated_code.set_generated_code( code )
            self._statistics.set_parse_time( parsed_time )
            self._statistics.set_code_generation_time( code_generated_time )
        except Exception, error:
            user_msg = [ 'Error occured during code generation process!' ]
            user_msg.append( 'Error:' )
            user_msg.append( str( error ) )
            self._generated_code.set_generated_code( '\n'.join( user_msg ) )
    def test(self):

        code = """
            namespace xyz{

                struct good{};

                typedef void (*ff1)( int, int );

                void f_bad( ff1 );

            }
        """

        mb = module_builder.module_builder_t(
            [module_builder.create_text_fc(code)],
            xml_generator_config=autoconfig.xml_generator_config)

        xyz = mb.namespace(name='xyz')
        xyz.include()

        xyz.exclude(compilation_errors=True)

        self.assertTrue(xyz.ignore == False)
        self.assertTrue(xyz.class_('good').ignore == False)
        self.assertTrue(xyz.free_function('f_bad').ignore == True)
Exemplo n.º 9
0
def generate_code():

    code_tree = parser.create_cached_source_fc(
        os.path.join(root_dir, "Engine.h"), "BootCache.xml")

    defined_symbols = ['B_NO_INTERLOCKED_INTRINSICS']

    include_dirs = [
        os.path.join(root_dir, "..", "..", "..", "Engine", "Common"),
        os.path.join(root_dir, "..", "..", "..", "Engine", "Graphics"),
        os.path.join(root_dir, "..", "..", "..", "Engine", "FileSystem")
    ]

    mb = module_builder.module_builder_t([code_tree],
                                         gccxml_path=gccxml_bin,
                                         working_directory=root_dir,
                                         include_paths=include_dirs,
                                         define_symbols=defined_symbols,
                                         undefine_symbols=[],
                                         indexing_suite_version=2,
                                         cflags='')

    #ns = mb.global_ns
    #ns.exclude()

    return mb
Exemplo n.º 10
0
    def _create_extension_source_file(self):
        global LICENSE

        #xml_file = os.path.split( self.__to_be_exported_header )[1]
        #xml_file = os.path.join( autoconfig.build_dir, xml_file + '.xml' )
        #xml_cached_fc = parser.create_cached_source_fc( self.__to_be_exported_header, xml_file )

        #mb = module_builder.module_builder_t( [xml_cached_fc]
        mb = module_builder.module_builder_t(
            [self.__to_be_exported_header],
            gccxml_path=autoconfig.gccxml.executable,
            include_paths=[autoconfig.boost.include],
            undefine_symbols=['__MINGW32__'],
            indexing_suite_version=self.__indexing_suite_version)
        for decl in mb.decls():
            decl.documentation = '"documentation"'
        self.customize(mb)
        doc_extractor = lambda decl: decl.documentation
        if not mb.has_code_creator():
            mb.build_code_creator(self.__module_name,
                                  doc_extractor=doc_extractor)
        mb.code_creator.std_directories.extend(autoconfig.scons_config.cpppath)
        mb.code_creator.user_defined_directories.append(
            autoconfig.data_directory)
        mb.code_creator.precompiled_header = "boost/python.hpp"
        mb.code_creator.license = LICENSE
        self.generate_source_files(mb)
        self.__test_already_exposed(mb)
Exemplo n.º 11
0
 def test(self):
     
     code = """
         namespace xyz{
             struct Y;
             
             struct X{
                 X();
                 X( const X& );       
                 X( Y* );
             };
         }
     """
     
     mb = module_builder.module_builder_t( 
             [ module_builder.create_text_fc( code ) ]
             , gccxml_path=autoconfig.gccxml.executable )
     
     x = mb.class_( 'X' )
     x.include()
     x.constructors().body = '    //all constructors body'
     x.null_constructor_body = '    //null constructor body'
     x.copy_constructor_body = '    //copy constructor body'
     
     mb.build_code_creator( 'XXX' )
     code = mb.code_creator.create()
     tmp = code.split( x.null_constructor_body )
     self.failUnless( len( tmp ) == 2 )
     tmp = code.split( x.copy_constructor_body )
     self.failUnless( len( tmp ) == 2 )
     tmp = code.split( '    //all constructors body' )
     self.failUnless( len( tmp ) == 2 )
Exemplo n.º 12
0
 def test(self):
     mb = module_builder.module_builder_t(
         [ module_builder.create_text_fc( self.CODE )]
         , gccxml_path=autoconfig.gccxml.executable )
     d = mb.class_( 'derived' )
     f = d.mem_fun( 'f' )
     self.failUnless( f.create_with_signature == True )
    def test(self):

        code = """
            namespace xyz{
                struct Y;

                struct X{
                    X();
                    X( const X& );
                    X( Y* );
                };
            }
        """

        mb = module_builder.module_builder_t(
            [module_builder.create_text_fc(code)],
            xml_generator_config=autoconfig.xml_generator_config)

        x = mb.class_('X')
        x.include()
        x.constructors().body = '    //all constructors body'
        x.null_constructor_body = '    //null constructor body'
        x.copy_constructor_body = '    //copy constructor body'

        mb.build_code_creator('XXX')
        code = mb.code_creator.create()
        tmp = code.split(x.null_constructor_body)
        self.assertTrue(len(tmp) == 2)
        tmp = code.split(x.copy_constructor_body)
        self.assertTrue(len(tmp) == 2)
        tmp = code.split('    //all constructors body')
        self.assertTrue(len(tmp) == 2)
 def test(self):
     mb = module_builder.module_builder_t(
         [module_builder.create_text_fc(self.CODE)],
         xml_generator_config=autoconfig.xml_generator_config)
     d = mb.class_('derived')
     f = d.member_function('f')
     self.assertTrue(f.create_with_signature == True)
Exemplo n.º 15
0
 def __init__(self, files):
     # Parse code generation parameters from (optional) command line arguments
     # Otherwise hard code paths from my particular dev machine... (yuck)
     parser = argparse.ArgumentParser(description='Generates boost-python wrapping code for an OSG module.')
     parser.add_argument('--gccxml_path', 
                         default="C:/Program Files (x86)/gccxml/bin/gccxml.exe", 
                         help="path to the GCCXML executable program",)
     parser.add_argument('--osg_include_path', 
                         default="C:/Program Files (x86)/OpenSceneGraph323vs2008/include", 
                         help="path to the OpenSceneGraph C++ header files",)
     default_compiler = "msvc9"
     parser.add_argument('--gccxml_compiler', 
                         default=default_compiler, 
                         help="name of C++ compiler",)
     args = parser.parse_args()
     #
     gccxml_path = args.gccxml_path
     osg_include_path = args.osg_include_path
     compiler = args.gccxml_compiler
     #
     self.max_arity = 18
     define_symbols = []
     if compiler == 'msvc9':
         define_symbols.append("_HAS_TR1=0") # avoid boost compiler errors on windows
     define_symbols.append("BOOST_PYTHON_MAX_ARITY=%d" % self.max_arity)
     #
     self.mb = module_builder.module_builder_t(
         files = files,
         gccxml_path = gccxml_path,
         include_paths = [osg_include_path,],
         define_symbols=define_symbols,
         indexing_suite_version=2,
         compiler=compiler,
     )
     self.mb.BOOST_PYTHON_MAX_ARITY = self.max_arity # Prevents warnings on 10-18 argument methods
Exemplo n.º 16
0
 def test(self):
     
     code = """
         namespace xyz{
         
             struct good{};
             
             typedef void (*ff1)( int, int );
             
             void f_bad( ff1 );
             
         }
     """
     
     mb = module_builder.module_builder_t( 
             [ module_builder.create_text_fc( code ) ]
             , gccxml_path=autoconfig.gccxml.executable )
     
     xyz = mb.namespace( name='xyz' )
     xyz.include()
     
     xyz.exclude(compilation_errors=True)
     
     self.failUnless( xyz.ignore == False )
     self.failUnless( xyz.class_( 'good' ).ignore == False )
     self.failUnless( xyz.free_fun( 'f_bad' ).ignore == True )
    def test(self):
        module_builder.set_logger_level( logging.CRITICAL )
        messages.disable( *messages.all_warning_msgs )

        xml_file = parser.create_gccxml_fc( os.path.join( autoconfig.data_directory, 'particleuniverse.xml' ) )

        mb = module_builder.module_builder_t(
                [ xml_file ]
                , gccxml_path=autoconfig.gccxml.executable
                , indexing_suite_version=2
                , compiler=pygccxml.utils.native_compiler.get_gccxml_compiler())

        mb.global_ns.exclude()
        mb.namespace('ParticleUniverse').include()
        mb.namespace('Ogre').include()
        mb.namespace('Ogre').classes().already_exposed = True

        target_dir = os.path.join( autoconfig.build_directory, 'particle_universe' )
        #~ if os.path.exists( target_dir ):
            #~ shutil.rmtree( target_dir )
        #~ os.mkdir( target_dir )
        psp = mb.class_( '::ParticleUniverse::ParticleScriptParser' )
        declarations.print_declarations( psp )
        mb.build_code_creator( 'PU' )
        mb.split_module( target_dir )
Exemplo n.º 18
0
 def __init__(self, name, deps=None, replacement_dict=default_replacement,
              indexing_suite_version=2):
     """Constructor.
     @name name of the python module
     @dep name of another module this module depends on"""
     # create a separate thread that prints out a message every 60 seconds
     # to let build bots know the build is not stuck.
     self.heartbeat = threading.Thread(target=Heartbeat(60))
     self.heartbeat.daemon = True
     self.heartbeat.start()
     xml_generator_config = parser.load_xml_generator_configuration("/Users/mmoll/build/omplapp/1.4.2/castxml.cfg")
     self.mb = module_builder.module_builder_t(
         files=['bindings/' + name + '.h'],
         # cache is not used with compilation_mode = parser.COMPILATION_MODE.ALL_AT_ONCE
         #cache = '/Users/mmoll/build/omplapp/1.4.2/pyplusplus_'+name+'.cache',
         xml_generator_config=xml_generator_config,
         start_with_declarations=['ompl::' + name],
         compilation_mode=parser.COMPILATION_MODE.ALL_AT_ONCE,
         indexing_suite_version=indexing_suite_version)
     self.replacement = {} if replacement_dict is None else replacement_dict
     self.mb.classes().always_expose_using_scope = True
     self.mb.add_registration_code('PyEval_InitThreads();', tail=False)
     self.std_ns = self.mb.namespace('std')
     self.ompl_ns = self.mb.namespace('ompl')
     self.call_policies()
     self.filter_declarations()
     if deps != None:
         for dep in deps:
             self.mb.register_module_dependency(dep)
     self.mb.build_code_creator(module_name='_' + name)
     self.mb.split_module('bindings/' + name, use_files_sum_repository=True)
Exemplo n.º 19
0
def main(args):
    from pyplusplus import module_builder
    from pyplusplus.module_builder import call_policies

    if args.chdir:
        from os import chdir
        chdir(args.chdir)

    builder = module_builder.module_builder_t(args.input,
                                              include_paths=args.include)

    if args.mangle:
        from runpy import runpy
        M = runpy(args.mangle)
        M['mangle'](builder)

        #eg. things a mangle might do
        #Cell = builder.class_('Cell')
        #Cell.member_function('getelem').call_policies = call_policies.return_internal_reference()
        # The Elem* pointer passed to setelem(P) is now "owned" by the Cell
        #Cell.member_function('setelem').call_policies = call_policies.with_custodian_and_ward(1,2)

        #Cell.var('elem').expost_value = False

    builder.build_code_creator(module_name=args.name)
    builder.write_module(args.output)
    def test(self):
        module_builder.set_logger_level( logging.CRITICAL )
        messages.disable( *messages.all_warning_msgs )

        ogre_file = autoconfig.data_directory.replace( 'pyplusplus_dev', 'pygccxml_dev' )
        ogre_file = parser.create_gccxml_fc( os.path.join( ogre_file, 'ogre.1.7.xml' ) )

        mb = module_builder.module_builder_t(
                [ ogre_file ]
                , xml_generator_config=autoconfig.xml_generator_config
                , indexing_suite_version=2)

        mb.global_ns.exclude()
        mb.namespace('Ogre').include()

        x = mb.global_ns.decls( lambda d: 'Animation*' in d.name and 'MapIterator' in d.name )
        for y in x:
            print(y.name)
            print(y.partial_name)
            print(declarations.full_name( y, with_defaults=False ))

        target_dir = os.path.join( autoconfig.build_directory, 'ogre' )
        #~ if os.path.exists( target_dir ):
            #~ shutil.rmtree( target_dir )
        #~ os.mkdir( target_dir )

        mb.build_code_creator( 'Ogre3d' )
        mb.split_module( target_dir )
Exemplo n.º 21
0
    def test(self):
        module_builder.set_logger_level( logging.CRITICAL )
        messages.disable( *messages.all_warning_msgs )

        ogre_file = autoconfig.data_directory.replace( 'pyplusplus_dev', 'pygccxml_dev' )
        ogre_file = parser.create_gccxml_fc( os.path.join( ogre_file, 'ogre.1.7.xml' ) )

        mb = module_builder.module_builder_t(
                [ ogre_file ]
                , gccxml_path=autoconfig.gccxml.executable
                , indexing_suite_version=2
                , compiler=pygccxml.utils.native_compiler.get_gccxml_compiler())

        mb.global_ns.exclude()
        mb.namespace('Ogre').include()

        x = mb.global_ns.decls( lambda d: 'Animation*' in d.name and 'MapIterator' in d.name )
        for y in x:
            print y.name
            print y.partial_name
            print declarations.full_name( y, with_defaults=False )

        target_dir = os.path.join( autoconfig.build_directory, 'ogre' )
        #~ if os.path.exists( target_dir ):
            #~ shutil.rmtree( target_dir )
        #~ os.mkdir( target_dir )

        mb.build_code_creator( 'Ogre3d' )
        mb.split_module( target_dir )
def gen_cpp(params, q_result, q_error):
    '''
    Generate cpp (Boost.Python) code
    @param params: List of parameters [gccxml,incPath,macros]
    @param q_result: python queue to put result in
    @param q_error: python queue to put error in
    @return None (isn't evaluated)
    '''
    try:
        header_file = params[3]
    
        include_paths = params[1]
        include_paths.append( os.path.split( header_file )[0] )
        
        mb = module_builder.module_builder_t( 
                [ header_file ]
                , gccxml_path=params[0]
                , working_directory=os.path.split( header_file )[0]
                , include_paths=include_paths
                , define_symbols=params[2] )
    
        mb.build_code_creator( "pyplusplus" )
        mb.code_creator.user_defined_directories.extend( include_paths )
        code = mb.code_creator.create()
        code = code.replace( '\n\r', '\n' )
        code = code.replace( '\r\n', '\n' )

        q_result.put( code )
    except Exception, error:
        q_result.put(str( error ))
        q_error.put(str( error ))
Exemplo n.º 23
0
 def test(self):
     mb = module_builder.module_builder_t( self._get_files()
                                           , gccxml_path=autoconfig.gccxml.executable
                                           , include_paths=[autoconfig.boost.include]
                                           , undefine_symbols=['__MINGW32__'])
     writer = lambda decl: None
     module_builder.print_declarations( mb.global_ns, writer=writer )
Exemplo n.º 24
0
    def _create_extension_source_file(self):
        global LICENSE

        if os.path.exists( self.__generated_source_file_name + '.xml' ):
            os.remove( self.__generated_source_file_name + '.xml' )

        test_header_cfg \
            = pygccxml.parser.create_cached_source_fc( self.__to_be_exported_header
                                                       , self.__generated_source_file_name + '.xml' )

        mb = module_builder.module_builder_t( [ test_header_cfg ]
                                              #, undefine_symbols=['__MINGW32__']
                                              , indexing_suite_version=self.__indexing_suite_version
                                              , gccxml_config=autoconfig.cxx_parsers_cfg.gccxml)
        for decl in mb.decls():
            decl.documentation = '"documentation"'
        self.customize( mb )
        doc_extractor = lambda decl: decl.documentation
        if not mb.has_code_creator():
            mb.build_code_creator( self.__module_name, doc_extractor=doc_extractor )
        mb.code_creator.std_directories.extend( autoconfig.scons_config.cpppath )
        mb.code_creator.user_defined_directories.append( autoconfig.data_directory )
        mb.code_creator.precompiled_header = "boost/python.hpp"
        mb.code_creator.license = LICENSE
        self.generate_source_files( mb )
        self.__test_already_exposed( mb )
Exemplo n.º 25
0
def export():
    global license
    header_file = os.path.join(settings.easybmp_path, 'EasyBMP.h')
    #create configuration for GCC-XML parser
    #initialize module builder
    mb = module_builder.module_builder_t(
        [header_file],
        gccxml_path=settings.gccxml_path,
        working_directory=settings.easybmp_path)

    bmp_class = mb.class_('BMP')
    call_operator = bmp_class.operator(symbol='()', recursive=False)
    call_operator.alias = 'GetRGBAPixel'
    call_operator.call_policies = module_builder.call_policies.return_internal_reference(
    )
    #customizing code, before generation
    mb.build_code_creator(settings.module_name)
    mb.code_creator.license = license
    mb.code_creator.user_defined_directories.append(settings.easybmp_path)
    mb.code_creator.precompiled_header = 'boost/python.hpp'
    mb.code_creator.replace_included_headers([header_file])

    mb.write_module(
        os.path.join(settings.generated_files_dir,
                     settings.module_name + '.cpp'))
Exemplo n.º 26
0
    def __init__(self,
                 module_name = '',
                 call_policies = (),
                 function_call_policies = (),
                 excluded_classes = (),
                 excluded_members = (),
                 included_members = (),
                 excluded_constructors = (),
                 already_exposed = (),
                 headers = [],
                 extra_headers = [],
                 extra_declarations = [],
                 extra_registrations = [],
                 extra_member_registrations = [],
                 held_types = [],
                 ownership_transfers = [],
                 ):
        self.module_name = module_name
        self.headers = headers
        self.call_policies = call_policies
        self.function_call_policies = function_call_policies
        self.excluded_classes = excluded_classes
        self.excluded_members = excluded_members
        self.included_members = included_members
        self.excluded_constructors = excluded_constructors
        self.already_exposed = already_exposed
        self.extra_headers = extra_headers
        self.extra_declarations = extra_declarations
        self.extra_member_registrations = extra_member_registrations
        self.extra_registrations = extra_registrations
        self.held_types = held_types
        self.ownership_transfers = ownership_transfers
        self.bindings_dir = "."


        # If only generating the list of dependences, do not create
        # the module builder, because it would compile all the headers
        # with gccxml.
        if len(sys.argv) == 2 and sys.argv[1] == '--generate-dependences':
            pass
	else:
            #try:
            #    os.mkdir(self.bindings_dir)
            #except OSError:
            #    pass
            
            hh = map(os.path.abspath, headers)
            header_file_name = "%s/%s_headers.hpp" % (self.bindings_dir,
                                                     self.module_name)
            f = open(header_file_name, 'w')
            for h in hh:
                f.write('#include <%s>\n'% h)
            f.close()
            self.module_builder = module_builder.module_builder_t(
                [os.path.abspath(header_file_name)]
                , gccxml_path=r"/usr/bin/gccxml" 
                , include_paths=include_paths
                , define_symbols=['TCE_PYTHON_BINDINGS']
                , indexing_suite_version=2)
Exemplo n.º 27
0
    def __init__(
        self,
        module_name='',
        call_policies=(),
        function_call_policies=(),
        excluded_classes=(),
        excluded_members=(),
        included_members=(),
        excluded_constructors=(),
        already_exposed=(),
        headers=[],
        extra_headers=[],
        extra_declarations=[],
        extra_registrations=[],
        extra_member_registrations=[],
        held_types=[],
        ownership_transfers=[],
    ):
        self.module_name = module_name
        self.headers = headers
        self.call_policies = call_policies
        self.function_call_policies = function_call_policies
        self.excluded_classes = excluded_classes
        self.excluded_members = excluded_members
        self.included_members = included_members
        self.excluded_constructors = excluded_constructors
        self.already_exposed = already_exposed
        self.extra_headers = extra_headers
        self.extra_declarations = extra_declarations
        self.extra_member_registrations = extra_member_registrations
        self.extra_registrations = extra_registrations
        self.held_types = held_types
        self.ownership_transfers = ownership_transfers
        self.bindings_dir = "."

        # If only generating the list of dependences, do not create
        # the module builder, because it would compile all the headers
        # with gccxml.
        if len(sys.argv) == 2 and sys.argv[1] == '--generate-dependences':
            pass
        else:
            #try:
            #    os.mkdir(self.bindings_dir)
            #except OSError:
            #    pass

            hh = map(os.path.abspath, headers)
            header_file_name = "%s/%s_headers.hpp" % (self.bindings_dir,
                                                      self.module_name)
            f = open(header_file_name, 'w')
            for h in hh:
                f.write('#include <%s>\n' % h)
            f.close()
            self.module_builder = module_builder.module_builder_t(
                [os.path.abspath(header_file_name)],
                gccxml_path=r"/usr/bin/gccxml",
                include_paths=include_paths,
                define_symbols=['TCE_PYTHON_BINDINGS'],
                indexing_suite_version=2)
Exemplo n.º 28
0
 def test(self):
     mb = module_builder.module_builder_t(
         [ module_builder.create_text_fc( 'namespace arr{ struct x{ x( int arr[3][3], int ){} x( const x arr[3][3], int ){} }; }' )]
         , gccxml_path=autoconfig.gccxml.executable )
     arr = mb.namespace( name='arr' )
     mem_funs = arr.calldefs( 'x', arg_types=[None,None] )
     for x in mem_funs:
         self.failUnless( x.exportable == False )
Exemplo n.º 29
0
 def test(self):
     mb = module_builder.module_builder_t(
             [ module_builder.create_text_fc( 'namespace enums{ enum { OK=1 }; }' ) ]
             , gccxml_path=autoconfig.gccxml.executable )
     mb.namespace( name='::enums' ).include()
     mb.build_code_creator('dummy')
     flatten = code_creators.make_flatten(mb.code_creator.creators)
     self.failUnless( filter( lambda inst: isinstance( inst, code_creators.unnamed_enum_t ), flatten ) )
Exemplo n.º 30
0
 def test(self):
     mb = module_builder.module_builder_t( self._get_files()
                                           , gccxml_path=autoconfig.gccxml.executable
                                           , include_paths=[autoconfig.boost.include]
                                           , undefine_symbols=['__MINGW32__']
                                           , compiler=pygccxml.utils.native_compiler.get_gccxml_compiler())
     writer = lambda decl: None
     module_builder.print_declarations( mb.global_ns, writer=writer )
Exemplo n.º 31
0
 def test(self):
     mb = module_builder.module_builder_t(
         [ module_builder.create_text_fc( self.CODE )]
         , gccxml_path=autoconfig.gccxml.executable )
     xxx = mb.namespace( name='xxx' )
     fun = xxx.calldef( 'do_smth' )
     self.failUnless( fun.readme() == [] )
     minus_minus = xxx.operator( symbol='--' )
     self.failUnless( 1 == len( minus_minus.readme() ), os.linesep.join( minus_minus.readme() ) )
Exemplo n.º 32
0
    def test(self):
        mb = module_builder.module_builder_t(
                        [ module_builder.create_text_fc( 'struct x{};' ) ]
                        , xml_generator_config=autoconfig.xml_generator_config
                        , encoding='UTF-8')

        mb.build_code_creator( module_name='unicode_bug' )
        mb.code_creator.license = "//абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
        mb.write_module( os.path.join( autoconfig.build_dir, 'unicode_bug.cpp' ) )
Exemplo n.º 33
0
 def test(self):
     mb = module_builder.module_builder_t(
             [ module_builder.create_text_fc( 'namespace enums{ enum { OK=1 }; }' ) ]
             , gccxml_path=autoconfig.gccxml.executable
             , compiler=pygccxml.utils.native_compiler.get_gccxml_compiler() )
     mb.namespace( name='::enums' ).include()
     mb.build_code_creator('dummy')
     flatten = code_creators.make_flatten(mb.code_creator.creators)
     self.failUnless( [inst for inst in flatten if isinstance( inst, code_creators.unnamed_enum_t )] )
 def test(self):
     mb = module_builder.module_builder_t(
         [module_builder.create_text_fc(self.CODE)],
         xml_generator_config=autoconfig.xml_generator_config)
     xxx = mb.namespace(name='xxx')
     fun = xxx.calldef('do_smth')
     self.assertTrue(fun.readme() == [])
     minus_minus = xxx.operator(symbol='--')
     self.assertTrue(1 == len(minus_minus.readme()),
                     os.linesep.join(minus_minus.readme()))
Exemplo n.º 35
0
    def test(self):
        mb = module_builder.module_builder_t(
                        [ module_builder.create_text_fc( 'struct x{};' ) ]
                        , gccxml_path=autoconfig.gccxml.executable
                        , encoding='UTF-8'
                        , compiler=autoconfig.cxx_parsers_cfg.gccxml.compiler)

        mb.build_code_creator( module_name='unicode_bug' )
        mb.code_creator.license = "//абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
        mb.write_module( os.path.join( autoconfig.build_dir, 'unicode_bug.cpp' ) )
Exemplo n.º 36
0
    def test(self):
        mb = module_builder.module_builder_t(
                        [ module_builder.create_text_fc( 'struct x{};' ) ]
                        , gccxml_path=autoconfig.gccxml.executable
                        , encoding='UTF-8'
                        , compiler=autoconfig.cxx_parsers_cfg.gccxml.compiler)

        mb.build_code_creator( module_name='unicode_bug' )
        mb.code_creator.license = "//абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
        mb.write_module( os.path.join( autoconfig.build_dir, 'unicode_bug.cpp' ) )
Exemplo n.º 37
0
def createModuleBuilder(input_file, defined_symbols):
    ret = module_builder.module_builder_t(files=[input_file],
                                          gccxml_path=GCCXML_PATH,
                                          include_paths=INCLUDE_PATHS,
                                          define_symbols=defined_symbols,
                                          indexing_suite_version=2)

    ret.BOOST_PYTHON_MAX_ARITY = 25
    ret.classes().always_expose_using_scope = True

    return ret
Exemplo n.º 38
0
 def test_find_by_class_instance(self):
     mb = module_builder.module_builder_t(
         [ module_builder.create_text_fc( 'namespace enums{ enum color{ red = 1}; }' )]
         , gccxml_path=autoconfig.gccxml.executable )
     mb.namespace( name='::enums' ).include()
     mb.build_code_creator('dummy')
     enum_found = code_creators.creator_finder.find_by_class_instance(
         code_creators.enum_t
         , mb.code_creator.creators
         , recursive=True)
     self.failUnless( enum_found )
Exemplo n.º 39
0
    def __init__(self):
        self.__file = os.path.join(crc_settings.working_dir, "crc_export.hpp")

        self.__mb = module_builder.module_builder_t(
            [parser.create_cached_source_fc(self.__file, os.path.join(crc_settings.generated_files_dir, "crc.xml"))],
            gccxml_path=crc_settings.gccxml.executable,
            include_paths=[crc_settings.boost.include],
            define_symbols=crc_settings.defined_symbols,
            undefine_symbols=crc_settings.undefined_symbols,
            indexing_suite_version=2,
        )
Exemplo n.º 40
0
 def test_find_by_declaration(self):
     mb = module_builder.module_builder_t(
         [ module_builder.create_text_fc( 'namespace enums{ enum color{ red = 1}; }' )]
         , gccxml_path=autoconfig.gccxml.executable )
     mb.namespace( name='::enums' ).include()
     enum_matcher = declarations.match_declaration_t( name='color' )
     mb.build_code_creator( 'dummy' )
     enum_found = code_creators.creator_finder.find_by_declaration(
                     enum_matcher
                     , mb.code_creator.creators )
     self.failUnless( enum_found )
Exemplo n.º 41
0
    def test(self):
        fpath = os.path.join(autoconfig.data_directory,
                             'already_exposed_to_be_exported.hpp')
        mb = module_builder.module_builder_t(
            [module_builder.create_source_fc(fpath)],
            gccxml_path=autoconfig.gccxml.executable,
            compiler=pygccxml.utils.native_compiler.get_gccxml_compiler())

        mb.global_ns.exclude()
        mb.namespace('already_exposed').include()
        mb.build_code_creator('already_exposed')

        already_exposed_dir = os.path.join(autoconfig.build_directory,
                                           'already_exposed')
        mb.write_module(
            os.path.join(already_exposed_dir, 'already_exposed.cpp'))

        #-----------------------------------------------------------------------

        fpath = os.path.join(autoconfig.data_directory,
                             'already_exposed_2to_be_exported.hpp')
        mb = module_builder.module_builder_t(
            [module_builder.create_source_fc(fpath)],
            gccxml_path=autoconfig.gccxml.executable,
            compiler=pygccxml.utils.native_compiler.get_gccxml_compiler())

        mb.global_ns.exclude()
        mb.namespace('to_be_exposed').include()
        mb.build_code_creator('to_be_exposed')

        mb.register_module_dependency(already_exposed_dir)

        mb.build_code_creator('to_be_exposed')
        to_be_exposed_dir = os.path.join(autoconfig.build_directory,
                                         'to_be_exposed')
        mb.write_module(os.path.join(to_be_exposed_dir, 'to_be_exposed.cpp'))

        body = mb.code_creator.body
        self.failUnless(2 == len(body.creators))
        ae_derived_code = body.creators[0].create()
        self.failUnless(mb.class_('ae_base').decl_string in ae_derived_code)
Exemplo n.º 42
0
 def __init__(self):
     "Container for pyplusplus module builder for wrapping V3D"
     # Look for "--win64" command line argument
     parser = OptionParser()
     parser.add_option("--win64", action="store_true", dest="win64", default=False, help="Whether we are building Windows 64-bit")
     (options, args) = parser.parse_args()
     includes = []
     homedir = os.path.expanduser('~')
     for path in ['.',
                    os.path.join(homedir, 'svn/v3d_cmake/v3d_main/basic_c_fun'),
                    os.path.join(homedir, 'svn/v3d/v3d_main/basic_c_fun'),
                    os.path.join(homedir, 'Documents/svn/v3d_cmake/v3d_main/basic_c_fun'),
                    os.path.abspath('../../../v3d_main/basic_c_fun'),
                    '/usr/include/Qt',
                    '/usr/include/QtCore',
                    '/usr/include/QtGui',
                    '/usr/include/qt4',
                    '/usr/include/qt4/QtCore',
                    '/usr/include/qt4/QtGui',
                    '/Library/Frameworks/QtCore.framework/Headers',
                    '/Library/Frameworks/QtGui.framework/Headers',
                    'C:/Qt/qt-64bit-4.7.2/include/QtCore/',
                    'C:/Qt/qt-64bit-4.7.2/include/QtGui/',
                    'C:/Qt/qt-64bit-4.7.2/include/Qt/',
                    'C:/Qt/qt-64bit-4.7.2/include/',
                  ]:
         if os.path.exists(path):
             # keep command line short
             abs_path = os.path.abspath(path)
             rel_path = os.path.relpath(path)
             # print abs_path
             # print rel_path
             if len(abs_path) > len(rel_path):
                 includes.append(rel_path)
             else:
                 includes.append(abs_path)
     gccxml_executable = self.find_gccxml()
     gccxml_cflags = ' --gccxml-cxxflags "-m32"'
     # gccxml_cflags = ''
     define_symbols=[]
     if sys.platform == 'win32':
         define_symbols.append("_HAS_TR1=0")
     if options.win64:
         define_symbols.append("_WIN64")
     self.mb = module_builder.module_builder_t(
         files = ['wrappable_v3d.h',],
         gccxml_path=gccxml_executable,
         cflags=gccxml_cflags,
         include_paths=includes,
         indexing_suite_version=2,
         # ignore_gccxml_output=True,
         define_symbols=define_symbols,)
Exemplo n.º 43
0
    def __init__(self, name, deps=None, replacement_dict=default_replacement, indexing_suite_version = 2):
        """Constructor.
        @name name of the python module
        @dep name of another module this module depends on"""
        module_builder.set_logger_level( logging.INFO )
        candidate_include_paths = [ "/home/lucas/private_ompl/omplapp/ompl/src", "/home/lucas/private_ompl/omplapp/src",
            "/usr/include/python2.7", "/usr/include", "/usr/local/include", ""]

        # Adding standard windows headers
        if platform == 'win32':
            compiler = getenv('GCCXML_COMPILER')
            # MinGW
            if compiler != None and (compiler.lower().endswith('g++') or compiler.lower().endswith('c++')):
                version = subprocess.Popen([compiler, '-dumpversion'],
                    stdout=subprocess.PIPE).communicate()[0].strip()
                # Find whole path to MinGW
                compiler_path = ""
                for path in getenv('PATH').split(';'):
                    if exists(join(path, compiler + '.exe')):
                        compiler_path = path
                        break

                if compiler_path is not "":
                    # Adding in necessary include paths
                    candidate_include_paths.append (join(compiler_path, "..", "include"))
                    candidate_include_paths.append (join(compiler_path, "..", "lib", "gcc", "mingw32", version, "include"))
                    candidate_include_paths.append (join(compiler_path, "..", "lib", "gcc", "mingw32", version, "include", "c++"))
                    candidate_include_paths.append (join(compiler_path, "..", "lib", "gcc", "mingw32", version, "include", "c++", "mingw32"))

        include_paths = []
        for path in candidate_include_paths:
            if len(path)>0 and exists(path):
                include_paths.append(path)
        self.mb = module_builder.module_builder_t(
            files = [ 'bindings/' + name + '.h' ],
            cache = '/home/lucas/private_ompl/omplapp/build/pyplusplus_'+name+'.cache',
            gccxml_path = "/usr/local/bin/gccxml",
            include_paths = include_paths,
            cflags="",
            indexing_suite_version = indexing_suite_version )
        self.replacement = {} if replacement_dict==None else replacement_dict
        self.mb.classes().always_expose_using_scope = True
        self.mb.add_registration_code('PyEval_InitThreads();', tail=False)
        self.std_ns = self.mb.namespace('std')
        self.ompl_ns = self.mb.namespace('ompl')
        self.call_policies()
        self.filter_declarations()
        if deps!=None:
            for dep in deps:
                self.mb.register_module_dependency(dep)
        self.mb.build_code_creator( module_name='_'+name )
        self.mb.split_module('bindings/' + name, use_files_sum_repository=True)
Exemplo n.º 44
0
def createModuleBuilder(input_file, defined_symbols):
    ret = module_builder.module_builder_t(
        files=[input_file],
        gccxml_path=GCCXML_PATH,
        include_paths=INCLUDE_PATHS,
        define_symbols=defined_symbols,
        indexing_suite_version=2,
    )

    ret.BOOST_PYTHON_MAX_ARITY = 25
    ret.classes().always_expose_using_scope = True

    return ret
Exemplo n.º 45
0
    def test__getitem__( self ):
        mb = module_builder.module_builder_t( self._get_files()
                                              , gccxml_path=autoconfig.gccxml.executable
                                              , include_paths=[autoconfig.boost.include]
                                              , undefine_symbols=['__MINGW32__']
                                              , compiler=pygccxml.utils.native_compiler.get_gccxml_compiler() )

        public_bases = mb.classes( 'public_base_t' )
        self.failUnless( 1 == len( public_bases ) )

        public_bases.include()
        self.failUnless( public_bases[0].ignore == False )

        mb.global_ns[ 'public_base_t' ].exclude()

        self.failUnless( public_bases[0].ignore == True )
Exemplo n.º 46
0
 def test(self):
     
     code = """
         namespace xyz{
             void do_smth( int, ... );
         }
     """
     
     mb = module_builder.module_builder_t( 
             [ module_builder.create_text_fc( code ) ]
             , gccxml_path=autoconfig.gccxml.executable )
     
     do_smth = mb.free_fun( 'do_smth' )
     
     self.failUnless( do_smth.exportable == False )
     print do_smth.why_not_exportable()
Exemplo n.º 47
0
 def __init__(self):
     self.__file = os.path.join( random_settings.working_dir, 'random_export.hpp' )
     self.__mb = module_builder.module_builder_t( 
                     [ parser.create_cached_source_fc( 
                         self.__file
                         , os.path.join( random_settings.generated_files_dir, 'random.xml' ) ) ]
                     , gccxml_path=random_settings.gccxml.executable
                     , include_paths=[random_settings.boost.include]
                     , define_symbols=random_settings.defined_symbols
                     , undefine_symbols=random_settings.undefined_symbols
                     , indexing_suite_version=2)
     self.generators = [   "ecuyer1988"
                           , "hellekalek1995"
                           , "kreutzer1986"
                           , "lagged_fibonacci1279"
                           , "lagged_fibonacci19937"
                           , "lagged_fibonacci2281"
                           , "lagged_fibonacci23209"
                           , "lagged_fibonacci3217"
                           , "lagged_fibonacci4423"
                           , "lagged_fibonacci44497"
                           , "lagged_fibonacci607"
                           , "lagged_fibonacci9689"
                           , "minstd_rand"
                           , "minstd_rand0"
                           , "mt11213b"
                           , "mt19937"
                           , "ranlux3"
                           , "ranlux3_01"
                           , "ranlux4"
                           , "ranlux4_01"
                           , "ranlux64_3_01"
                           , "ranlux64_4_01"
                           , "taus88" ]
 
     self.no_min_max = [ 'py_cauchy_distribution'
                         , 'py_bernoulli_distribution'
                         , 'py_binomial_distribution'
                         , 'py_poisson_distribution'
                         , 'py_normal_distribution'
                         , 'py_gamma_distribution'
                         , 'py_triangle_distribution'
                         , 'py_uniform_on_sphere'
                         , 'py_exponential_distribution'
                         , 'py_geometric_distribution'
                         , 'py_lognormal_distribution'
                         ]
    def test__getitem__(self):
        mb = module_builder.module_builder_t(
            self._get_files(),
            gccxml_path=autoconfig.gccxml.executable,
            include_paths=[autoconfig.boost.include],
            undefine_symbols=["__MINGW32__"],
        )

        public_bases = mb.classes("public_base_t")
        self.failUnless(1 == len(public_bases))

        public_bases.include()
        self.failUnless(public_bases[0].ignore == False)

        mb.global_ns["public_base_t"].exclude()

        self.failUnless(public_bases[0].ignore == True)
Exemplo n.º 49
0
def do_main():

  op_parser = OptionParser()
  op_parser.add_option("-o","--outputfile",type="string",dest="outputfile",action="store")
  op_parser.add_option("-m","--modulename",type="string",dest="modulename",action="store")
  op_parser.add_option("-I","--includepaths",type="string",dest="include_paths",action="store",default='')
  op_parser.add_option("-D","--define",type="string",dest="define_symbols",action="store",default='')
  op_parser.add_option("--gccxml_bin",type="string",dest="gccxml_bin",action="store",default='/usr/bin/gccxml')


  (options,input_files) = op_parser.parse_args(sys.argv)

  if options.outputfile == None :
    op_parser.error("Output file not specified")

  if options.modulename == None:
    op_parser.error("Module name not specified")  

  if os.path.exists(options.outputfile):
    os.remove(options.outputfile)

    
  print 'parsing input files',input_files[1:len(input_files)]


  mb = module_builder.module_builder_t(
	  files = input_files[1:len(input_files)]
	  , gccxml_path= options.gccxml_bin
	  , include_paths = [options.include_paths]
	  , define_symbols = [options.define_symbols]
	  ) 
	  
  #framework.is_abstract = True;
  #number.add_fake_constructors( number.calldefs( 'create' ) )

  #Now it is the time to give a name to our module
  mb.build_code_creator( module_name=options.modulename )

  #It is common requirement in software world - each file should have license
  mb.code_creator.license = '//Boost Software License( http://boost.org/more/license_info.html )'

  #I don't want absolute includes within code
  mb.code_creator.user_defined_directories.append( os.path.abspath('.') )

  #And finally we can write code to the disk
  mb.write_module( os.path.join( os.path.abspath('.'), options.outputfile ) )