'Create the buffer-independent list of libs.'

def _buf_indep_libs_from_env(self, env):

    cache_key = 'ruby-libs'
    if (cache_key not in env.cache):
        env.add_pref_observer('ruby', self._invalidate_cache)
        env.add_pref_observer('rubyExtraPaths', self._invalidate_cache_and_rescan_extra_dirs)
        env.add_pref_observer('codeintel_selected_catalogs', self._invalidate_cache)
        db = self.mgr.db
        ruby = None
        if env.has_pref('ruby'):
            ruby = (env.get_pref('ruby').strip() or None)
        if ((not ruby) or (not exists(ruby))):
            ruby = self._ruby_from_env(env)
        if (not ruby):
            log.warn('no    Ruby    was    found    from    which    to    determine    the    import    path')
            (ver, libdir, sitelibdir, import_path, gem_lib_dirs) = (None, None, None, [], [])
        else:
            (ver, libdir, sitelibdir, import_path, gem_lib_dirs) = self._ruby_info_from_ruby(ruby, env)
        libs = []
        extra_dirs = self._extra_dirs_from_env(env)
        if extra_dirs:
            log.debug('Ruby    extra    lib    dirs:    %r', extra_dirs)
            libs.append(db.get_lang_lib('Ruby', 'extradirslib', extra_dirs))
        paths_from_libname = {'sitelib': [], 'envlib': [], 'stdlib': []}
        STATE = 'envlib'
        canon_libdir = ((libdir and normcase(libdir)) or None)
        canon_sitelibdir = ((sitelibdir and normcase(sitelibdir)) or None)
        for dir in import_path:
            canon_dir = normcase(dir)
            if (dir == '.'):
                continue
            elif dir.startswith(sitelibdir):
                STATE = 'sitelib'
            elif dir.startswith(libdir):
                STATE = 'stdlib'
            if (not exists(dir)):
                continue
            paths_from_libname[STATE].append(dir)
        log.debug('Ruby    %s    paths    for    each    lib:\n%s', ver, indent(pformat(paths_from_libname)))
        if paths_from_libname['envlib']:
            libs.append(db.get_lang_lib('Ruby', 'envlib', paths_from_libname['envlib']))
        if paths_from_libname['sitelib']:
            libs.append(db.get_lang_lib('Ruby', 'sitelib', paths_from_libname['sitelib']))
        if gem_lib_dirs:
            libs.append(db.get_lang_lib('Ruby', 'gemlib', gem_lib_dirs))
        catalog_selections = env.get_pref('codeintel_selected_catalogs')
        libs += [db.get_catalog_lib('Ruby', catalog_selections), db.get_stdlib('Ruby', ver)]
        env.cache[cache_key] = libs
    return env.cache[cache_key]
