Exemplo n.º 1
0
def test_re_opening_cache_file():
    """
    Test re-oping cache files.

    This test is run by file_cache_tester.py in a subprocess.

    """

    data = autoconfig.data_directory

    # xml_generator has not been set
    if utils.xml_generator is not None:
        raise Exception

    # Try to reopen an old cache file and check if there is an exception
    # These old files do not know about the xml generator; a RuntimeError
    # should be thrown, asking to regenerate the cache file.
    c_file = os.path.join(data, 'old_cache.cache')
    error = False
    try:
        parser.file_cache_t(c_file)
    except RuntimeError:
        error = True
    if error is False:
        raise Exception

    # This cache file knows about the xml generator, and was generated
    # with CastXML. Loading the cache should set the utils.xml_generator.
    c_file = os.path.join(data, 'new_cache.cache')
    parser.file_cache_t(c_file)
    if "CastXML" not in utils.xml_generator:
        raise Exception
Exemplo n.º 2
0
def test_re_opening_cache_file():
    """
    Test re-oping cache files.

    This test is run by file_cache_tester.py in a subprocess.

    """

    data = autoconfig.data_directory

    # xml_generator has not been set
    if utils.xml_generator is not None:
        raise Exception

    # Try to reopen an old cache file and check if there is an exception
    # These old files do not know about the xml generator; a RuntimeError
    # should be thrown, asking to regenerate the cache file.
    c_file = os.path.join(data, 'old_cache.cache')
    error = False
    try:
        parser.file_cache_t(c_file)
    except RuntimeError:
        error = True
    if error is False:
        raise Exception

    # This cache file knows about the xml generator, and was generated
    # with CastXML. Loading the cache should set the utils.xml_generator.
    c_file = os.path.join(data, 'new_cache.cache')
    parser.file_cache_t(c_file)
    if "CastXML" not in utils.xml_generator:
        raise Exception
Exemplo n.º 3
0
 def test_from_file(self):
     declarations = parser.parse([self.header], self.config)
     cache = parser.file_cache_t(self.cache_file)
     cache.update(source_file=self.header, configuration=self.config, declarations=declarations, included_files=[])
     self.assertTrue(
         declarations == cache.cached_value(self.header, self.config),
         "cached declarations and source declarations are different",
     )
     cache.flush()
     cache = parser.file_cache_t(self.cache_file)
     self.assertTrue(
         declarations == cache.cached_value(self.header, self.config),
         ("cached declarations and source declarations are different, " + "after pickling"),
     )
Exemplo n.º 4
0
    def test_cache(self):
        cache = parser.file_cache_t(self.cache_file)
        reader = parser.source_reader_t(self.config, cache)
        decls1 = reader.read_file(self.header)
        cache.flush()
        cache = parser.file_cache_t(self.cache_file)
        reader = parser.source_reader_t(self.config, cache)
        decls2 = reader.read_file(self.header)

        enum_matcher = declarations.declaration_matcher_t(
            name="EColor", decl_type=declarations.enumeration_t)

        color1 = declarations.matcher.get_single(enum_matcher, decls1)
        color2 = declarations.matcher.get_single(enum_matcher, decls2)
        self.assertTrue(color1.values == color2.values)
 def test_cache( self ):
     cache = parser.file_cache_t( self.cache_file )
     reader = parser.source_reader_t( self.config, cache )
     decls1 = reader.read_file( self.header )
     cache.flush()
     cache = parser.file_cache_t( self.cache_file )
     reader = parser.source_reader_t( self.config, cache )
     decls2 = reader.read_file( self.header )
     
     enum_matcher = declarations.declaration_matcher_t( name="EColor"
                                                        , decl_type=declarations.enumeration_t )
     
     color1 = declarations.matcher.get_single( enum_matcher, decls1 )
     color2 = declarations.matcher.get_single( enum_matcher, decls2 )
     self.failUnless( color1.values == color2.values )
Exemplo n.º 6
0
 def test_from_file(self):
     declarations = parser.parse([self.header], self.config)
     cache = parser.file_cache_t(self.cache_file)
     cache.update(source_file=self.header,
                  configuration=self.config,
                  declarations=declarations,
                  included_files=[])
     self.assertTrue(
         declarations == cache.cached_value(self.header, self.config),
         "cached declarations and source declarations are different")
     cache.flush()
     cache = parser.file_cache_t(self.cache_file)
     self.assertTrue(
         declarations == cache.cached_value(self.header, self.config),
         ("cached declarations and source declarations are different, " +
          "after pickling"))
Exemplo n.º 7
0
    def test_update(self):

        # Save the content of the header file for later
        with open(self.header, "r") as old_header:
            content = old_header.read()

        declarations = parser.parse([self.header], self.config)
        cache = parser.file_cache_t(self.cache_file)
        cache.update(source_file=self.header,
                     configuration=self.config,
                     declarations=declarations,
                     included_files=[])
        self.assertTrue(
            declarations == cache.cached_value(self.header, self.config),
            "cached declarations and source declarations are different")
        self.touch()
        self.assertTrue(
            cache.cached_value(self.header, self.config) is None,
            "cache didn't recognize that some files on disk has been changed")

        # We wrote a //touch in the header file. Just replace the file with the
        # original content. The touched file would be sometimes commited by
        # error as it was modified.
        with open(self.header, "w") as new_header:
            new_header.write(content)
Exemplo n.º 8
0
    def test_update(self):

        # Save the content of the header file for later
        with open(self.header, "r") as old_header:
            content = old_header.read()

        declarations = parser.parse([self.header], self.config)
        cache = parser.file_cache_t(self.cache_file)
        cache.update(
            source_file=self.header,
            configuration=self.config,
            declarations=declarations,
            included_files=[])
        self.assertTrue(
            declarations == cache.cached_value(
                self.header,
                self.config),
            "cached declarations and source declarations are different")
        self.touch()
        self.assertTrue(
            cache.cached_value(self.header, self.config) is None,
            "cache didn't recognize that some files on disk has been changed")

        # We wrote a //touch in the header file. Just replace the file with the
        # original content. The touched file would be sometimes commited by
        # error as it was modified.
        with open(self.header, "w") as new_header:
            new_header.write(content)
def test_project_on_include_std_dot_hpp():
    include_std_header = os.path.join(autoconfig.data_directory,
                                      'include_std.hpp')
    clock_prev = time.perf_counter()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.project_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path), dcache)
    reader.read_files([include_std_header])
    dcache.flush()
    clock_now = time.perf_counter()
    print(('without cache: %f seconds' % (clock_now - clock_prev)))

    clock_prev = time.perf_counter()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.project_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path), dcache)
    reader.read_files([include_std_header])
    clock_now = time.perf_counter()
    print(('with cache   : %f seconds' % (clock_now - clock_prev)))
Exemplo n.º 10
0
def test_on_windows_dot_h():
    he = r"2003\Vc7\PlatformSDK\Include\windows.h"
    windows_header = r"D:\Program Files\Microsoft Visual Studio .NET " + he
    clock_prev = time.perf_counter()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.source_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path), dcache)
    reader.read_file(windows_header)
    dcache.flush()
    clock_now = time.perf_counter()
    print(('without cache: %f seconds' % (clock_now - clock_prev)))

    clock_prev = time.perf_counter()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.source_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path), dcache)
    reader.read_file(windows_header)
    clock_now = time.perf_counter()
    print(('with cache   : %f seconds' % (clock_now - clock_prev)))
Exemplo n.º 11
0
def test_source_on_include_std_dot_hpp():
    include_std_header = os.path.join(autoconfig.data_directory,
                                      'include_std.hpp')
    clock_prev = timeit.default_timer()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.source_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path), dcache)
    reader.read_file(include_std_header)
    dcache.flush()
    clock_now = timeit.default_timer()
    print('without cache: %f seconds' % (clock_now - clock_prev))

    clock_prev = timeit.default_timer()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.source_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path), dcache)
    reader.read_file(include_std_header)
    clock_now = timeit.default_timer()
    print('with cache   : %f seconds' % (clock_now - clock_prev))
Exemplo n.º 12
0
def test_on_windows_dot_h():
    he = r"2003\Vc7\PlatformSDK\Include\windows.h"
    windows_header = r"D:\Program Files\Microsoft Visual Studio .NET " + he
    clock_prev = time.clock()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.source_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path),
        dcache)
    reader.read_file(windows_header)
    dcache.flush()
    clock_now = time.clock()
    print('without cache: %f seconds' % (clock_now - clock_prev))

    clock_prev = time.clock()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.source_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path),
        dcache)
    reader.read_file(windows_header)
    clock_now = time.clock()
    print('with cache   : %f seconds' % (clock_now - clock_prev))
Exemplo n.º 13
0
def test_project_on_include_std_dot_hpp():
    include_std_header = os.path.join(
        autoconfig.data_directory,
        'include_std.hpp')
    clock_prev = time.clock()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.project_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path),
        dcache)
    reader.read_files([include_std_header])
    dcache.flush()
    clock_now = time.clock()
    print('without cache: %f seconds' % (clock_now - clock_prev))

    clock_prev = time.clock()
    dcache = parser.file_cache_t(dcache_file_name)
    reader = parser.project_reader_t(
        parser.xml_generator_configuration_t(
            xml_generator_path=autoconfig.generator_path),
        dcache)
    reader.read_files([include_std_header])
    clock_now = time.clock()
    print('with cache   : %f seconds' % (clock_now - clock_prev))
Exemplo n.º 14
0
   def parse(self):
      """Parse the header files and setup the known declarations.
      
      Currently this method can only be called once.
      This method can be called anytime after initialization and all
      Template() calls have been made.

      @returns: Returns the root of the declaration tree
      @rtype: L{IDecl<declwrapper.IDecl>}
      @postcondition: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored.
      """
      if self.mHeaderFiles==[]:
         raise ValueError, "No header files specified"
      
      if self.mVerbose:
         print "Parsing headers: ", self.mHeaderFiles

      # Record the time when parsing started...
      self.mStartTime = time.time()

      # Create and initialize the config object
      parser_cfg = parser.config_t(self.mGccXmlPath,
                                   self.mWorkingDir,
                                   self.mIncludePaths,
                                   define_symbols=self.mDefines,
                                   undefine_symbols=self.mUndefines,
                                   start_with_declarations=None)

      full_header_list = self.mHeaderFiles[:]
      
      # Handle template instantiation as needed      
      temp_file, temp_filename = (None,None)
      template_instantiation_text = self.buildTemplateFileContents()
      if None != template_instantiation_text:
         temp_filename = pygccxml.utils.create_temp_file_name(suffix=".h")
         temp_file = file(temp_filename, 'w')
         temp_file.write(template_instantiation_text)
         temp_file.close()
         if self.mVerbose:
            print "   creating template instantiation file: ", temp_filename
         full_header_list.append(temp_filename)      

      # Create the cache object...
      if self.mCacheDir!=None:
         if self.mVerbose:
            print "Using directory cache in '%s'"%self.mCacheDir
         cache = parser.directory_cache_t(self.mCacheDir)
      elif self.mCacheFile!=None:
         if self.mVerbose:
            print "Using file cache '%s'"%self.mCacheFile
         cache = parser.file_cache_t(self.mCacheFile)         
      else:
         if self.mVerbose:
            print "No cache in use"
         cache = None

      # Create the parser object...
      the_parser = parser.project_reader_t(config=parser_cfg, 
                                           cache=cache,
                                           decl_factory=decl_wrappers.dwfactory_t())
      # ...and parse the headers
      parsed_decls = the_parser.read_files(full_header_list, 
                                           parser.project_reader.COMPILATION_MODE.FILE_BY_FILE)
      
      assert len(parsed_decls) == 1    # assume that we get root of full tree
      self.mDeclRoot = parsed_decls[0]
      
      # Parse the files and add to decl root
      # - then traverse tree setting everything to ignore
      self.mDeclRootWrapper = DeclWrapper(self.mDeclRoot)
      # Set the module builder instance (this is done here and not in the
      # constructor so that Allen's DeclWrapper object still work as well)
      self.mDeclRootWrapper.modulebuilder = self
      self.mDeclRootWrapper.ignore()
      
      # Cleanup
      if temp_filename:
         pygccxml.utils.remove_file_no_raise( temp_filename )
      
      typedef_decls = declarations.make_flatten(parsed_decls)
      typedef_decls = decls = filter( lambda x: (isinstance( x, declarations.typedef_t ) and 
                                                 not x.name.startswith('__') and 
                                                 x.location.file_name != "<internal>")
                                      , typedef_decls )

      self.mTypeDefMap = {}
      for d in typedef_decls:
         type_def_name = d.name
         full_name = declarations.full_name(d)
         if full_name.startswith("::"):    # Remove the base namespace
            full_name = full_name[2:]
         real_type_name = d.type.decl_string
         if real_type_name.startswith("::"):    # Remove base namespace
            real_type_name = real_type_name[2:]   
         self.mTypeDefMap[full_name] = real_type_name

      self.mParseEndTime = time.time()
      if self.mVerbose:
         print "Completed parsing in %s."%self._time2str(self.mParseEndTime-self.mStartTime)

      return self.mDeclRootWrapper
Exemplo n.º 15
0
    def parse(self):
        """Parse the header files and setup the known declarations.
      
      Currently this method can only be called once.
      This method can be called anytime after initialization and all
      Template() calls have been made.

      :rtype: Returns the root of the declaration tree
      @rtype: L{IDecl<declwrapper.IDecl>}
      @postcondition: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored.
      """
        if self.mHeaderFiles == []:
            raise ValueError, "No header files specified"

        if self.mVerbose:
            print "Parsing headers: ", self.mHeaderFiles

        # Record the time when parsing started...
        self.mStartTime = time.time()

        # Create and initialize the config object
        parser_cfg = parser.config_t(self.mGccXmlPath,
                                     self.mWorkingDir,
                                     self.mIncludePaths,
                                     define_symbols=self.mDefines,
                                     undefine_symbols=self.mUndefines,
                                     start_with_declarations=None)

        full_header_list = self.mHeaderFiles[:]

        # Handle template instantiation as needed
        temp_file, temp_filename = (None, None)
        template_instantiation_text = self.buildTemplateFileContents()
        if None != template_instantiation_text:
            temp_filename = pygccxml.utils.create_temp_file_name(suffix=".h")
            temp_file = file(temp_filename, 'w')
            temp_file.write(template_instantiation_text)
            temp_file.close()
            if self.mVerbose:
                print "   creating template instantiation file: ", temp_filename
            full_header_list.append(temp_filename)

        # Create the cache object...
        if self.mCacheDir != None:
            if self.mVerbose:
                print "Using directory cache in '%s'" % self.mCacheDir
            cache = parser.directory_cache_t(self.mCacheDir)
        elif self.mCacheFile != None:
            if self.mVerbose:
                print "Using file cache '%s'" % self.mCacheFile
            cache = parser.file_cache_t(self.mCacheFile)
        else:
            if self.mVerbose:
                print "No cache in use"
            cache = None

        # Create the parser object...
        the_parser = parser.project_reader_t(
            config=parser_cfg,
            cache=cache,
            decl_factory=decl_wrappers.dwfactory_t())
        # ...and parse the headers
        parsed_decls = the_parser.read_files(
            full_header_list,
            parser.project_reader.COMPILATION_MODE.FILE_BY_FILE)

        assert len(parsed_decls) == 1  # assume that we get root of full tree
        self.mDeclRoot = parsed_decls[0]

        # Parse the files and add to decl root
        # - then traverse tree setting everything to ignore
        self.mDeclRootWrapper = DeclWrapper(self.mDeclRoot)
        # Set the module builder instance (this is done here and not in the
        # constructor so that Allen's DeclWrapper object still work as well)
        self.mDeclRootWrapper.modulebuilder = self
        self.mDeclRootWrapper.ignore()

        # Cleanup
        if temp_filename:
            pygccxml.utils.remove_file_no_raise(temp_filename)

        typedef_decls = declarations.make_flatten(parsed_decls)
        typedef_decls = decls = filter(
            lambda x:
            (isinstance(x, declarations.typedef_t) and not x.name.startswith(
                '__') and x.location.file_name != "<internal>"), typedef_decls)

        self.mTypeDefMap = {}
        for d in typedef_decls:
            type_def_name = d.name
            full_name = declarations.full_name(d)
            if full_name.startswith("::"):  # Remove the base namespace
                full_name = full_name[2:]
            real_type_name = d.type.decl_string
            if real_type_name.startswith("::"):  # Remove base namespace
                real_type_name = real_type_name[2:]
            self.mTypeDefMap[full_name] = real_type_name

        self.mParseEndTime = time.time()
        if self.mVerbose:
            print "Completed parsing in %s." % self._time2str(
                self.mParseEndTime - self.mStartTime)

        return self.mDeclRootWrapper
Exemplo n.º 16
0
def dopypp(task):

    global included_decls

    # Set the path for importing additional tools
    if not os.path.join(task.srcpath, 'tools', 'waf') in sys.path:
        sys.path.append(os.path.join(task.srcpath, 'tools', 'waf'))

    # Increase recursion limit for tough includes
    sys.setrecursionlimit(sys.getrecursionlimit()*2)

    from pyplusplus import module_builder, messages, utils, code_repository
    from pygccxml import declarations,parser
    from pyplusplus.module_builder import call_policies
    from pypp_utils import TemplateBuilder
    import logging

    # Disable some annoying messages
    if not Logs.verbose:
        module_builder.set_logger_level(logging.FATAL)
        messages.disable(messages.W1023)
        messages.disable(messages.W1025)
        messages.disable(messages.W1026)
        messages.disable(messages.W1027)
        messages.disable(messages.W1031)
        messages.disable(messages.W1043)
    elif Logs.verbose > 2:
        module_builder.set_logger_level(logging.DEBUG)

    ## ????????????????????????????????????? What is this for ?????????????????????????????
    logger_lock.acquire()
    log = logging.getLogger()
    temp_handler = None
    if len(log.handlers) > 0:
        temp_handler = log.handlers[0]
        log.removeHandler(log.handlers[0])
    logger_lock.release()

    # Create source list with proper directories
    sources = map(lambda a: os.path.abspath(os.path.join(task.bldpath, a.srcpath(task.env))), task.inputs)

    # Create include list
    global_includes = task.includes
    global_includes += task.env['CPPPATH']
    global_includes += [os.path.abspath(os.path.join(task.bldpath, i.srcpath(task.env))) for i in task.path_lst]

    try:
        #if int(task.env['CC_VERSION'][1]) >= 3:
            #compilerExec = task.env['CXX_OLD_VERSION'][0]
        #else:
        compilerExec = task.env['CXX'][0]

        # No cache can be used on mac-osx systems, otherwise pygccxml segfaults
        if sys.platform != 'darwin':
            mb = module_builder.module_builder_t(
                                    files=sources
                                    , start_with_declarations = task.start_decls
                                    , define_symbols = task.define_symbols
                                    , working_directory = task.bldpath
                                    , include_paths = global_includes
                                    , compiler = compilerExec
                                    , cache=parser.file_cache_t(os.path.abspath(os.path.join(task.bldpath, task.outputs[0].bldpath(task.env)+'_cache' ))))
        else:
            mb = module_builder.module_builder_t(
                                    files=sources
                                    , start_with_declarations = task.start_decls
                                    , define_symbols = task.define_symbols
                                    , working_directory = task.bldpath
                                    , include_paths = global_includes
                                    , compiler = compilerExec)
    except Exception, e:
        print e
        if temp_handler:
            log.addHandler(temp_handler)
        return 1