Commit 69649be5 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

QbsProjectManager: No reparse after programmatic project file changes.



qbs knows the effect of adding and removing files. There is no need to
set up the project from scratch.

Change-Id: I8938c7cfb3e3ac2deb3fb0d2175f447391a669cb
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@digia.com>
parent 23a72546
......@@ -35,7 +35,6 @@
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/idocument.h>
#include <coreplugin/messagemanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <qtsupport/qtsupportconstants.h>
......@@ -116,46 +115,6 @@ static qbs::GroupData findMainQbsGroup(const qbs::ProductData &productData)
return qbs::GroupData();
}
static bool addQbsFiles(QbsBaseProjectNode *node, const QStringList &filePaths, qbs::Project prj,
const qbs::ProductData &productData, const qbs::GroupData &groupData,
const QString &productPath, QStringList *notAdded)
{
QStringList allPaths = groupData.allFilePaths();
foreach (const QString &path, filePaths) {
qbs::ErrorInfo err = prj.addFiles(productData, groupData, QStringList() << path);
if (err.hasError()) {
Core::MessageManager::write(err.toString());
*notAdded += path;
} else {
allPaths += path;
}
}
if (notAdded->count() != filePaths.count())
QbsGroupNode::setupFiles(node, allPaths, productPath, true);
return notAdded->isEmpty();
}
static bool removeQbsFiles(QbsBaseProjectNode *node, const QStringList &filePaths, qbs::Project prj,
const qbs::ProductData &productData, const qbs::GroupData &groupData,
const QString &productPath, QStringList *notRemoved)
{
QStringList allPaths = groupData.allFilePaths();
foreach (const QString &path, filePaths) {
qbs::ErrorInfo err = prj.removeFiles(productData, groupData, QStringList() << path);
if (err.hasError()) {
Core::MessageManager::write(err.toString());
*notRemoved += path;
} else {
allPaths.removeOne(path);
}
}
if (notRemoved->count() != filePaths.count())
QbsGroupNode::setupFiles(node, allPaths, productPath, true);
return notRemoved->isEmpty();
}
class FileTreeNode {
public:
explicit FileTreeNode(const QString &n = QString(), FileTreeNode *p = 0, bool f = false) :
......@@ -428,8 +387,8 @@ bool QbsGroupNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
return false;
}
return addQbsFiles(this, filePaths, prjNode->qbsProject(), prdNode->qbsProductData(),
*m_qbsGroupData, m_productPath, notAdded);
return prjNode->project()->addFilesToProduct(this, filePaths, prdNode->qbsProductData(),
*m_qbsGroupData, notAdded);
}
bool QbsGroupNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
......@@ -450,8 +409,8 @@ bool QbsGroupNode::removeFiles(const QStringList &filePaths, QStringList *notRem
return false;
}
return removeQbsFiles(this, filePaths, prjNode->qbsProject(), prdNode->qbsProductData(),
*m_qbsGroupData, m_productPath, notRemoved);
return prjNode->project()->removeFilesFromProduct(this, filePaths, prdNode->qbsProductData(),
*m_qbsGroupData, notRemoved);
}
void QbsGroupNode::updateQbsGroupData(const qbs::GroupData *grp, const QString &productPath,
......@@ -632,8 +591,8 @@ bool QbsProductNode::addFiles(const QStringList &filePaths, QStringList *notAdde
qbs::GroupData grp = findMainQbsGroup(m_qbsProductData);
if (grp.isValid()) {
const QString &productPath = QFileInfo(m_qbsProductData.location().fileName()).absolutePath();
return addQbsFiles(this, filePaths, prjNode->qbsProject(), m_qbsProductData, grp, productPath, notAdded);
return prjNode->project()->addFilesToProduct(this, filePaths, m_qbsProductData, grp,
notAdded);
}
QTC_ASSERT(false, return false);
......@@ -653,8 +612,8 @@ bool QbsProductNode::removeFiles(const QStringList &filePaths, QStringList *notR
qbs::GroupData grp = findMainQbsGroup(m_qbsProductData);
if (grp.isValid()) {
const QString &productPath = QFileInfo(m_qbsProductData.location().fileName()).absolutePath();
return removeQbsFiles(this, filePaths, prjNode->qbsProject(), m_qbsProductData, grp, productPath, notRemoved);
return prjNode->project()->removeFilesFromProduct(this, filePaths, m_qbsProductData, grp,
notRemoved);
}
QTC_ASSERT(false, return false);
......
......@@ -37,10 +37,9 @@
#include "qbsnodes.h"
#include <coreplugin/documentmanager.h>
#include <utils/qtcassert.h>
#include <coreplugin/icontext.h>
#include <coreplugin/id.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/mimedatabase.h>
#include <cpptools/cppmodelmanagerinterface.h>
......@@ -62,6 +61,7 @@
#include <qmljstools/qmljsmodelmanager.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <qbs.h>
......@@ -185,6 +185,84 @@ QStringList QbsProject::files(Project::FilesMode fileMode) const
return result.toList();
}
class ChangeExpector
{
public:
ChangeExpector(const QString &filePath, const QSet<Core::IDocument *> &documents)
: m_document(0)
{
foreach (Core::IDocument * const doc, documents) {
if (doc->filePath() == filePath) {
m_document = doc;
break;
}
}
QTC_ASSERT(m_document, return);
Core::DocumentManager::expectFileChange(filePath);
m_wasInDocumentManager = Core::DocumentManager::removeDocument(m_document);
QTC_CHECK(m_wasInDocumentManager);
}
~ChangeExpector()
{
QTC_ASSERT(m_document, return);
Core::DocumentManager::addDocument(m_document);
Core::DocumentManager::unexpectFileChange(m_document->filePath());
}
private:
Core::IDocument *m_document;
bool m_wasInDocumentManager;
};
bool QbsProject::addFilesToProduct(QbsBaseProjectNode *node, const QStringList &filePaths,
const qbs::ProductData &productData, const qbs::GroupData &groupData, QStringList *notAdded)
{
QTC_ASSERT(m_qbsProject.isValid(), return false);
QStringList allPaths = groupData.allFilePaths();
const QString productFilePath = productData.location().fileName();
ChangeExpector expector(productFilePath, m_qbsDocuments);
foreach (const QString &path, filePaths) {
qbs::ErrorInfo err = m_qbsProject.addFiles(productData, groupData, QStringList() << path);
if (err.hasError()) {
Core::MessageManager::write(err.toString());
*notAdded += path;
} else {
allPaths += path;
}
}
if (notAdded->count() != filePaths.count()) {
m_projectData = m_qbsProject.projectData();
QbsGroupNode::setupFiles(node, allPaths, QFileInfo(productFilePath).absolutePath(), true);
}
return notAdded->isEmpty();
}
bool QbsProject::removeFilesFromProduct(QbsBaseProjectNode *node, const QStringList &filePaths,
const qbs::ProductData &productData, const qbs::GroupData &groupData,
QStringList *notRemoved)
{
QTC_ASSERT(m_qbsProject.isValid(), return false);
QStringList allPaths = groupData.allFilePaths();
const QString productFilePath = productData.location().fileName();
ChangeExpector expector(productFilePath, m_qbsDocuments);
foreach (const QString &path, filePaths) {
qbs::ErrorInfo err
= m_qbsProject.removeFiles(productData, groupData, QStringList() << path);
if (err.hasError()) {
Core::MessageManager::write(err.toString());
*notRemoved += path;
} else {
allPaths.removeOne(path);
}
}
if (notRemoved->count() != filePaths.count()) {
m_projectData = m_qbsProject.projectData();
QbsGroupNode::setupFiles(node, allPaths, QFileInfo(productFilePath).absolutePath(), true);
}
return notRemoved->isEmpty();
}
void QbsProject::invalidate()
{
prepareForParsing();
......
......@@ -48,6 +48,8 @@ namespace qbs {
class BuildJob;
class CleanJob;
class Error;
class GroupData;
class ProductData;
class ProjectData;
class CleanOptions;
class InstallJob;
......@@ -62,7 +64,7 @@ namespace ProjectExplorer { class BuildConfiguration; }
namespace QbsProjectManager {
namespace Internal {
class QbsBaseProjectNode;
class QbsProjectNode;
class QbsRootProjectNode;
class QbsProjectParser;
......@@ -84,6 +86,13 @@ public:
QStringList files(FilesMode fileMode) const;
bool addFilesToProduct(QbsBaseProjectNode *node, const QStringList &filePaths,
const qbs::ProductData &productData, const qbs::GroupData &groupData,
QStringList *notAdded);
bool removeFilesFromProduct(QbsBaseProjectNode *node, const QStringList &filePaths,
const qbs::ProductData &productData, const qbs::GroupData &groupData,
QStringList *notRemoved);
qbs::BuildJob *build(const qbs::BuildOptions &opts, QStringList products = QStringList());
qbs::CleanJob *clean(const qbs::CleanOptions &opts);
qbs::InstallJob *install(const qbs::InstallOptions &opts);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment