OSDN Git Service

Fix available QtVersion::availableToolchains
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qtversionmanager.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef QTVERSIONMANAGER_H
34 #define QTVERSIONMANAGER_H
35
36 #include "qt4projectmanager_global.h"
37
38 #include <projectexplorer/abi.h>
39
40 #include <QtCore/QHash>
41 #include <QtCore/QSet>
42 #include <QtCore/QSharedPointer>
43 #include <QtCore/QFutureInterface>
44 #include <QtCore/QStringList>
45
46 namespace Utils {
47 class Environment;
48 }
49
50 namespace ProjectExplorer {
51 class HeaderPath;
52 class IOutputParser;
53 class Task;
54 }
55
56 namespace Qt4ProjectManager {
57
58 namespace Internal {
59 class QtOptionsPageWidget;
60 class QtOptionsPage;
61 }
62
63 class QT4PROJECTMANAGER_EXPORT QtVersionNumber
64 {
65 public:
66     QtVersionNumber(int ma, int mi, int p);
67     QtVersionNumber(const QString &versionString);
68     QtVersionNumber();
69
70     int majorVersion;
71     int minorVersion;
72     int patchVersion;
73     bool operator <(const QtVersionNumber &b) const;
74     bool operator <=(const QtVersionNumber &b) const;
75     bool operator >(const QtVersionNumber &b) const;
76     bool operator >=(const QtVersionNumber &b) const;
77     bool operator !=(const QtVersionNumber &b) const;
78     bool operator ==(const QtVersionNumber &b) const;
79 private:
80     bool checkVersionString(const QString &version) const;
81 };
82
83
84 class QT4PROJECTMANAGER_EXPORT QtVersion
85 {
86     friend class QtVersionManager;
87 public:
88     QtVersion(const QString &name, const QString &qmakeCommand,
89               bool isAutodetected = false, const QString &autodetectionSource = QString());
90
91     explicit QtVersion(const QString &path, bool isAutodetected = false, const QString &autodetectionSource = QString());
92
93     QtVersion(const QString &name, const QString &qmakeCommand, int id,
94               bool isAutodetected = false, const QString &autodetectionSource = QString());
95     QtVersion();
96     ~QtVersion();
97
98     bool isValid() const;
99     bool toolChainAvailable(const QString &id) const;
100
101     QString invalidReason() const;
102     QString description() const;
103     bool isAutodetected() const { return m_isAutodetected; }
104     QString autodetectionSource() const { return m_autodetectionSource; }
105
106     QString displayName() const;
107     QString sourcePath() const;
108     QString qmakeCommand() const;
109     QString uicCommand() const;
110     QString designerCommand() const;
111     QString linguistCommand() const;
112     QString qmlviewerCommand() const;
113     QString systemRoot() const;
114     void setSystemRoot(const QString &);
115
116     bool supportsTargetId(const QString &id) const;
117     QSet<QString> supportedTargetIds() const;
118
119     QList<ProjectExplorer::Abi> qtAbis() const;
120
121     /// @returns the name of the mkspec, which is generally not enough
122     /// to pass to qmake.
123     QString mkspec() const;
124     /// @returns the full path to the default directory
125     /// specifally not the directory the symlink/ORIGINAL_QMAKESPEC points to
126     QString mkspecPath() const;
127
128     bool isBuildWithSymbianSbsV2() const;
129
130     void setDisplayName(const QString &name);
131     void setQMakeCommand(const QString &path);
132
133     QString qtVersionString() const;
134     QtVersionNumber qtVersion() const;
135     // Returns the PREFIX, BINPREFIX, DOCPREFIX and similar information
136     QHash<QString,QString> versionInfo() const;
137
138     QString sbsV2Directory() const;
139     void setSbsV2Directory(const QString &directory);
140
141     void addToEnvironment(Utils::Environment &env) const;
142     QList<ProjectExplorer::HeaderPath> systemHeaderPathes() const;
143
144     bool supportsBinaryDebuggingHelper() const;
145     QString gdbDebuggingHelperLibrary() const;
146     QString qmlDebuggingHelperLibrary(bool debugVersion) const;
147     QString qmlDumpTool(bool debugVersion) const;
148     QString qmlObserverTool() const;
149     QStringList debuggingHelperLibraryLocations() const;
150
151     bool hasGdbDebuggingHelper() const;
152     bool hasQmlDump() const;
153     bool hasQmlDebuggingLibrary() const;
154     bool hasQmlObserver() const;
155     Utils::Environment qmlToolsEnvironment() const;
156
157     void invalidateCache();
158
159     bool hasExamples() const;
160     QString examplesPath() const;
161
162     bool hasDocumentation() const;
163     QString documentationPath() const;
164
165     bool hasDemos() const;
166     QString demosPath() const;
167
168     QString headerInstallPath() const;
169     QString frameworkInstallPath() const;
170     QString libraryInstallPath() const;
171
172     // All valid Ids are >= 0
173     int uniqueId() const;
174
175     enum QmakeBuildConfig
176     {
177         NoBuild = 1,
178         DebugBuild = 2,
179         BuildAll = 8
180     };
181
182     Q_DECLARE_FLAGS(QmakeBuildConfigs, QmakeBuildConfig)
183
184     QmakeBuildConfigs defaultBuildConfig() const;
185     QString toHtml(bool verbose) const;
186
187     bool supportsShadowBuilds() const;
188
189     /// Check a .pro-file/Qt version combination on possible issues with
190     /// its symbian setup.
191     /// @return a list of tasks, ordered on severity (errors first, then
192     ///         warnings and finally info items.
193     QList<ProjectExplorer::Task> reportIssues(const QString &proFile, const QString &buildDir, bool includeTargetSpecificErrors);
194
195     ProjectExplorer::IOutputParser *createOutputParser() const;
196
197 private:
198     static int getUniqueId();
199     // Also used by QtOptionsPageWidget
200     void updateSourcePath();
201     void updateVersionInfo() const;
202     QString findQtBinary(const QStringList &possibleName) const;
203     void updateAbiAndMkspec() const;
204     QString resolveLink(const QString &path) const;
205     QString qtCorePath() const;
206
207     QString m_displayName;
208     QString m_sourcePath;
209     int m_id;
210     bool m_isAutodetected;
211     QString m_autodetectionSource;
212     mutable bool m_hasDebuggingHelper; // controlled by m_versionInfoUpToDate
213     mutable bool m_hasQmlDump;         // controlled by m_versionInfoUpToDate
214     mutable bool m_hasQmlDebuggingLibrary; // controlled by m_versionInfoUpdate
215     mutable bool m_hasQmlObserver;     // controlled by m_versionInfoUpToDate
216
217     QString m_sbsV2Directory;
218     mutable QString m_systemRoot;
219
220     mutable bool m_abiUpToDate;
221     mutable QString m_mkspec; // updated lazily
222     mutable QString m_mkspecFullPath;
223     mutable QList<ProjectExplorer::Abi> m_abis;
224
225     mutable bool m_versionInfoUpToDate;
226     mutable QHash<QString,QString> m_versionInfo; // updated lazily
227     mutable bool m_notInstalled;
228     mutable bool m_defaultConfigIsDebug;
229     mutable bool m_defaultConfigIsDebugAndRelease;
230     mutable bool m_hasExamples;
231     mutable bool m_hasDemos;
232     mutable bool m_hasDocumentation;
233
234     mutable QString m_qmakeCommand;
235     mutable QString m_qtVersionString;
236     mutable QString m_uicCommand;
237     mutable QString m_designerCommand;
238     mutable QString m_linguistCommand;
239     mutable QString m_qmlviewerCommand;
240     mutable QSet<QString> m_targetIds;
241
242     mutable bool m_isBuildUsingSbsV2;
243     mutable bool m_qmakeIsExecutable;
244     mutable bool m_validSystemRoot;
245 };
246
247 struct QMakeAssignment
248 {
249     QString variable;
250     QString op;
251     QString value;
252 };
253
254 class QT4PROJECTMANAGER_EXPORT QtVersionManager : public QObject
255 {
256     Q_OBJECT
257     // for getUniqueId();
258     friend class QtVersion;
259     friend class Internal::QtOptionsPage;
260 public:
261     static QtVersionManager *instance();
262     QtVersionManager();
263     ~QtVersionManager();
264
265     // This will *always* return at least one (Qt in Path), even if that is
266     // unconfigured.
267     QList<QtVersion *> versions() const;
268     QList<QtVersion *> validVersions() const;
269
270     // Note: DO NOT STORE THIS POINTER!
271     //       The QtVersionManager will delete it at random times and you will
272     //       need to get a new pointer by calling this method again!
273     QtVersion *version(int id) const;
274     QtVersion *emptyVersion() const;
275
276     QtVersion *qtVersionForQMakeBinary(const QString &qmakePath);
277
278     // Used by the projectloadwizard
279     void addVersion(QtVersion *version);
280     void removeVersion(QtVersion *version);
281
282     // Target Support:
283     bool supportsTargetId(const QString &id) const;
284     // This returns a list of versions that support the target with the given id.
285     // @return A list of QtVersions that supports a target. This list may be empty!
286
287     QList<QtVersion *> versionsForTargetId(const QString &id, const QtVersionNumber &minimumQtVersion = QtVersionNumber()) const;
288     QSet<QString> supportedTargetIds() const;
289
290     // Static Methods
291     static bool makefileIsFor(const QString &makefile, const QString &proFile);
292     static QPair<QtVersion::QmakeBuildConfigs, QString> scanMakeFile(const QString &makefile,
293                                                                      QtVersion::QmakeBuildConfigs defaultBuildConfig);
294     static QString findQMakeBinaryFromMakefile(const QString &directory);
295     bool isValidId(int id) const;
296
297     // Compatibility with pre-2.2:
298     QString popPendingMwcUpdate();
299     QString popPendingGcceUpdate();
300
301 signals:
302     void qtVersionsChanged(const QList<int> &uniqueIds);
303     void updateExamples(QString, QString, QString);
304
305 private slots:
306     void updateSettings();
307 private:
308     // This function is really simplistic...
309     static bool equals(QtVersion *a, QtVersion *b);
310     static QString findQMakeLine(const QString &directory, const QString &key);
311     static QString trimLine(const QString line);
312     static void parseArgs(const QString &args,
313                           QList<QMakeAssignment> *assignments,
314                           QList<QMakeAssignment> *afterAssignments,
315                           QString *additionalArguments);
316     static QtVersion::QmakeBuildConfigs qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments,
317                                                                     QtVersion::QmakeBuildConfigs defaultBuildConfig);
318     // Used by QtOptionsPage
319     void setNewQtVersions(QList<QtVersion *> newVersions);
320     // Used by QtVersion
321     int getUniqueId();
322     void writeVersionsIntoSettings();
323     void addNewVersionsFromInstaller();
324     void updateSystemVersion();
325     void updateDocumentation();
326
327     static int indexOfVersionInList(const QtVersion * const version, const QList<QtVersion *> &list);
328     void updateUniqueIdToIndexMap();
329
330     QtVersion *m_emptyVersion;
331     QMap<int, QtVersion *> m_versions;
332     int m_idcount;
333     // managed by QtProjectManagerPlugin
334     static QtVersionManager *m_self;
335
336     // Compatibility with pre-2.2:
337     QStringList m_pendingMwcUpdates;
338     QStringList m_pendingGcceUpdates;
339 };
340
341 } // namespace Qt4ProjectManager
342
343 Q_DECLARE_OPERATORS_FOR_FLAGS(Qt4ProjectManager::QtVersion::QmakeBuildConfigs)
344
345 #endif // QTVERSIONMANAGER_H