コード例 #1
0
ファイル: Server.cpp プロジェクト: jbulow/rtags
bool Server::init(const Options &options)
{
    Client::initMessages();
    mIndexerThreadPool = new ThreadPool(options.threadCount);

    mOptions = options;
    if (options.options & ClangIncludePath) {
        Path clangPath = Path::resolved(CLANG_INCLUDEPATH);
        clangPath.prepend("-I");
        mOptions.defaultArguments.append(clangPath);
    } else {
        mOptions.defaultArguments.append("-nobuiltininc");
        mOptions.defaultArguments.append("-nostdinc++");
    }

    if (options.options & UnlimitedErrors)
        mOptions.defaultArguments.append("-ferror-limit=0");
    if (options.options & Wall)
        mOptions.defaultArguments.append("-Wall");
    if (options.options & SpellChecking)
        mOptions.defaultArguments << "-fspell-checking";
    mClangPath = Path::resolved(CLANG_BIN "/clang");
    error() << "using args:" << String::join(mOptions.defaultArguments, " ");

    if (mOptions.options & ClearProjects) {
        clearProjects();
    }

    for (int i=0; i<10; ++i) {
        mServer = new SocketServer;
        if (mServer->listenUnix(mOptions.socketFile)) {
            break;
        }
        delete mServer;
        mServer = 0;
        if (!i) {
            enum { Timeout = 5000 };
            Client client(mOptions.socketFile, Timeout, Client::DontWarnOnConnectionFailure);
            QueryMessage msg(QueryMessage::Shutdown);
            client.message(&msg);
        }
        sleep(1);
        Path::rm(mOptions.socketFile);
    }
    if (!mServer) {
        error("Unable to listen on %s", mOptions.socketFile.constData());
        return false;
    }

    restoreFileIds();
    mServer->clientConnected().connect(this, &Server::onNewConnection);
    reloadProjects();

    return true;
}
コード例 #2
0
ファイル: Server.cpp プロジェクト: jsyjr/rtags
bool Server::init(const Options &options)
{
    {
        Path dir(RTAGS_BIN);
        dir.resolve();
        List<Path> plugins = dir.files(Path::File);
        Path executableDir = Rct::executablePath().resolved().parentDir();
        if (dir != executableDir)
            plugins += executableDir.files(Path::File);
        for (int i=0; i<plugins.size(); ++i) {
            if (mPluginFactory.addPlugin(plugins.at(i))) {
                error() << "Loaded plugin" << plugins.at(i);
            }
        }
    }
    RTags::initMessages();

    mIndexerThreadPool = new ThreadPool(options.threadCount);
    mQueryThreadPool = new ThreadPool(2);

    mOptions = options;
    if (options.options & NoBuiltinIncludes) {
        mOptions.defaultArguments.append("-nobuiltininc");
        mOptions.defaultArguments.append("-nostdinc++");
    } else {
        Path clangPath = Path::resolved(CLANG_INCLUDEPATH);
        clangPath.prepend("-I");
        mOptions.defaultArguments.append(clangPath);
    }

    if (options.options & UnlimitedErrors)
        mOptions.defaultArguments.append("-ferror-limit=0");
    if (options.options & Wall)
        mOptions.defaultArguments.append("-Wall");
    if (options.options & SpellChecking)
        mOptions.defaultArguments << "-fspell-checking";
    error() << "using args:" << String::join(mOptions.defaultArguments, " ");

    if (mOptions.options & ClearProjects) {
        clearProjects();
    }

    for (int i=0; i<10; ++i) {
        mServer.reset(new SocketServer);
        if (mServer->listen(mOptions.socketFile)) {
            break;
        }
        mServer.reset();
        if (!i) {
            enum { Timeout = 1000 };
            Connection connection;
            if (connection.connectToServer(mOptions.socketFile, Timeout)) {
                connection.send(QueryMessage(QueryMessage::Shutdown));
                connection.disconnected().connect(std::bind([](){ EventLoop::eventLoop()->quit(); }));
                connection.finished().connect(std::bind([](){ EventLoop::eventLoop()->quit(); }));
                EventLoop::eventLoop()->exec(Timeout);
            }
        }
        sleep(1);
        Path::rm(mOptions.socketFile);
    }
    if (!mServer) {
        error("Unable to listen on %s", mOptions.socketFile.constData());
        return false;
    }

    restoreFileIds();
    mServer->newConnection().connect(std::bind(&Server::onNewConnection, this));
    reloadProjects();
    if (!(mOptions.options & NoStartupCurrentProject)) {
        Path current = Path(mOptions.dataDir + ".currentProject").readAll(1024);
        if (current.size() > 1) {
            current.chop(1);
            if (!setCurrentProject(current)) {
                error() << "Can't restore project" << current;
                unlink((mOptions.dataDir + ".currentProject").constData());
            }
        }
    }

    if (mOptions.clearCompletionCacheInterval && mOptions.completionCacheSize) {
        clearCompletionCache();
    }

    return true;
}
コード例 #3
0
ファイル: Server.cpp プロジェクト: qyqx/rtags
bool Server::init(const Options &options)
{
    {
        List<Path> plugins = Rct::executablePath().parentDir().files(Path::File);
        for (int i=0; i<plugins.size(); ++i) {
            if (mPluginFactory.addPlugin(plugins.at(i))) {
                error() << "Loaded plugin" << plugins.at(i);
            }
        }
    }
    RTags::initMessages();

    mIndexerThreadPool = new ThreadPool(options.threadCount, options.clangStackSize);

    mOptions = options;
    if (options.options & NoBuiltinIncludes) {
        mOptions.defaultArguments.append("-nobuiltininc");
        mOptions.defaultArguments.append("-nostdinc++");
    } else {
        Path clangPath = Path::resolved(CLANG_INCLUDEPATH);
        clangPath.prepend("-I");
        mOptions.defaultArguments.append(clangPath);
    }

    if (options.options & UnlimitedErrors)
        mOptions.defaultArguments.append("-ferror-limit=0");
    if (options.options & Wall)
        mOptions.defaultArguments.append("-Wall");
    if (options.options & SpellChecking)
        mOptions.defaultArguments << "-fspell-checking";
    error() << "using args:" << String::join(mOptions.defaultArguments, " ");

    if (mOptions.options & ClearProjects) {
        clearProjects();
    }

    for (int i=0; i<10; ++i) {
        mServer = new SocketServer;
        if (mServer->listenUnix(mOptions.socketFile)) {
            break;
        }
        delete mServer;
        mServer = 0;
        if (!i) {
            enum { Timeout = 1000 };
            Client client;
            if (client.connectToServer(mOptions.socketFile, Timeout)) {
                QueryMessage msg(QueryMessage::Shutdown);
                client.send(&msg, Timeout);
            }
        }
        sleep(1);
        Path::rm(mOptions.socketFile);
    }
    if (!mServer) {
        error("Unable to listen on %s", mOptions.socketFile.constData());
        return false;
    }

    restoreFileIds();
    mServer->clientConnected().connect(this, &Server::onNewConnection);
    reloadProjects();
    if (!(mOptions.options & NoStartupCurrentProject)) {
        Path current = Path(mOptions.dataDir + ".currentProject").readAll(1024);
        if (current.size() > 1) {
            current.chop(1);
            if (!setCurrentProject(current)) {
                error() << "Can't restore project" << current;
                unlink((mOptions.dataDir + ".currentProject").constData());
            }
        }
    }

    return true;
}
コード例 #4
0
ファイル: Server.cpp プロジェクト: rosrad/rtags
bool Server::init(const Options &options)
{
    RTags::initMessages();

    mOptions = options;
    mSuspended = (options.options & StartSuspended);
    Path clangPath = Path::resolved(CLANG_INCLUDEPATH_STR);
    mOptions.includePaths.append(clangPath);
#ifdef OS_Darwin
    if (clangPath.exists()) {
        Path cppClangPath = clangPath + "../../../c++/v1/";
        cppClangPath.resolve();
        if (cppClangPath.isDir()) {
            mOptions.includePaths.append(cppClangPath);
        } else {
            cppClangPath = clangPath + "../../../../include/c++/v1/";
            cppClangPath.resolve();
            if (cppClangPath.isDir()) {
                mOptions.includePaths.append(cppClangPath);
            } else {
                error("Unable to find libc++ include path (.../c++/v1) near " CLANG_INCLUDEPATH_STR );
                return false;
            }
        }
        // this seems to be the only way we get things like cstdint
    }
#endif

    if (!(options.options & NoUnlimitedErrors))
        mOptions.defaultArguments << "-ferror-limit=0";
    if (options.options & Wall)
        mOptions.defaultArguments << "-Wall";
    if (options.options & SpellChecking)
        mOptions.defaultArguments << "-fspell-checking";
    if (!(options.options & NoNoUnknownWarningsOption))
        mOptions.defaultArguments.append("-Wno-unknown-warning-option");
    Log l(Error);
    l << "Running with" << mOptions.jobCount << "jobs, using args:"
      << String::join(mOptions.defaultArguments, ' ') << '\n';
    l << "Includepaths:" << String::join(mOptions.includePaths, ' ');

    if (mOptions.options & ClearProjects) {
        clearProjects();
    }

    for (int i=0; i<10; ++i) {
        mUnixServer.reset(new SocketServer);
        if (mUnixServer->listen(mOptions.socketFile)) {
            break;
        }
        mUnixServer.reset();
        if (!i) {
            enum { Timeout = 1000 };
            Connection connection;
            if (connection.connectUnix(mOptions.socketFile, Timeout)) {
                connection.send(QueryMessage(QueryMessage::Shutdown));
                connection.disconnected().connect(std::bind([](){ EventLoop::eventLoop()->quit(); }));
                connection.finished().connect(std::bind([](){ EventLoop::eventLoop()->quit(); }));
                EventLoop::eventLoop()->exec(Timeout);
            }
        } else {
            sleep(1);
        }
        Path::rm(mOptions.socketFile);
    }
    if (!mUnixServer) {
        error("Unable to listen on %s", mOptions.socketFile.constData());
        return false;
    }

    restoreFileIds();
    mUnixServer->newConnection().connect(std::bind(&Server::onNewConnection, this, std::placeholders::_1));
    reloadProjects();
    if (!(mOptions.options & NoStartupCurrentProject)) {
        Path current = Path(mOptions.dataDir + ".currentProject").readAll(1024);
        if (current.size() > 1) {
            current.chop(1);
            const auto project = mProjects.value(current);
            if (!project) {
                error() << "Can't restore project" << current;
                unlink((mOptions.dataDir + ".currentProject").constData());
            } else {
                setCurrentProject(project);
            }
        }
    }

    return true;
}