예제 #1
0
    def _FindDBForFile(self, path):
        file_dir = os.path.dirname(path)
        for folder in PathsToAllParentFolders(file_dir):
            # Note: this name is not part of the standard, but CMake outputs the DB
            # and calls it this. Consider using other known filenames once they exist
            # for swift.
            db_file_name = 'compile_commands.json'
            absolute_db_path = folder + '/' + db_file_name
            if not os.path.isfile(absolute_db_path):
                continue

            with self._db_lock:
                cached_db = self._dbs_by_folder.get(folder)
                # If there is a cached DB, and it's is still up to date then use it
                incoming_hash = CompilationDatabaseHash(absolute_db_path)
                if cached_db and incoming_hash == cached_db.DBHash():
                    # DB CacheHit
                    return cached_db

            db = CompilationDatabase()
            db.Load(absolute_db_path)
            with self._db_lock:
                self._dbs_by_folder[folder] = db
                return db
        logging.debug("No DB For File: " + path)
        return None
예제 #2
0
파일: flags.py 프로젝트: nerokapa/ycmd
  def FindCompilationDatabase( self, file_dir ):
    # We search up the directory hierarchy, to first see if we have a
    # compilation database already for that path, or if a compile_commands.json
    # file exists in that directory.
    for folder in PathsToAllParentFolders( file_dir ):
      # Try/catch to syncronise access to cache
      try:
        database = self.compilation_database_dir_map[ folder ]
        if database:
          return database

        raise NoCompilationDatabase
      except KeyError:
        pass

      compile_commands = os.path.join( folder, 'compile_commands.json' )
      if os.path.exists( compile_commands ):
        database = ycm_core.CompilationDatabase( folder )

        if database.DatabaseSuccessfullyLoaded():
          self.compilation_database_dir_map[ folder ] = database
          return database

    # Nothing was found. No compilation flags are available.
    # Note: we cache the fact that none was found for this folder to speed up
    # subsequent searches.
    self.compilation_database_dir_map[ file_dir ] = None
    raise NoCompilationDatabase
예제 #3
0
def _ExtraConfModuleSourceFilesForFile(filename):
    """For a given filename, search all parent folders for YCM_EXTRA_CONF_FILENAME
  files that will compute the flags necessary to compile the file.
  If _GlobalYcmExtraConfFileLocation() exists it is returned as a fallback."""

    for folder in PathsToAllParentFolders(filename):
        candidate = os.path.join(folder, YCM_EXTRA_CONF_FILENAME)
        if os.path.exists(candidate):
            yield candidate
    global_ycm_extra_conf = _GlobalYcmExtraConfFileLocation()
    if (global_ycm_extra_conf and os.path.exists(global_ycm_extra_conf)):
        yield global_ycm_extra_conf
예제 #4
0
def _ExtraConfModuleSourceFilesForFile(filename):
    """For a given filename, search all parent folders for YCM_EXTRA_CONF_FILENAME
  files that will compute the flags necessary to compile the file.
  If _GlobalYcmExtraConfFileLocation() exists it is returned as a fallback.
  Otherwise, we return the "default" extra_conf file. This file applies
  best-efforts to generate flags according to a series of heuristics (such as
  looking for a compilation database)"""

    for folder in PathsToAllParentFolders(filename):
        candidate = os.path.join(folder, YCM_EXTRA_CONF_FILENAME)
        if os.path.exists(candidate):
            yield candidate
    global_ycm_extra_conf = _GlobalYcmExtraConfFileLocation()
    if (global_ycm_extra_conf and os.path.exists(global_ycm_extra_conf)):
        yield global_ycm_extra_conf

    yield YCMD_DEFAULT_EXTRA_CONF_PATH
예제 #5
0
def CompilationDatabaseExists(file_dir):
    for folder in PathsToAllParentFolders(file_dir):
        if os.path.exists(os.path.join(folder, 'compile_commands.json')):
            return True

    return False
예제 #6
0
def ProjectRoot(path):
    for dir in PathsToAllParentFolders(path):
        if os.path.isfile(os.path.join(dir, 'engine.cfg')):
            return dir