Пример #1
0
def make_headerdb(layers):
    databases_len = len(layers[0])
    complementary_databases = [
        InMemoryCompilationDatabase() for _ in range(databases_len)
    ]

    db_files = set()
    for layer in layers:
        for database in layer:
            db_files.update(database.get_all_files())

    # loop until there is nothing more to resolve
    # we first get the files directly included by the compilation database
    # then the files directly included by these files and so on
    while True:
        # mapping of <header normalized absolute path> -> _Data
        db_update = {}
        for layer in layers:
            for db_idx, database in enumerate(layer):
                _make_headerdb1(database.get_all_compile_commands(), db_files,
                                db_idx, db_update)
        if not db_update:
            break
        layers = [[
            InMemoryCompilationDatabase() for _ in range(databases_len)
        ]]
        for k, v in db_update.items():
            db_files.add(k)
            for db_list in (layers[0], complementary_databases):
                db_list[v.db_idx].compile_commands.append(v.compile_command)
    return complementary_databases
Пример #2
0
 def complement(self, compile_commands):
     '''
     The output is returned sorted in the following order: file, directory,
     arguments.
     '''
     database = InMemoryCompilationDatabase(compile_commands)
     result = list(Complementer().complement(
         [[database]])[0].get_all_compile_commands())
     result.sort(key=operator.attrgetter('file', 'directory', 'arguments'))
     return result
Пример #3
0
 def _probe_dir1(self, directory):
     for compdb_cls in self._registry:
         with suppress(ProbeError):
             yield compdb_cls.probe_directory(directory)
             break
     else:
         # no compilation database found,
         # calling the interface's probe_directory() function
         # should raise a good probe error
         CompilationDatabaseInterface.probe_directory(directory)
         # make sure to raise something,
         # in case probe_directory() no longer asserts
         raise AssertionError
     for complementer in self._complementers:
         cache_path = os.path.join(directory, complementer.cache_filename)
         if os.path.exists(cache_path):
             yield JSONCompilationDatabase(cache_path)
         elif self.raise_on_missing_cache:
             raise ComplementerCacheNotFound(complementer, directory)
         else:
             yield InMemoryCompilationDatabase()