Example #1
0
///NOTE: when you change this, update @c defaultConfigure in cmakemanagertest.cpp
bool checkForNeedingConfigure( KDevelop::IProject* project )
{
    const KDevelop::Path builddir = currentBuildDir(project);
    if( !builddir.isValid() )
    {
        CMakeBuildDirChooser bd;

        KDevelop::Path folder = project->path();
        QString relative=CMake::projectRootRelative(project);
        folder.cd(relative);

        bd.setSourceFolder( folder );
        bd.setAlreadyUsed( CMake::allBuildDirs(project) );
        bd.setCMakeBinary( currentCMakeBinary(project) );

        if( !bd.exec() )
        {
            return false;
        }

        QString newbuilddir = bd.buildFolder().toLocalFile();
        int addedBuildDirIndex = buildDirCount( project ); // old count is the new index

        // Initialize the kconfig items with the values from the dialog, this ensures the settings
        // end up in the config file once the changes are saved
        qCDebug(CMAKE) << "adding to cmake config: new builddir index" << addedBuildDirIndex;
        qCDebug(CMAKE) << "adding to cmake config: builddir path " << bd.buildFolder();
        qCDebug(CMAKE) << "adding to cmake config: installdir " << bd.installPrefix();
        qCDebug(CMAKE) << "adding to cmake config: extra args" << bd.extraArguments();
        qCDebug(CMAKE) << "adding to cmake config: build type " << bd.buildType();
        qCDebug(CMAKE) << "adding to cmake config: cmake binary " << bd.cmakeBinary();
        qCDebug(CMAKE) << "adding to cmake config: environment <null>";
        CMake::setBuildDirCount( project, addedBuildDirIndex + 1 );
        CMake::setCurrentBuildDirIndex( project, addedBuildDirIndex );
        CMake::setCurrentBuildDir( project, bd.buildFolder() );
        CMake::setCurrentInstallDir( project, bd.installPrefix() );
        CMake::setCurrentExtraArguments( project, bd.extraArguments() );
        CMake::setCurrentBuildType( project, bd.buildType() );
        CMake::setCurrentCMakeBinary( project, bd.cmakeBinary() );
        CMake::setCurrentEnvironment( project, QString() );

        return true;
    } else if( !QFile::exists( KDevelop::Path(builddir, "CMakeCache.txt").toLocalFile() ) ||
                //TODO: maybe we could use the builder for that?
               !(QFile::exists( KDevelop::Path(builddir, "Makefile").toLocalFile() ) ||
                    QFile::exists( KDevelop::Path(builddir, "build.ninja").toLocalFile() ) ) )
    {
        // User entered information already, but cmake hasn't actually been run yet.
        return true;
    }
    return false;
}
Example #2
0
void updateConfig( KDevelop::IProject* project, int buildDirIndex)
{
    if (buildDirIndex < 0)
        return;

    KConfigGroup buildDirGrp = buildDirGroup( project, buildDirIndex );
    const KDevelop::Path builddir(buildDirGrp.readEntry( Config::Specific::buildDirPathKey, QString() ));
    const KDevelop::Path cacheFilePath( builddir, QStringLiteral("CMakeCache.txt"));
    QFile file(cacheFilePath.toLocalFile());
    const QMap<QString, QString> keys = {
        { Config::Specific::cmakeBinKey, QStringLiteral("CMAKE_COMMAND") },
        { Config::Specific::cmakeInstallDirKey, QStringLiteral("CMAKE_INSTALL_PREFIX") },
        { Config::Specific::cmakeBuildTypeKey, QStringLiteral("CMAKE_BUILD_TYPE") }
    };
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QTextStream in(&file);
        while (!in.atEnd())
        {
            QString line = in.readLine().trimmed();
            if(!line.isEmpty() && !line[0].isLetterOrNumber())
            {
                CacheLine c;
                c.readLine(line);

                if(c.isCorrect()) {
                    QString key = keys.value(c.name());
                    if (!key.isEmpty()) {
                        buildDirGrp.writeEntry( key, c.value() );
                    }
                }
            }
        }
    } else
        qCWarning(CMAKE) << "error. Could not find the file" << cacheFilePath;
}
Example #3
0
void setCurrentBuildDir( KDevelop::IProject* project, const KDevelop::Path& path )
{
    writeProjectParameter( project, Config::Specific::buildDirPathKey, path.toLocalFile() );
}
Example #4
0
void setCurrentCMakeBinary( KDevelop::IProject* project, const KDevelop::Path& path )
{
    writeProjectParameter( project, Config::Specific::cmakeBinKey, path.toLocalFile() );
}
Example #5
0
void setCurrentInstallDir( KDevelop::IProject* project, const KDevelop::Path& path )
{
    writeProjectParameter( project, Config::Specific::cmakeInstallDirKey, path.toLocalFile() );
}
Example #6
0
void Test::TestFindRailsRoot()
{
    KDevelop::Path path;

    // Empty URL.
    path = Helpers::findRailsRoot(QUrl(""));
    Q_ASSERT(!path.isValid());

    // App.
    path = Helpers::findRailsRoot(QUrl("/rails/app/controllers/file.rb"));
    Q_ASSERT(path.isValid());
    QCOMPARE(path.toLocalFile(), QString("/rails"));
    path = Helpers::findRailsRoot(QUrl("/rails/app/models/file.rb"));
    Q_ASSERT(path.isValid());
    QCOMPARE(path.toLocalFile(), QString("/rails"));
    path = Helpers::findRailsRoot(QUrl("/rails/app/views/file.rb"));
    Q_ASSERT(path.isValid());
    QCOMPARE(path.toLocalFile(), QString("/rails"));

    // Tests.
    path = Helpers::findRailsRoot(QUrl("/rails/test/file.rb"));
    Q_ASSERT(path.isValid());
    QCOMPARE(path.toLocalFile(), QString("/rails"));
    path = Helpers::findRailsRoot(QUrl("/rails/dir/test/file.rb"));
    Q_ASSERT(path.isValid());
    QCOMPARE(path.toLocalFile(), QString("/rails/dir"));

    // Invalids
    path = Helpers::findRailsRoot(QUrl("/rails/app/test/file.rb"));
    Q_ASSERT(!path.isValid());
    path = Helpers::findRailsRoot(QUrl("/rails/app/controllers"));
    Q_ASSERT(!path.isValid());
}