forked from qt-creator/qt-creator
ProjectExplorer: Move BuildSystem owership to BuildConfiguration
... or Target. This patch moves build system from conceptually "one per project" to "one per target (i.e. per project-and-kit)" or "per BuildConfigurations" for targets where the builds differ significantly. Building requires usually items from the kit (Qt version, compiler, ...) so a target-agnostic build is practically almost always wrong. Moving the build system to the target also has the potential to solve issues caused by switching targets while parsing, that used Project::activeTarget() regularly, with potentially different results before and after the switch. This patch might create performance/size regressions when several targets are set up per project as the build system implementation's internal data are duplicated in this case. The idea is to fix that by sharing per-project pieces again in the project implementation once these problems occur. Change-Id: I87f640ce418b93175b5029124eaa55f3b8721dca Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -24,28 +24,19 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmlprojectnodes.h"
|
||||
#include "qmlproject.h"
|
||||
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <coreplugin/fileiconprovider.h>
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/editormanager/documentmodel.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/textfileformat.h>
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QTextCodec>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace QmlProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
QmlProjectNode::QmlProjectNode(QmlProject *project) : ProjectNode(project->projectDirectory()),
|
||||
m_project(project)
|
||||
QmlProjectNode::QmlProjectNode(Project *project)
|
||||
: ProjectNode(project->projectDirectory())
|
||||
{
|
||||
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
|
||||
|
||||
@@ -53,91 +44,5 @@ QmlProjectNode::QmlProjectNode(QmlProject *project) : ProjectNode(project->proje
|
||||
setIcon(qmlProjectIcon);
|
||||
}
|
||||
|
||||
bool QmlBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
|
||||
{
|
||||
if (dynamic_cast<QmlProjectNode *>(context)) {
|
||||
if (action == AddNewFile || action == EraseFile)
|
||||
return true;
|
||||
QTC_ASSERT(node, return false);
|
||||
|
||||
if (action == Rename && node->asFileNode()) {
|
||||
const FileNode *fileNode = node->asFileNode();
|
||||
QTC_ASSERT(fileNode, return false);
|
||||
return fileNode->fileType() != FileType::Project;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return BuildSystem::supportsAction(context, action, node);
|
||||
}
|
||||
|
||||
QmlProject *QmlBuildSystem::project() const
|
||||
{
|
||||
return static_cast<QmlProject *>(BuildSystem::project());
|
||||
}
|
||||
|
||||
bool QmlBuildSystem::addFiles(Node *context, const QStringList &filePaths, QStringList *notAdded)
|
||||
{
|
||||
if (dynamic_cast<QmlProjectNode *>(context))
|
||||
return project()->addFiles(filePaths);
|
||||
|
||||
return BuildSystem::addFiles(context, filePaths, notAdded);
|
||||
}
|
||||
|
||||
bool QmlBuildSystem::deleteFiles(Node *context, const QStringList &filePaths)
|
||||
{
|
||||
if (dynamic_cast<QmlProjectNode *>(context))
|
||||
return true;
|
||||
|
||||
return BuildSystem::deleteFiles(context, filePaths);
|
||||
}
|
||||
|
||||
bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const QString &newFilePath)
|
||||
{
|
||||
if (dynamic_cast<QmlProjectNode *>(context)) {
|
||||
if (filePath.endsWith(project()->mainFile())) {
|
||||
project()->setMainFile(newFilePath);
|
||||
|
||||
// make sure to change it also in the qmlproject file
|
||||
const QString qmlProjectFilePath = project()->projectFilePath().toString();
|
||||
Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath);
|
||||
const QList<Core::IEditor *> editors = Core::DocumentModel::editorsForFilePath(qmlProjectFilePath);
|
||||
TextEditor::TextDocument *document = nullptr;
|
||||
if (!editors.isEmpty()) {
|
||||
document = qobject_cast<TextEditor::TextDocument*>(editors.first()->document());
|
||||
if (document && document->isModified())
|
||||
if (!Core::DocumentManager::saveDocument(document))
|
||||
return false;
|
||||
}
|
||||
|
||||
QString fileContent;
|
||||
QString error;
|
||||
Utils::TextFileFormat textFileFormat;
|
||||
const QTextCodec *codec = QTextCodec::codecForName("UTF-8"); // qml files are defined to be utf-8
|
||||
if (Utils::TextFileFormat::readFile(qmlProjectFilePath, codec, &fileContent, &textFileFormat, &error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
qWarning() << "Failed to read file" << qmlProjectFilePath << ":" << error;
|
||||
}
|
||||
|
||||
// find the mainFile and do the file name with brackets in a capture group and mask the . with \.
|
||||
QString originalFileName = QFileInfo(filePath).fileName();
|
||||
originalFileName.replace(".", "\\.");
|
||||
const QRegularExpression expression(QString("mainFile:\\s*\"(%1)\"").arg(originalFileName));
|
||||
const QRegularExpressionMatch match = expression.match(fileContent);
|
||||
|
||||
fileContent.replace(match.capturedStart(1), match.capturedLength(1), QFileInfo(newFilePath).fileName());
|
||||
|
||||
if (!textFileFormat.writeFile(qmlProjectFilePath, fileContent, &error))
|
||||
qWarning() << "Failed to write file" << qmlProjectFilePath << ":" << error;
|
||||
project()->refresh(QmlProject::Everything);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return BuildSystem::renameFile(context, filePath, newFilePath);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlProjectManager
|
||||
|
||||
Reference in New Issue
Block a user