Merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/cmakecache into lp:qtcreator-plugin-ubuntu

Proposed by Benjamin Zeller
Status: Merged
Approved by: Zoltan Balogh
Approved revision: 265
Merged at revision: 247
Proposed branch: lp:~zeller-benjamin/qtcreator-plugin-ubuntu/cmakecache
Merge into: lp:qtcreator-plugin-ubuntu
Diff against target: 475 lines (+244/-43)
12 files modified
src/ubuntu/ubuntu.pro (+4/-2)
src/ubuntu/ubuntucmakecache.cpp (+129/-0)
src/ubuntu/ubuntucmakecache.h (+58/-0)
src/ubuntu/ubuntulocalrunconfiguration.cpp (+30/-13)
src/ubuntu/ubuntulocalrunconfigurationfactory.cpp (+7/-1)
src/ubuntu/ubuntumenu.h (+0/-1)
src/ubuntu/ubuntupackagestep.cpp (+0/-3)
src/ubuntu/ubuntupackagingwidget.cpp (+5/-2)
src/ubuntu/ubuntuplugin.cpp (+2/-0)
src/ubuntu/ubuntuprojectguesser.cpp (+4/-15)
src/ubuntu/ubuntuvalidationresultmodel.cpp (+5/-5)
src/ubuntu/ubuntuvalidationresultmodel.h (+0/-1)
To merge this branch: bzr merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/cmakecache
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Zoltan Balogh Approve
Review via email: mp+231516@code.launchpad.net

Commit message

- Add UbuntuCMakeCache
- Add support for UBUNTU_MANIFEST_PATH cache variable to support core
apps
- Fallback to search the manifest file in builddir if the desktop file
path in the project dir manifest file is not valid (core apps
compatibility)
- Fix bug lp:1358381 "new click-check-* scripts not shown in Validate
section of Ubuntu Publish"

Description of the change

- Add UbuntuCMakeCache
- Add support for UBUNTU_MANIFEST_PATH cache variable to support core
apps
- Fallback to search the manifest file in builddir if the desktop file
path in the project dir manifest file is not valid (core apps
compatibility)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
265. By Benjamin Zeller

Fix bug lp:1358381 "new click-check-* scripts not shown in Validate
section of Ubuntu Publish"

Revision history for this message
Zoltan Balogh (bzoltan) wrote :

OK

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ubuntu/ubuntu.pro'
2--- src/ubuntu/ubuntu.pro 2014-08-18 12:29:43 +0000
3+++ src/ubuntu/ubuntu.pro 2014-08-20 15:15:46 +0000
4@@ -132,7 +132,8 @@
5 ubuntuabstractguieditor.cpp \
6 ubuntuabstractguieditordocument.cpp \
7 ubuntuapparmoreditor.cpp \
8- ubuntueditorfactory.cpp
9+ ubuntueditorfactory.cpp \
10+ ubuntucmakecache.cpp
11
12 HEADERS += \
13 ubuntuplugin.h \
14@@ -212,5 +213,6 @@
15 ubuntuabstractguieditor.h \
16 ubuntuabstractguieditordocument.h \
17 ubuntuapparmoreditor.h \
18- ubuntueditorfactory.h
19+ ubuntueditorfactory.h \
20+ ubuntucmakecache.h
21
22
23=== added file 'src/ubuntu/ubuntucmakecache.cpp'
24--- src/ubuntu/ubuntucmakecache.cpp 1970-01-01 00:00:00 +0000
25+++ src/ubuntu/ubuntucmakecache.cpp 2014-08-20 15:15:46 +0000
26@@ -0,0 +1,129 @@
27+#include "ubuntucmakecache.h"
28+
29+#include <projectexplorer/session.h>
30+#include <projectexplorer/project.h>
31+#include <projectexplorer/target.h>
32+#include <projectexplorer/buildconfiguration.h>
33+#include <cmakeprojectmanager/cmakeprojectconstants.h>
34+
35+#include <QRegularExpression>
36+#include <QDir>
37+
38+namespace Ubuntu{
39+namespace Internal {
40+
41+enum {
42+ debug = 0
43+};
44+
45+/*!
46+ * \class UbuntuCMakeCache::UbuntuCMakeCache
47+ * Automatic updating value cache, this reads all relevant CMakeCache files
48+ * and stores some for quick querying
49+ */
50+
51+UbuntuCMakeCache * UbuntuCMakeCache::m_instance = nullptr;
52+
53+UbuntuCMakeCache::UbuntuCMakeCache(QObject *parent) :
54+ QObject(parent)
55+{
56+ Q_ASSERT_X(m_instance == nullptr,Q_FUNC_INFO,"There can be only one UbuntuCMakeCache instance");
57+ m_instance = this;
58+
59+ connect(ProjectExplorer::SessionManager::instance(),SIGNAL(aboutToRemoveProject(ProjectExplorer::Project *)),
60+ this,SLOT(onAboutToRemoveProject(ProjectExplorer::Project*)));
61+}
62+
63+QVariant UbuntuCMakeCache::getValue(const QString &key, ProjectExplorer::BuildConfiguration *bc, const QVariant defaultValue)
64+{
65+ UbuntuCMakeCache *inst = instance();
66+ if(!inst)
67+ return defaultValue;
68+
69+ Utils::FileName cacheFile = bc->buildDirectory().appendPath(QStringLiteral("CMakeCache.txt"));
70+ QString cacheKey = inst->normalize(cacheFile.toString());
71+
72+ bool needsRefresh = false;
73+ if(!inst->m_map.contains(cacheKey)) {
74+ //we need to read it
75+ needsRefresh = true;
76+ } else {
77+ //check if the file has changed since the last read
78+ inst->m_map[cacheKey].cacheFile.refresh();
79+ if(debug) qDebug()<<"File Last Read "<<inst->m_map[cacheKey].cacheFile.lastModified()
80+ <<"Cache Last Read "<<inst->m_map[cacheKey].lastRead;
81+ if(inst->m_map[cacheKey].cacheFile.lastModified() != inst->m_map[cacheKey].lastRead) {
82+ needsRefresh = true;
83+ }
84+ }
85+
86+ if(needsRefresh)
87+ inst->refreshCache(cacheKey, cacheFile);
88+
89+ if(inst->m_map[cacheKey].values.contains(key))
90+ return inst->m_map[cacheKey].values[key];
91+
92+ return defaultValue;
93+}
94+
95+UbuntuCMakeCache *UbuntuCMakeCache::instance()
96+{
97+ return m_instance;
98+}
99+
100+void UbuntuCMakeCache::onAboutToRemoveProject(ProjectExplorer::Project *p)
101+{
102+ if(!p)
103+ return;
104+
105+ //remove all values that belong to the project
106+ for (ProjectExplorer::Target *t : p->targets()) {
107+ for(ProjectExplorer::BuildConfiguration *bc : t->buildConfigurations()) {
108+ Utils::FileName cacheFile = bc->buildDirectory().appendPath(QStringLiteral("CMakeCache.txt"));
109+ m_map.remove(normalize(cacheFile.toString()));
110+ }
111+ }
112+}
113+
114+QString UbuntuCMakeCache::normalize(const QString &path) const
115+{
116+ return QDir::cleanPath(path);
117+}
118+
119+void UbuntuCMakeCache::refreshCache(const QString &key, const Utils::FileName &fName)
120+{
121+ if(debug) qDebug()<<"Rebuilding cache for: "<<key;
122+ UbuntuCMakeCacheEntry *entry = nullptr;
123+ if(m_map.contains(key)) {
124+ entry = &m_map[key];
125+ entry->lastRead = fName.toFileInfo().lastModified();
126+ } else {
127+ QFileInfo fInfo = fName.toFileInfo();
128+ entry = &m_map.insert(key,UbuntuCMakeCacheEntry{fInfo,fInfo.lastModified(),CMakeCacheValueMap()}).value();
129+ }
130+
131+ QFile cache(fName.toString());
132+ if(cache.exists() && cache.open(QIODevice::ReadOnly)) {
133+ static const QRegularExpression regExpPType(QLatin1String("^UBUNTU_PROJECT_TYPE:(.*)=\\s*(\\S*)\\s*$"));
134+ static const QRegularExpression regExpManifestPath (QLatin1String("^UBUNTU_MANIFEST_PATH:(.*)=\\s*(\\S*)\\s*$"));
135+ QTextStream in(&cache);
136+ while (!in.atEnd()) {
137+ QString contents = in.readLine();
138+ QRegularExpressionMatch m = regExpPType.match(contents);
139+ if(m.hasMatch()) {
140+ entry->values.insert(QStringLiteral("UBUNTU_PROJECT_TYPE"),m.captured(2));
141+ continue;
142+ }
143+ m = regExpManifestPath.match(contents);
144+ if(m.hasMatch()) {
145+ entry->values.insert(QStringLiteral("UBUNTU_MANIFEST_PATH"),m.captured(2));
146+ continue;
147+ }
148+ }
149+
150+
151+ }
152+}
153+
154+}}
155+
156
157=== added file 'src/ubuntu/ubuntucmakecache.h'
158--- src/ubuntu/ubuntucmakecache.h 1970-01-01 00:00:00 +0000
159+++ src/ubuntu/ubuntucmakecache.h 2014-08-20 15:15:46 +0000
160@@ -0,0 +1,58 @@
161+#ifndef UBUNTUCMAKECACHE_H
162+#define UBUNTUCMAKECACHE_H
163+
164+#include <QObject>
165+#include <QHash>
166+#include <QMap>
167+#include <QVariant>
168+#include <QDateTime>
169+#include <QFileInfo>
170+
171+#include <utils/fileutils.h>
172+
173+namespace ProjectExplorer {
174+ class Project;
175+ class Target;
176+ class BuildConfiguration;
177+}
178+
179+namespace Ubuntu{
180+namespace Internal {
181+
182+typedef QMap<QString,QVariant> CMakeCacheValueMap;
183+
184+struct UbuntuCMakeCacheEntry {
185+ QFileInfo cacheFile;
186+ QDateTime lastRead;
187+ CMakeCacheValueMap values;
188+};
189+
190+typedef QMap<QString,UbuntuCMakeCacheEntry> CMakeCache;
191+
192+class UbuntuCMakeCache : public QObject
193+{
194+ Q_OBJECT
195+public:
196+ explicit UbuntuCMakeCache(QObject *parent = 0);
197+
198+ static QVariant getValue (const QString &key, ProjectExplorer::BuildConfiguration *bc, const QVariant defaultValue = QVariant());
199+ static UbuntuCMakeCache *instance();
200+
201+private slots:
202+ void onAboutToRemoveProject (ProjectExplorer::Project *p);
203+
204+private:
205+ QString normalize (const QString &path) const;
206+ void refreshCache (const QString &key, const Utils::FileName &fName);
207+
208+private:
209+ CMakeCache m_map;
210+ static UbuntuCMakeCache *m_instance;
211+
212+};
213+
214+}}
215+
216+
217+
218+#endif // UBUNTUCMAKECACHE_H
219
220=== modified file 'src/ubuntu/ubuntulocalrunconfiguration.cpp'
221--- src/ubuntu/ubuntulocalrunconfiguration.cpp 2014-08-14 18:41:49 +0000
222+++ src/ubuntu/ubuntulocalrunconfiguration.cpp 2014-08-20 15:15:46 +0000
223@@ -21,6 +21,7 @@
224 #include "ubuntuprojectguesser.h"
225 #include "ubuntuclickmanifest.h"
226 #include "ubunturemoterunconfiguration.h"
227+#include "ubuntucmakecache.h"
228
229 #include <qtsupport/baseqtversion.h>
230 #include <qtsupport/qtkitinformation.h>
231@@ -144,18 +145,34 @@
232 };
233
234 //first lets check if the informations in the manifest file are helpful
235- QFileInfo manifestFile(projectDir.appendPath(QStringLiteral("manifest.json")).toString());
236- if ( manifestFile.exists() ) {
237- UbuntuClickManifest manifest;
238- if(manifest.load(manifestFile.absoluteFilePath())){
239- QString desktop = getDesktopFromManifest(manifest);
240-
241- if(!desktop.isEmpty()) {
242- QFileInfo d(desktop);
243-
244- desktop = searchDesktopFile(d.fileName());
245- if(!desktop.isEmpty())
246- return desktop;
247+ QVariant manifestPath = UbuntuCMakeCache::getValue(QStringLiteral("UBUNTU_MANIFEST_PATH"),
248+ config->target()->activeBuildConfiguration(),
249+ QStringLiteral("manifest.json"));
250+
251+
252+ //search for the manifest file in the project dir AND in the builddir
253+ QList<Utils::FileName> searchPaths{
254+ projectDir.appendPath(manifestPath.toString()),
255+ config->target()->activeBuildConfiguration()->buildDirectory()
256+ .appendPath(QFileInfo(manifestPath.toString()).path())
257+ .appendPath(QStringLiteral("manifest.json"))
258+ };
259+
260+ for(Utils::FileName path : searchPaths) {
261+ QFileInfo manifestFile(path.toString());
262+ if(debug) qDebug()<<"Searching for the manifest file: "<<manifestFile.absoluteFilePath();
263+ if ( manifestFile.exists() ) {
264+ UbuntuClickManifest manifest;
265+ if(manifest.load(manifestFile.absoluteFilePath())){
266+ QString desktop = getDesktopFromManifest(manifest);
267+
268+ if(!desktop.isEmpty()) {
269+ QFileInfo d(desktop);
270+
271+ desktop = searchDesktopFile(d.fileName());
272+ if(!desktop.isEmpty())
273+ return desktop;
274+ }
275 }
276 }
277 }
278@@ -193,7 +210,7 @@
279
280 return QString();
281 }
282- manifestPath = package_dir.absoluteFilePath(QLatin1String("manifest.json"));
283+ manifestPath = package_dir.absoluteFilePath(QStringLiteral("manifest.json"));
284
285 //read the manifest
286 UbuntuClickManifest manifest;
287
288=== modified file 'src/ubuntu/ubuntulocalrunconfigurationfactory.cpp'
289--- src/ubuntu/ubuntulocalrunconfigurationfactory.cpp 2014-08-18 15:52:52 +0000
290+++ src/ubuntu/ubuntulocalrunconfigurationfactory.cpp 2014-08-20 15:15:46 +0000
291@@ -22,6 +22,8 @@
292 #include "ubuntudevice.h"
293 #include "clicktoolchain.h"
294 #include "ubuntuclickmanifest.h"
295+#include "ubuntucmakecache.h"
296+
297 #include <cmakeprojectmanager/cmakeproject.h>
298 #include <cmakeprojectmanager/cmakeprojectconstants.h>
299
300@@ -63,7 +65,11 @@
301 return types;
302 }
303
304- QString manifestPath = QStringLiteral("%1/manifest.json").arg(parent->project()->projectDirectory());
305+ QString manifestPath = QDir::cleanPath(parent->project()->projectDirectory()
306+ +QDir::separator()
307+ +UbuntuCMakeCache::getValue(QStringLiteral("UBUNTU_MANIFEST_PATH"),
308+ parent->activeBuildConfiguration(),
309+ QStringLiteral("manifest.json")).toString());
310 UbuntuClickManifest manifest;
311
312 //if we have no manifest, we can not query the app id's
313
314=== modified file 'src/ubuntu/ubuntumenu.h'
315--- src/ubuntu/ubuntumenu.h 2014-08-19 09:50:02 +0000
316+++ src/ubuntu/ubuntumenu.h 2014-08-20 15:15:46 +0000
317@@ -89,7 +89,6 @@
318 bool isProperUbuntuHtmlProject(ProjectExplorer::Project *project) const;
319 static UbuntuMenu *m_instance;
320 QPointer<ProjectExplorer::Project> m_ctxMenuProject;
321-
322 };
323
324
325
326=== modified file 'src/ubuntu/ubuntupackagestep.cpp'
327--- src/ubuntu/ubuntupackagestep.cpp 2014-08-14 18:41:49 +0000
328+++ src/ubuntu/ubuntupackagestep.cpp 2014-08-20 15:15:46 +0000
329@@ -473,9 +473,6 @@
330 QFile::remove(debTargetPath);
331
332 if( injectDebugScript && ubuntuDevice ) {
333-
334- QString projectName = target()->project()->displayName();
335-
336 QRegularExpression deskExecRegex(QStringLiteral("^(\\s*[Ee][Xx][Ee][cC]=.*)$"),QRegularExpression::MultilineOption);
337
338 UbuntuClickManifest manifest;
339
340=== modified file 'src/ubuntu/ubuntupackagingwidget.cpp'
341--- src/ubuntu/ubuntupackagingwidget.cpp 2014-08-19 10:11:23 +0000
342+++ src/ubuntu/ubuntupackagingwidget.cpp 2014-08-20 15:15:46 +0000
343@@ -27,6 +27,7 @@
344 #include "ubuntudevice.h"
345 #include "ubuntupackagestep.h"
346 #include "ubuntushared.h"
347+#include "ubuntucmakecache.h"
348
349 #include <projectexplorer/projectexplorer.h>
350 #include <projectexplorer/project.h>
351@@ -116,9 +117,11 @@
352
353 ProjectExplorer::Project* startupProject = ProjectExplorer::SessionManager::startupProject();
354
355- //@TODO this could fail if the manifest file is not named correctly
356+ QVariant manifestPath = UbuntuCMakeCache::getValue(QStringLiteral("UBUNTU_MANIFEST_PATH"),
357+ startupProject->activeTarget()->activeBuildConfiguration(),
358+ QStringLiteral("manifest.json"));
359 UbuntuClickManifest manifest;
360- if(!manifest.load(startupProject->projectDirectory()+QDir::separator()+QStringLiteral("manifest.json")))
361+ if(!manifest.load(startupProject->projectDirectory()+QDir::separator()+manifestPath.toString()))
362 return;
363
364 QString sClickPackageName;
365
366=== modified file 'src/ubuntu/ubuntuplugin.cpp'
367--- src/ubuntu/ubuntuplugin.cpp 2014-08-19 09:50:02 +0000
368+++ src/ubuntu/ubuntuplugin.cpp 2014-08-20 15:15:46 +0000
369@@ -40,6 +40,7 @@
370 #include "ubuntuqmlbuildconfiguration.h"
371 #include "ubuntufirstrunwizard.h"
372 #include "ubuntueditorfactory.h"
373+#include "ubuntucmakecache.h"
374
375 #include <coreplugin/modemanager.h>
376 #include <projectexplorer/kitmanager.h>
377@@ -140,6 +141,7 @@
378 addAutoReleasedObject(new ClickToolChainFactory);
379 addAutoReleasedObject(new UbuntuCMakeToolFactory);
380 addAutoReleasedObject(new UbuntuCMakeMakeStepFactory);
381+ addAutoReleasedObject(new UbuntuCMakeCache);
382 addAutoReleasedObject(new UbuntuCMakeBuildConfigurationFactory);
383 addAutoReleasedObject(new UbuntuHtmlBuildConfigurationFactory);
384 addAutoReleasedObject(new UbuntuQmlBuildConfigurationFactory);
385
386=== modified file 'src/ubuntu/ubuntuprojectguesser.cpp'
387--- src/ubuntu/ubuntuprojectguesser.cpp 2014-07-07 06:33:37 +0000
388+++ src/ubuntu/ubuntuprojectguesser.cpp 2014-08-20 15:15:46 +0000
389@@ -16,6 +16,7 @@
390 * Author: Benjamin Zeller <benjamin.zeller@canonical.com>
391 */
392 #include "ubuntuprojectguesser.h"
393+#include "ubuntucmakecache.h"
394
395 #include <projectexplorer/project.h>
396 #include <projectexplorer/target.h>
397@@ -213,21 +214,9 @@
398 if(project->activeTarget()
399 && project->activeTarget()->activeBuildConfiguration())
400 {
401- QFile cache(project->activeTarget()->activeBuildConfiguration()->buildDirectory().toString()
402- + QDir::separator()
403- + QLatin1String("CMakeCache.txt"));
404-
405- if(cache.exists() && cache.open(QIODevice::ReadOnly)) {
406- QRegularExpression regExp(QLatin1String("^UBUNTU_PROJECT_TYPE:(.*)=\\s*(\\S*)\\s*$"));
407- QTextStream in(&cache);
408- while (!in.atEnd()) {
409- QString contents = in.readLine();
410- QRegularExpressionMatch m = regExp.match(contents);
411- if(m.hasMatch()) {
412- return m.captured(2);
413- }
414- }
415- }
416+ QVariant val = UbuntuCMakeCache::getValue(QStringLiteral("UBUNTU_PROJECT_TYPE"),project->activeTarget()->activeBuildConfiguration());
417+ if(val.isValid())
418+ return val.toString();
419 }
420
421 QFile projectFile(project->projectFilePath());
422
423=== modified file 'src/ubuntu/ubuntuvalidationresultmodel.cpp'
424--- src/ubuntu/ubuntuvalidationresultmodel.cpp 2014-06-02 09:48:49 +0000
425+++ src/ubuntu/ubuntuvalidationresultmodel.cpp 2014-08-20 15:15:46 +0000
426@@ -25,6 +25,7 @@
427 #include <QStringList>
428 #include <QVariant>
429 #include <QIcon>
430+#include <QDir>
431
432
433 namespace Ubuntu {
434@@ -235,6 +236,7 @@
435
436 }
437
438+
439 /*!
440 * \brief ClickRunChecksParser::beginRecieveData
441 * Clear alls internal data and starts a completely new parse
442@@ -285,7 +287,7 @@
443 */
444 bool ClickRunChecksParser::tryParseNextSection(bool dataComplete)
445 {
446- QRegularExpression re(QLatin1String("^([=]+[\\s]+[A-Za-z0-9\\-_]+[\\s]+[=]+)$")); // match section beginnings
447+ QRegularExpression re(QStringLiteral("^([=]+[\\s]+[A-Za-z0-9\\-_]+[\\s]+[=]+)$")); // match section beginnings
448 re.setPatternOptions(QRegularExpression::MultilineOption);
449
450 QRegularExpressionMatchIterator matchIter = re.globalMatch(m_data,m_nextSectionOffset);
451@@ -314,10 +316,8 @@
452 type.remove(QLatin1String("="));
453 type = type.trimmed();
454
455- if(type == QLatin1String("click-check-lint")
456- || type == QLatin1String("click-check-desktop")
457- || type == QLatin1String("click-check-security")
458- || type == QLatin1String("click-check-functional")) {
459+ static const QRegularExpression regExp(QStringLiteral("^(click-check-.*)"));
460+ if(regExp.match(type).hasMatch()) {
461 parseJsonSection(type,startOffset,(endOffset-startOffset)+1);
462 } else {
463 //ignore unknown sections
464
465=== modified file 'src/ubuntu/ubuntuvalidationresultmodel.h'
466--- src/ubuntu/ubuntuvalidationresultmodel.h 2014-04-10 10:56:24 +0000
467+++ src/ubuntu/ubuntuvalidationresultmodel.h 2014-08-20 15:15:46 +0000
468@@ -68,7 +68,6 @@
469 void parsedNewTopLevelItem (DataItem* item);
470 private:
471 QString m_data;
472-
473 int m_nextSectionOffset;
474 int m_errorCount;
475 int m_warnCount;

Subscribers

People subscribed via source and target branches