File: projectsgenerator.cpp

package info (click to toggle)
kdevelop 4%3A5.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 57,892 kB
  • sloc: cpp: 278,773; javascript: 3,558; python: 3,385; sh: 1,317; ansic: 689; xml: 273; php: 95; makefile: 40; lisp: 13; sed: 12
file content (210 lines) | stat: -rw-r--r-- 7,804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * Copyright 2014 Sergey Kalinichev <kalinichev.so.0@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "projectsgenerator.h"

#include <tests/kdevsignalspy.h>

#include <interfaces/icore.h>
#include <interfaces/iproject.h>
#include <interfaces/iprojectcontroller.h>
#include <util/path.h>

#include <QDir>
#include <QFile>
#include <QTextStream>
#include <QDebug>


using namespace KDevelop;

namespace
{
/// @param projectFile projectName.kdev4 file
IProject* loadProject( const QString& projectFile, const QString& projectName )
{
    auto* projectSpy = new KDevSignalSpy( ICore::self()->projectController(), SIGNAL(projectOpened(KDevelop::IProject*)) );
    ICore::self()->projectController()->openProject( QUrl::fromLocalFile(projectFile) );

    if( !projectSpy->wait( 5000 ) ) {
        qFatal("Expected project to be loaded within 5 seconds, but this didn't happen");
    }
    IProject* project = ICore::self()->projectController()->findProjectByName( projectName );

    return project;
}

void createFile( QFile& file )
{
    file.remove();
    if ( !file.open( QIODevice::ReadWrite ) ) {
        qFatal("Cannot create the file %s", file.fileName().toUtf8().constData());
    }
}
}

IProject* ProjectsGenerator::GenerateSimpleProject()
{
    // directory structure:
    // ./simpleproject.kdev4
    // ./src/main.cpp
    // ./.kdev4/simpleproject.kdev4

    const QString sp = QStringLiteral( "simpleproject" );
    auto rootFolder = QDir::temp();
    QDir(rootFolder.absolutePath() + "/" + sp).removeRecursively();
    rootFolder.mkdir( sp );
    rootFolder.cd( sp );
    rootFolder.mkdir( QStringLiteral("src") );
    rootFolder.mkdir( QStringLiteral(".kdev4") );

    {
        QFile file( rootFolder.filePath( QStringLiteral("simpleproject.kdev4") ) );
        createFile( file );
        QTextStream stream1( &file );
        stream1 << "[Project]\nName=SimpleProject\nManager=KDevCustomBuildSystem";
    }
    {
        QFile file( rootFolder.filePath( QStringLiteral("src/main.cpp") ) );
        createFile( file );
    }
    {
        QFile file( rootFolder.filePath( QStringLiteral(".kdev4/simpleproject.kdev4") ) );
        createFile( file );
        QTextStream stream( &file );
        stream << "[Buildset]\n" <<
        "BuildItems=@Variant(\\x00\\x00\\x00\\t\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0b\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x1a\\x00S\\x00i\\x00m\\x00p\\x00l\\x00e\\x00P\\x00r\\x00o\\x00j\\x00e\\x00c\\x00t)\n" <<
        "[CustomDefinesAndIncludes][ProjectPath0]\n" <<
        "Path=/\n" <<
        "[CustomDefinesAndIncludes][ProjectPath0][Defines]\n" <<
        "_DEBUG=\n" <<
        "VARIABLE=VALUE\n" <<
        "[CustomDefinesAndIncludes][ProjectPath0][Includes]\n" <<
        "1=" << QDir::rootPath() << "usr/include/mydir\n" <<
        "[Project]\n" <<
        "VersionControlSupport=\n";
    }
    return loadProject( QDir::tempPath() + "/simpleproject/simpleproject.kdev4", QStringLiteral("SimpleProject") );
}

IProject* ProjectsGenerator::GenerateMultiPathProject()
{
    // directory structure:
    // ./multipathproject.kdev4
    // ./src/main.cpp
    // ./anotherFolder/tst.h
    // ./.kdev4/multipathproject.kdev4

    const QString mp = QStringLiteral( "multipathproject" );
    auto rootFolder = QDir::temp();
    QDir(rootFolder.absolutePath() + "/" + mp).removeRecursively();
    rootFolder.mkdir( mp );
    rootFolder.cd( mp );
    rootFolder.mkdir( QStringLiteral("src") );
    rootFolder.mkdir( QStringLiteral(".kdev4") );
    rootFolder.mkdir( QStringLiteral("anotherFolder") );

    {
        QFile file( rootFolder.filePath( QStringLiteral("multipathproject.kdev4") ) );
        createFile( file );
        QTextStream stream1( &file );
        stream1 << "[Project]\nName=MultiPathProject\nManager=KDevCustomBuildSystem";
        ;
    }
    {
        QFile file1( rootFolder.filePath( QStringLiteral("src/main.cpp") ) );
        createFile( file1 );
        QFile file2( rootFolder.filePath( QStringLiteral("anotherFolder/tst.h") ) );
        createFile( file2 );
    }
    {
        QFile file( rootFolder.filePath( QStringLiteral(".kdev4/multipathproject.kdev4") ) );
        createFile( file );
        QTextStream stream( &file );
        stream << "[Buildset]\n" <<
        "BuildItems=@Variant(\\x00\\x00\\x00\\t\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0b\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00 \\x00M\\x00u\\x00l\\x00t\\x00i\\x00P\\x00a\\x00t\\x00h\\x00P\\x00r\\x00o\\x00j\\x00e\\x00c\\x00t)\n" <<
        "[CustomDefinesAndIncludes][ProjectPath0]\n" <<
        "Path=.\n" <<
        "[CustomDefinesAndIncludes][ProjectPath0][Defines]\n" <<
        "SOURCE=CONTENT\n" <<
        "_COPY=\n" <<
        "[CustomDefinesAndIncludes][ProjectPath0][Includes]\n" <<
        "1=" << QDir::rootPath() << "usr/include/otherdir\n" <<
        "[CustomDefinesAndIncludes][ProjectPath1]\n" <<
        "Path=src\n" <<
        "[CustomDefinesAndIncludes][ProjectPath1][Defines]\n" <<
        "BUILD=debug\n" <<
        "[CustomDefinesAndIncludes][ProjectPath1][Includes]\n" <<
        "1=" << QDir::rootPath() << "usr/local/include/mydir\n" <<
        "[CustomDefinesAndIncludes][ProjectPath2]\n" <<
        "Path=anotherFolder\n" <<
        "[CustomDefinesAndIncludes][ProjectPath2][Defines]\n" <<
        "HIDDEN=\n" <<
        "[Project]\n" <<
        "VersionControlSupport=\n";
    }
    return loadProject( QDir::tempPath() + "/multipathproject/multipathproject.kdev4", QStringLiteral("MultiPathProject") );
}

IProject* ProjectsGenerator::GenerateSimpleProjectWithOutOfProjectFiles()
{
    auto project = GenerateSimpleProject();
    Q_ASSERT(project);

    auto rootFolder = QDir(project->path().path());
    const QString includePaths = QStringLiteral(".kdev_include_paths");

    QFile file(rootFolder.filePath(includePaths));
    createFile(file);
    QTextStream stream( &file );
    stream << "." + QDir::separator() + "include1.h\n" << rootFolder.canonicalPath() + QDir::separator() + "include2.h";

    return project;
}

IProject* ProjectsGenerator::GenerateEmptyProject()
{
    // directory structure:
    // ./emptyproject.kdev4
    // ./.kdev4/emptyproject.kdev4

    const QString ep = QStringLiteral("emptyproject");
    auto rootFolder = QDir::temp();
    QDir(rootFolder.absolutePath() + "/" + ep).removeRecursively();
    rootFolder.mkdir(ep);
    rootFolder.cd(ep);
    rootFolder.mkdir(QStringLiteral(".kdev4"));

    {
        QFile file(rootFolder.filePath(QStringLiteral("emptyproject.kdev4")));
        createFile(file);
        QTextStream stream(&file);
        stream << "[Project]\nName=EmptyProject\nManager=KDevCustomBuildSystem";
    }

    {
        QFile file(rootFolder.filePath(QStringLiteral(".kdev4/emptyproject.kdev4")));
        createFile(file);
        QTextStream stream(&file);
        stream << "[Project]\n" << "VersionControlSupport=\n";
    }
    return loadProject(QDir::tempPath() + "/emptyproject/emptyproject.kdev4", QStringLiteral("EmptyProject"));
}