Пример #1
1
std::string MsvcCompilerSupport::compileCppModule(const Pothos::Util::CompilerArgs &compilerArgs)
{
    std::vector<std::string> tempFilesToCleanup;

    //create compiler bat script
    const auto clBatPath = Poco::TemporaryFile::tempName() + ".bat";
    tempFilesToCleanup.push_back(clBatPath);
    std::ofstream clBatFile(clBatPath.c_str());
    clBatFile << "call \"" << _vcvars_path << "\"" << std::endl;
    clBatFile << "cl.exe %*" << std::endl;
    clBatFile << "exit /b %ERRORLEVEL%" << std::endl;
    clBatFile.close();

    //create args
    Poco::Process::Args args;
    args.push_back("/LD"); //Creates a dynamic-link library
    #ifdef _DEBUG
    args.push_back("/MDd"); //Creates a multithreaded DLL
    #else
    args.push_back("/MD"); //Creates a multithreaded DLL
    #endif

    //add libraries
    for (const auto &library : compilerArgs.libraries)
    {
        args.push_back("\""+library+"\"");
    }

    //add compiler flags
    for (const auto &flag : compilerArgs.flags)
    {
        args.push_back(flag);
    }

    //add include paths
    for (const auto &include : compilerArgs.includes)
    {
        args.push_back("/I");
        args.push_back("\""+include+"\"");
    }

    //add compiler sources
    for (const auto &source : compilerArgs.sources)
    {
        const auto filePath = Poco::TemporaryFile::tempName() + ".cpp";
        tempFilesToCleanup.push_back(filePath);
        std::ofstream(filePath.c_str()).write(source.data(), source.size());
        args.push_back("/Tp"); //Specifies a C++ source file
        args.push_back(filePath);
    }

    //create temp out file
    const auto outPath = Poco::TemporaryFile::tempName() + Poco::SharedLibrary::suffix();
    tempFilesToCleanup.push_back(outPath);
    args.push_back("/link");
    args.push_back("/out:"+outPath);

    //log the command
    std::string cmdToLog = "cl.exe ";
    for (const auto &a : args) cmdToLog += a + " ";
    //poco_information(Poco::Logger::get("Pothos.MsvcCompilerSupport.compileCppModule"), cmdToLog);

    //launch
    Poco::Pipe outPipe;
    Poco::Process::Env env;
    Poco::ProcessHandle ph(Poco::Process::launch(
        clBatPath, args, nullptr, &outPipe, &outPipe, env));

    //handle error case
    if (ph.wait() != 0 or not Poco::File(outPath.c_str()).exists())
    {
        Poco::PipeInputStream errStream(outPipe);
        const std::string errMsgBuff = std::string(
            std::istreambuf_iterator<char>(errStream),
            std::istreambuf_iterator<char>());
        cleanupTempFiles(tempFilesToCleanup);
        throw Pothos::Exception("MsvcCompilerSupport::compileCppModule", errMsgBuff);
    }

    //output file to string
    std::ifstream outFile(outPath.c_str(), std::ios::binary);
    const std::string outBuff = std::string(
        std::istreambuf_iterator<char>(outFile),
        std::istreambuf_iterator<char>());
    cleanupTempFiles(tempFilesToCleanup);
    return outBuff;
}
Пример #2
0
std::string ClangCompilerSupport::compileCppModule(const Pothos::Util::CompilerArgs &compilerArgs)
{
    std::vector<std::string> tempFilesToCleanup;

    //create args
    Poco::Process::Args args;

    //add libraries
    for (const auto &library : compilerArgs.libraries)
    {
        args.push_back(library);
    }

    //add compiler flags
    args.push_back("-std=c++11");
    args.push_back("-stdlib=libc++");
    args.push_back("-shared");
    args.push_back("-fPIC");
    for (const auto &flag : compilerArgs.flags)
    {
        args.push_back(flag);
    }

    //add include paths
    for (const auto &include : compilerArgs.includes)
    {
        args.push_back("-I");
        args.push_back(include);
    }

    //add compiler sources
    args.push_back("-x");
    args.push_back("c++");
    if (compilerArgs.sources.size() == 1)
    {
        args.push_back("-"); //stdin optimization for single source
    }
    else for (const auto &source : compilerArgs.sources)
    {
        const auto filePath = Poco::TemporaryFile::tempName() + ".cpp";
        tempFilesToCleanup.push_back(filePath);
        std::ofstream(filePath.c_str()).write(source.data(), source.size());
        args.push_back(filePath);
    }

    //create temp out file
    const auto outPath = Poco::TemporaryFile::tempName() + Poco::SharedLibrary::suffix();
    tempFilesToCleanup.push_back(outPath);
    args.push_back("-o");
    args.push_back(outPath);

    //launch
    Poco::Pipe inPipe, outPipe;
    Poco::Process::Env env;
    Poco::ProcessHandle ph(Poco::Process::launch(
        "clang++", args, &inPipe, &outPipe, &outPipe, env));

    //dump single source into stdin
    if (compilerArgs.sources.size() == 1)
    {
        Poco::PipeOutputStream inStream(inPipe);
        inStream.write(compilerArgs.sources[0].data(), compilerArgs.sources[0].size());
        inStream.close();
    }

    //handle error case
    if (ph.wait() != 0)
    {
        Poco::PipeInputStream errStream(outPipe);
        const std::string errMsgBuff = std::string(
            std::istreambuf_iterator<char>(errStream),
            std::istreambuf_iterator<char>());
        cleanupTempFiles(tempFilesToCleanup);
        throw Pothos::Exception("ClangCompilerSupport::compileCppModule", errMsgBuff);
    }

    //output file to string
    std::ifstream outFile(outPath.c_str(), std::ios::binary);
    const std::string outBuff = std::string(
        std::istreambuf_iterator<char>(outFile),
        std::istreambuf_iterator<char>());
    cleanupTempFiles(tempFilesToCleanup);
    return outBuff;
}
Пример #3
0
extern "C" KDE_EXPORT int kdemain(int argc, char **argv)
{
    KAboutData about("cervisia", 0, ki18n("Cervisia"), CERVISIA_VERSION,
                     ki18n("A CVS frontend"), KAboutData::License_GPL,
                     ki18n("Copyright (c) 1999-2002 Bernd Gehrmann\n"
                           "Copyright (c) 2002-2008 the Cervisia authors"), KLocalizedString(),
                     "http://cervisia.kde.org");

    about.addAuthor(ki18n("Bernd Gehrmann"), ki18n("Original author and former "
                    "maintainer"), "*****@*****.**");
    about.addAuthor(ki18n("Christian Loose"), ki18n("Maintainer"),
                    "*****@*****.**");
    about.addAuthor(ki18n("Andr\303\251 W\303\266bbeking"), ki18n("Developer"),
                    "*****@*****.**");
    about.addAuthor(ki18n("Carlos Woelz"), ki18n("Documentation"),
                    "*****@*****.**");

    about.addCredit(ki18n("Richard Moore"), ki18n("Conversion to KPart"),
                    "*****@*****.**");
    about.addCredit(ki18n("Laurent Montel"), ki18n("Conversion to D-Bus"),
                    "*****@*****.**");

    KCmdLineArgs::init(argc, argv, &about);

    KCmdLineOptions options;
    options.add("+[directory]", ki18n("The sandbox to be loaded"));
    options.add("resolve <file>", ki18n("Show resolve dialog for the given file"));
    options.add("log <file>", ki18n("Show log dialog for the given file"));
    options.add("annotate <file>", ki18n("Show annotation dialog for the given file"));
    KCmdLineArgs::addCmdLineOptions(options);

    KApplication app;

    QString resolvefile = KCmdLineArgs::parsedArgs()->getOption("resolve");
    if (!resolvefile.isEmpty())
        return ShowResolveDialog(resolvefile);

    // is command line option 'show log dialog' specified?
    QString logFile = KCmdLineArgs::parsedArgs()->getOption("log");
    if( !logFile.isEmpty() )
        return ShowLogDialog(logFile);

    // is command line option 'show annotation dialog' specified?
    QString annotateFile = KCmdLineArgs::parsedArgs()->getOption("annotate");
    if( !annotateFile.isEmpty() )
        return ShowAnnotateDialog(annotateFile);

    if ( app.isSessionRestored() ) {
        RESTORE(CervisiaShell);
    } else {
        CervisiaShell* shell = new CervisiaShell();

        const KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
        if( args->count() )
        {
            KUrl directory = args->url(0);
            shell->openURL(directory);
        }
        else
            shell->openURL();

        shell->setWindowIcon(qApp->windowIcon());
        shell->show();
    }

    int res = app.exec();
    cleanupTempFiles();
    return res;
}
Пример #4
0
extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
{
    KLocalizedString::setApplicationDomain("cervisia");

    QApplication app(argc, argv);

    KAboutData about("cervisia", i18n("Cervisia"), CERVISIA_VERSION,
                     i18n("A CVS frontend"), KAboutLicense::GPL,
                     i18n("Copyright (c) 1999-2002 Bernd Gehrmann\n"
                          "Copyright (c) 2002-2008 the Cervisia authors"), QString(),
                     QLatin1String("http://cervisia.kde.org"));

    about.addAuthor(i18n("Bernd Gehrmann"), i18n("Original author and former "
                    "maintainer"), "*****@*****.**");
    about.addAuthor(i18n("Christian Loose"), i18n("Maintainer"),
                    "*****@*****.**");
    about.addAuthor(i18n("Andr\303\251 W\303\266bbeking"), i18n("Developer"),
                    "*****@*****.**");
    about.addAuthor(i18n("Carlos Woelz"), i18n("Documentation"),
                    "*****@*****.**");

    about.addCredit(i18n("Richard Moore"), i18n("Conversion to KPart"),
                    "*****@*****.**");
    about.addCredit(i18n("Laurent Montel"), i18n("Conversion to D-Bus"),
                    "*****@*****.**");
    about.addCredit(i18n("Martin Koller"), i18n("Port to KDE Frameworks 5"),
                    "*****@*****.**");

    KAboutData::setApplicationData(about);

    QCommandLineParser parser;
    about.setupCommandLine(&parser);

    parser.addPositionalArgument(QLatin1String("directory"), i18n("The sandbox to be loaded"), QLatin1String("[directory]"));
    parser.addOption(QCommandLineOption(QLatin1String("resolve"), i18n("Show resolve dialog for the given file."), QLatin1String("file")));
    parser.addOption(QCommandLineOption(QLatin1String("log"), i18n("Show log dialog for the given file."), QLatin1String("file")));
    parser.addOption(QCommandLineOption(QLatin1String("annotate"), i18n("Show annotation dialog for the given file."), QLatin1String("file")));
    parser.addVersionOption();
    parser.addHelpOption();

    parser.process(app);
    about.processCommandLine(&parser);

    QString resolvefile = parser.value(QLatin1String("resolve"));
    if (!resolvefile.isEmpty())
        return ShowResolveDialog(resolvefile);

    // is command line option 'show log dialog' specified?
    QString logFile = parser.value(QLatin1String("log"));
    if( !logFile.isEmpty() )
        return ShowLogDialog(logFile);

    // is command line option 'show annotation dialog' specified?
    QString annotateFile = parser.value(QLatin1String("annotate"));
    if( !annotateFile.isEmpty() )
        return ShowAnnotateDialog(annotateFile);

    if ( app.isSessionRestored() ) {
        RESTORE(CervisiaShell);
    } else {
        CervisiaShell* shell = new CervisiaShell();

        if( parser.positionalArguments().count() )
        {
            QDir dir(parser.positionalArguments()[0]);
            QUrl directory = QUrl::fromLocalFile(dir.absolutePath());
            shell->openURL(directory);
        }
        else
            shell->openURL();

        shell->setWindowIcon(qApp->windowIcon());
        shell->show();
    }

    int res = app.exec();
    cleanupTempFiles();
    return res;
}