2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
#include "qmlproject.h"
|
2019-10-25 09:55:32 +02:00
|
|
|
|
2013-07-11 17:37:02 +02:00
|
|
|
#include "fileformat/qmlprojectfileformat.h"
|
2010-02-16 13:39:13 +01:00
|
|
|
#include "fileformat/qmlprojectitem.h"
|
2011-04-12 12:17:19 +02:00
|
|
|
#include "qmlprojectconstants.h"
|
2017-12-08 14:50:57 +01:00
|
|
|
#include "qmlprojectmanagerconstants.h"
|
2011-08-18 16:46:26 +02:00
|
|
|
#include "qmlprojectnodes.h"
|
2021-09-21 12:31:19 +02:00
|
|
|
#include "qmlprojectplugin.h"
|
|
|
|
#include "qmlprojectrunconfiguration.h"
|
2010-02-17 13:37:00 +01:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
|
|
|
#include <coreplugin/editormanager/documentmodel.h>
|
2021-09-03 14:58:42 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2017-02-28 16:31:07 +01:00
|
|
|
#include <coreplugin/icontext.h>
|
2010-02-17 13:37:00 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <coreplugin/messagemanager.h>
|
2017-03-03 18:16:34 +01:00
|
|
|
|
2017-11-28 15:57:15 +01:00
|
|
|
#include <projectexplorer/deploymentdata.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
#include <projectexplorer/kitmanager.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2017-03-03 18:16:34 +01:00
|
|
|
|
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2013-03-07 14:02:04 +01:00
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
2019-08-15 08:56:07 +02:00
|
|
|
|
2017-03-03 18:16:34 +01:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2011-04-15 15:55:11 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
|
|
|
|
2017-03-01 14:26:46 +01:00
|
|
|
#include <utils/algorithm.h>
|
2021-03-23 14:04:04 +01:00
|
|
|
#include <utils/infobar.h>
|
2021-08-25 13:50:10 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2017-03-01 14:26:46 +01:00
|
|
|
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2021-03-09 17:53:36 +01:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
#include <QMessageBox>
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QTextCodec>
|
2021-03-09 17:53:36 +01:00
|
|
|
#include <QTimer>
|
2010-01-19 13:41:02 +01:00
|
|
|
|
2013-09-05 01:52:17 +02:00
|
|
|
using namespace Core;
|
2013-09-10 17:59:34 +02:00
|
|
|
using namespace ProjectExplorer;
|
2019-10-25 09:55:32 +02:00
|
|
|
using namespace QmlProjectManager::Internal;
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
2010-01-18 16:32:14 +01:00
|
|
|
|
2020-03-03 12:30:28 +01:00
|
|
|
namespace {
|
|
|
|
Q_LOGGING_CATEGORY(infoLogger, "QmlProjectManager.QmlBuildSystem", QtInfoMsg)
|
|
|
|
}
|
|
|
|
|
2013-09-05 01:52:17 +02:00
|
|
|
namespace QmlProjectManager {
|
2013-03-07 14:02:04 +01:00
|
|
|
|
2021-08-03 16:07:42 +02:00
|
|
|
static bool isQtDesignStudio()
|
|
|
|
{
|
|
|
|
QSettings *settings = Core::ICore::settings();
|
|
|
|
const QString qdsStandaloneEntry = "QML/Designer/StandAloneMode"; //entry from qml settings
|
|
|
|
|
|
|
|
return settings->value(qdsStandaloneEntry, false).toBool();
|
|
|
|
}
|
|
|
|
static int preferedQtTarget(Target *target)
|
|
|
|
{
|
|
|
|
if (target) {
|
|
|
|
const QmlBuildSystem *buildSystem = qobject_cast<QmlBuildSystem *>(target->buildSystem());
|
|
|
|
if (buildSystem && buildSystem->qt6Project())
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2021-03-23 14:04:04 +01:00
|
|
|
const char openInQDSAppSetting[] = "OpenInQDSApp";
|
|
|
|
|
2019-08-15 12:26:14 +02:00
|
|
|
QmlProject::QmlProject(const Utils::FilePath &fileName)
|
|
|
|
: Project(QString::fromLatin1(Constants::QMLPROJECT_MIMETYPE), fileName)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2017-12-08 14:50:57 +01:00
|
|
|
setId(QmlProjectManager::Constants::QML_PROJECT_ID);
|
2017-01-30 14:59:10 +01:00
|
|
|
setProjectLanguages(Context(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID));
|
2021-06-04 07:59:00 +02:00
|
|
|
setDisplayName(fileName.completeBaseName());
|
2019-08-13 12:11:07 +02:00
|
|
|
|
|
|
|
setNeedsBuildConfigurations(false);
|
2019-10-25 09:55:32 +02:00
|
|
|
setBuildSystemCreator([](Target *t) { return new QmlBuildSystem(t); });
|
2021-03-09 17:53:36 +01:00
|
|
|
|
2021-08-03 16:07:42 +02:00
|
|
|
if (!isQtDesignStudio()) {
|
2021-09-21 12:31:19 +02:00
|
|
|
if (QmlProjectPlugin::qdsInstallationExists()) {
|
|
|
|
auto lambda = [fileName]() {
|
2021-03-23 14:04:04 +01:00
|
|
|
if (Core::ICore::infoBar()->canInfoBeAdded(openInQDSAppSetting)) {
|
|
|
|
Utils::InfoBarEntry
|
|
|
|
info(openInQDSAppSetting,
|
|
|
|
tr("Would you like to open the project in Qt Design Studio?"),
|
|
|
|
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
2021-09-21 12:31:19 +02:00
|
|
|
info.setCustomButtonInfo(tr("Open in Qt Design Studio"), [&, fileName] {
|
2021-03-23 14:04:04 +01:00
|
|
|
Core::ICore::infoBar()->removeInfo(openInQDSAppSetting);
|
2021-09-21 12:31:19 +02:00
|
|
|
QmlProjectPlugin::openQDS(fileName);
|
2021-03-23 14:04:04 +01:00
|
|
|
});
|
|
|
|
Core::ICore::infoBar()->addInfo(info);
|
2021-03-09 17:53:36 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
QTimer::singleShot(0, this, lambda);
|
|
|
|
}
|
2021-09-03 14:58:42 +02:00
|
|
|
} else {
|
2021-09-07 14:45:32 +02:00
|
|
|
m_openFileConnection = connect(
|
|
|
|
this, &QmlProject::anyParsingFinished, this, [this](Target *target, bool success) {
|
|
|
|
if (m_openFileConnection)
|
|
|
|
disconnect(m_openFileConnection);
|
|
|
|
|
|
|
|
if (target && success) {
|
|
|
|
const Utils::FilePath &folder = projectDirectory();
|
|
|
|
const Utils::FilePaths &uiFiles = files([&](const ProjectExplorer::Node *node) {
|
|
|
|
return node->filePath().completeSuffix() == "ui.qml"
|
|
|
|
&& node->filePath().parentDir() == folder;
|
|
|
|
});
|
|
|
|
if (!uiFiles.isEmpty()) {
|
|
|
|
Utils::FilePath currentFile;
|
|
|
|
if (auto cd = Core::EditorManager::currentDocument())
|
|
|
|
currentFile = cd->filePath();
|
|
|
|
|
|
|
|
if (currentFile.isEmpty() || !isKnownFile(currentFile))
|
|
|
|
Core::EditorManager::openEditor(uiFiles.first(), Utils::Id());
|
|
|
|
}
|
2021-09-07 13:05:53 +02:00
|
|
|
}
|
2021-09-07 14:45:32 +02:00
|
|
|
});
|
2021-03-09 17:53:36 +01:00
|
|
|
}
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlBuildSystem::QmlBuildSystem(Target *target)
|
|
|
|
: BuildSystem(target)
|
|
|
|
{
|
2021-08-20 13:04:02 +02:00
|
|
|
m_canonicalProjectDir =
|
2021-08-24 07:19:54 +02:00
|
|
|
target->project()->projectFilePath().canonicalPath().normalizedPathName().parentDir();
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
connect(target->project(), &Project::projectFileIsDirty,
|
|
|
|
this, &QmlBuildSystem::refreshProjectFile);
|
2019-08-15 12:26:14 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
// refresh first - project information is used e.g. to decide the default RC's
|
|
|
|
refresh(Everything);
|
|
|
|
|
|
|
|
// FIXME: Check. Probably bogus after the BuildSystem move.
|
|
|
|
// // addedTarget calls updateEnabled on the runconfigurations
|
|
|
|
// // which needs to happen after refresh
|
|
|
|
// foreach (Target *t, targets())
|
|
|
|
// addedTarget(t);
|
|
|
|
|
|
|
|
connect(target->project(), &Project::activeTargetChanged,
|
|
|
|
this, &QmlBuildSystem::onActiveTargetChanged);
|
|
|
|
updateDeploymentData();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QmlBuildSystem::~QmlBuildSystem()
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2010-09-24 14:29:40 +02:00
|
|
|
delete m_projectItem.data();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::triggerParsing()
|
2012-10-09 16:20:26 +02:00
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
refresh(Everything);
|
2012-10-09 16:20:26 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::onActiveTargetChanged(Target *)
|
2013-11-06 12:59:04 +01:00
|
|
|
{
|
|
|
|
// make sure e.g. the default qml imports are adapted
|
|
|
|
refresh(Configuration);
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::onKitChanged()
|
2013-05-02 15:29:33 +02:00
|
|
|
{
|
|
|
|
// make sure e.g. the default qml imports are adapted
|
|
|
|
refresh(Configuration);
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Utils::FilePath QmlBuildSystem::canonicalProjectDir() const
|
2009-05-06 16:13:44 +02:00
|
|
|
{
|
2017-11-28 15:57:15 +01:00
|
|
|
return m_canonicalProjectDir;
|
2009-05-06 16:13:44 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::parseProject(RefreshOptions options)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
if (options & Files) {
|
2010-01-19 13:53:48 +01:00
|
|
|
if (options & ProjectFile)
|
|
|
|
delete m_projectItem.data();
|
2010-01-18 16:32:14 +01:00
|
|
|
if (!m_projectItem) {
|
2013-07-11 17:37:02 +02:00
|
|
|
QString errorMessage;
|
2016-01-08 12:12:27 +01:00
|
|
|
m_projectItem = QmlProjectFileFormat::parseProjectFile(projectFilePath(), &errorMessage);
|
2013-07-11 17:37:02 +02:00
|
|
|
if (m_projectItem) {
|
2016-07-01 12:19:37 +03:00
|
|
|
connect(m_projectItem.data(), &QmlProjectItem::qmlFilesChanged,
|
2019-10-25 09:55:32 +02:00
|
|
|
this, &QmlBuildSystem::refreshFiles);
|
2013-07-11 17:37:02 +02:00
|
|
|
|
|
|
|
} else {
|
2020-12-17 10:30:03 +01:00
|
|
|
MessageManager::writeFlashing(tr("Error while loading project file %1.")
|
|
|
|
.arg(projectFilePath().toUserOutput()));
|
|
|
|
MessageManager::writeSilently(errorMessage);
|
2013-07-11 17:37:02 +02:00
|
|
|
}
|
2010-01-18 16:32:14 +01:00
|
|
|
}
|
|
|
|
if (m_projectItem) {
|
2017-11-28 15:57:15 +01:00
|
|
|
m_projectItem.data()->setSourceDirectory(canonicalProjectDir().toString());
|
|
|
|
if (m_projectItem->targetDirectory().isEmpty())
|
|
|
|
m_projectItem->setTargetDirectory(canonicalProjectDir().toString());
|
|
|
|
|
2017-03-14 11:18:09 +01:00
|
|
|
if (auto modelManager = QmlJS::ModelManagerInterface::instance())
|
|
|
|
modelManager->updateSourceFiles(m_projectItem.data()->files(), true);
|
2012-01-02 15:54:51 +01:00
|
|
|
|
|
|
|
QString mainFilePath = m_projectItem.data()->mainFile();
|
|
|
|
if (!mainFilePath.isEmpty()) {
|
2017-11-28 15:57:15 +01:00
|
|
|
mainFilePath
|
|
|
|
= QDir(canonicalProjectDir().toString()).absoluteFilePath(mainFilePath);
|
2013-01-21 13:54:20 +01:00
|
|
|
Utils::FileReader reader;
|
|
|
|
QString errorMessage;
|
2021-05-18 09:47:07 +02:00
|
|
|
if (!reader.fetch(Utils::FilePath::fromString(mainFilePath), &errorMessage)) {
|
2020-12-17 10:30:03 +01:00
|
|
|
MessageManager::writeFlashing(tr("Warning while loading project file %1.")
|
|
|
|
.arg(projectFilePath().toUserOutput()));
|
|
|
|
MessageManager::writeSilently(errorMessage);
|
2012-01-02 15:54:51 +01:00
|
|
|
}
|
|
|
|
}
|
2010-01-18 16:32:14 +01:00
|
|
|
}
|
2017-03-01 14:26:46 +01:00
|
|
|
generateProjectTree();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options & Configuration) {
|
|
|
|
// update configuration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::refresh(RefreshOptions options)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2019-08-06 14:46:37 +02:00
|
|
|
ParseGuard guard = guardParsingRun();
|
2009-05-04 12:19:22 +02:00
|
|
|
parseProject(options);
|
|
|
|
|
|
|
|
if (options & Files)
|
2017-03-01 14:26:46 +01:00
|
|
|
generateProjectTree();
|
2010-06-22 12:54:19 +02:00
|
|
|
|
2017-03-14 11:18:09 +01:00
|
|
|
auto modelManager = QmlJS::ModelManagerInterface::instance();
|
|
|
|
if (!modelManager)
|
2014-07-24 11:48:30 +02:00
|
|
|
return;
|
|
|
|
|
2012-12-06 17:20:58 +01:00
|
|
|
QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
|
2019-10-25 09:55:32 +02:00
|
|
|
modelManager->defaultProjectInfoForProject(project());
|
2018-02-26 14:26:07 +01:00
|
|
|
foreach (const QString &searchPath, makeAbsolute(canonicalProjectDir(), customImportPaths()))
|
2019-05-28 13:49:26 +02:00
|
|
|
projectInfo.importPaths.maybeInsert(Utils::FilePath::fromString(searchPath),
|
2014-07-22 19:06:44 +02:00
|
|
|
QmlJS::Dialect::Qml);
|
2013-01-10 16:12:45 +01:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
modelManager->updateProjectInfo(projectInfo, project());
|
2016-10-20 13:18:54 +02:00
|
|
|
|
2019-08-06 14:46:37 +02:00
|
|
|
guard.markAsSuccess();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QString QmlBuildSystem::mainFile() const
|
2010-12-03 17:04:29 +01:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem.data()->mainFile();
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2021-03-22 21:15:11 +01:00
|
|
|
Utils::FilePath QmlBuildSystem::mainFilePath() const
|
|
|
|
{
|
|
|
|
return projectDirectory().pathAppended(mainFile());
|
|
|
|
}
|
|
|
|
|
2020-02-20 14:51:45 +01:00
|
|
|
bool QmlBuildSystem::qtForMCUs() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem.data()->qtForMCUs();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-27 14:18:39 +02:00
|
|
|
bool QmlBuildSystem::qt6Project() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem.data()->qt6Project();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::setMainFile(const QString &mainFilePath)
|
2019-01-18 20:38:48 +01:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
m_projectItem.data()->setMainFile(mainFilePath);
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Utils::FilePath QmlBuildSystem::targetDirectory() const
|
2017-11-28 15:57:15 +01:00
|
|
|
{
|
2020-09-07 15:56:18 +02:00
|
|
|
if (DeviceTypeKitAspect::deviceTypeId(kit())
|
2017-11-28 15:57:15 +01:00
|
|
|
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)
|
|
|
|
return canonicalProjectDir();
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
return m_projectItem ? Utils::FilePath::fromString(m_projectItem->targetDirectory())
|
|
|
|
: Utils::FilePath();
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Utils::FilePath QmlBuildSystem::targetFile(const Utils::FilePath &sourceFile) const
|
2017-11-28 15:57:15 +01:00
|
|
|
{
|
|
|
|
const QDir sourceDir(m_projectItem ? m_projectItem->sourceDirectory()
|
|
|
|
: canonicalProjectDir().toString());
|
2019-10-25 09:55:32 +02:00
|
|
|
const QDir targetDir(targetDirectory().toString());
|
2017-11-28 15:57:15 +01:00
|
|
|
const QString relative = sourceDir.relativeFilePath(sourceFile.toString());
|
2019-05-28 13:49:26 +02:00
|
|
|
return Utils::FilePath::fromString(QDir::cleanPath(targetDir.absoluteFilePath(relative)));
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Utils::EnvironmentItems QmlBuildSystem::environment() const
|
2018-01-29 13:38:41 +01:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem.data()->environment();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QStringList QmlBuildSystem::customImportPaths() const
|
2010-02-03 09:13:23 +01:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
2018-02-24 18:36:58 +01:00
|
|
|
return m_projectItem.data()->importPaths();
|
|
|
|
return {};
|
2010-02-03 09:13:23 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QStringList QmlBuildSystem::customFileSelectors() const
|
2019-04-08 17:02:20 +02:00
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem.data()->fileSelectors();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::refreshProjectFile()
|
2010-01-19 13:53:48 +01:00
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
refresh(QmlBuildSystem::ProjectFile | Files);
|
2010-01-19 13:53:48 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QStringList QmlBuildSystem::makeAbsolute(const Utils::FilePath &path, const QStringList &relativePaths)
|
2018-02-26 14:26:07 +01:00
|
|
|
{
|
|
|
|
if (path.isEmpty())
|
|
|
|
return relativePaths;
|
|
|
|
|
|
|
|
const QDir baseDir(path.toString());
|
|
|
|
return Utils::transform(relativePaths, [&baseDir](const QString &path) {
|
|
|
|
return QDir::cleanPath(baseDir.absoluteFilePath(path));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::refreshFiles(const QSet<QString> &/*added*/, const QSet<QString> &removed)
|
2010-01-19 13:53:48 +01:00
|
|
|
{
|
2020-03-03 12:30:28 +01:00
|
|
|
if (m_blockFilesUpdate) {
|
|
|
|
qCDebug(infoLogger) << "Auto files refresh blocked.";
|
|
|
|
return;
|
|
|
|
}
|
2010-01-19 13:53:48 +01:00
|
|
|
refresh(Files);
|
2017-03-14 11:18:09 +01:00
|
|
|
if (!removed.isEmpty()) {
|
|
|
|
if (auto modelManager = QmlJS::ModelManagerInterface::instance())
|
2019-07-03 18:34:30 +02:00
|
|
|
modelManager->removeFiles(Utils::toList(removed));
|
2017-03-14 11:18:09 +01:00
|
|
|
}
|
2017-11-28 15:57:15 +01:00
|
|
|
refreshTargetDirectory();
|
2010-01-19 13:53:48 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::refreshTargetDirectory()
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
updateDeploymentData();
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks QmlProject::projectIssues(const Kit *k) const
|
2017-11-28 15:57:15 +01:00
|
|
|
{
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks result = Project::projectIssues(k);
|
2018-04-18 13:39:05 +02:00
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
const QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(k);
|
2018-04-18 13:39:05 +02:00
|
|
|
if (!version)
|
|
|
|
result.append(createProjectTask(Task::TaskType::Error, tr("No Qt version set in kit.")));
|
2018-03-08 17:46:20 +01:00
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
IDevice::ConstPtr dev = DeviceKitAspect::device(k);
|
2018-04-18 13:39:05 +02:00
|
|
|
if (dev.isNull())
|
|
|
|
result.append(createProjectTask(Task::TaskType::Error, tr("Kit has no device.")));
|
2018-03-08 17:46:20 +01:00
|
|
|
|
2018-04-18 13:39:05 +02:00
|
|
|
if (version && version->qtVersion() < QtSupport::QtVersionNumber(5, 0, 0))
|
|
|
|
result.append(createProjectTask(Task::TaskType::Error, tr("Qt version is too old.")));
|
|
|
|
|
|
|
|
if (dev.isNull() || !version)
|
|
|
|
return result; // No need to check deeper than this
|
2018-03-08 17:46:20 +01:00
|
|
|
|
|
|
|
if (dev->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
2018-03-08 17:46:51 +01:00
|
|
|
if (version->type() == QtSupport::Constants::DESKTOPQT) {
|
2021-07-13 09:41:26 +02:00
|
|
|
if (version->qmlRuntimeFilePath().isEmpty()) {
|
2018-04-18 13:39:05 +02:00
|
|
|
result.append(createProjectTask(Task::TaskType::Error,
|
2021-07-12 10:38:13 +02:00
|
|
|
tr("Qt version has no QML utility.")));
|
2018-03-08 17:46:20 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Non-desktop Qt on a desktop device? We don't support that.
|
2018-04-18 13:39:05 +02:00
|
|
|
result.append(createProjectTask(Task::TaskType::Error,
|
2018-06-08 13:53:51 +02:00
|
|
|
tr("Non-desktop Qt is used with a desktop device.")));
|
2018-03-08 17:46:20 +01:00
|
|
|
}
|
2018-04-18 13:39:05 +02:00
|
|
|
} else {
|
2021-07-12 10:38:13 +02:00
|
|
|
// If not a desktop device, don't check the Qt version for qml runtime binary.
|
|
|
|
// The device is responsible for providing it and we assume qml runtime can be found
|
2018-04-18 13:39:05 +02:00
|
|
|
// in $PATH if it's not explicitly given.
|
2018-03-08 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
2018-04-18 13:39:05 +02:00
|
|
|
return result;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2015-05-18 16:57:29 +02:00
|
|
|
Project::RestoreResult QmlProject::fromMap(const QVariantMap &map, QString *errorMessage)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2015-05-18 16:57:29 +02:00
|
|
|
RestoreResult result = Project::fromMap(map, errorMessage);
|
2015-09-08 17:15:17 +02:00
|
|
|
if (result != RestoreResult::Ok)
|
2015-05-18 16:57:29 +02:00
|
|
|
return result;
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2013-03-07 14:02:04 +01:00
|
|
|
if (!activeTarget()) {
|
|
|
|
// find a kit that matches prerequisites (prefer default one)
|
2021-08-03 16:07:42 +02:00
|
|
|
const QList<Kit *> kits = Utils::filtered(KitManager::kits(), [this](const Kit *k) {
|
|
|
|
return !containsType(projectIssues(k), Task::TaskType::Error)
|
|
|
|
&& DeviceTypeKitAspect::deviceTypeId(k)
|
|
|
|
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
|
2018-04-18 13:39:05 +02:00
|
|
|
});
|
2013-03-07 14:02:04 +01:00
|
|
|
|
|
|
|
if (!kits.isEmpty()) {
|
2019-08-01 14:58:00 +02:00
|
|
|
if (kits.contains(KitManager::defaultKit()))
|
|
|
|
addTargetForDefaultKit();
|
|
|
|
else
|
|
|
|
addTargetForKit(kits.first());
|
2013-03-07 14:02:04 +01:00
|
|
|
}
|
2021-08-03 16:07:42 +02:00
|
|
|
|
|
|
|
if (isQtDesignStudio()) {
|
|
|
|
auto setKitWithVersion = [&](int qtMajorVersion) {
|
|
|
|
const QList<Kit *> qtVersionkits
|
|
|
|
= Utils::filtered(kits, [qtMajorVersion](const Kit *k) {
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(k);
|
|
|
|
return (version && version->qtVersion().majorVersion == qtMajorVersion);
|
|
|
|
});
|
|
|
|
if (!qtVersionkits.isEmpty()) {
|
|
|
|
if (qtVersionkits.contains(KitManager::defaultKit()))
|
|
|
|
addTargetForDefaultKit();
|
|
|
|
else
|
|
|
|
addTargetForKit(qtVersionkits.first());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int preferedVersion = preferedQtTarget(activeTarget());
|
|
|
|
|
|
|
|
if (activeTarget())
|
|
|
|
removeTarget(activeTarget());
|
|
|
|
|
|
|
|
setKitWithVersion(preferedVersion);
|
|
|
|
}
|
2013-03-07 14:02:04 +01:00
|
|
|
}
|
2009-05-07 12:27:52 +02:00
|
|
|
|
2015-05-18 16:57:29 +02:00
|
|
|
return RestoreResult::Ok;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 14:49:59 +02:00
|
|
|
ProjectExplorer::DeploymentKnowledge QmlProject::deploymentKnowledge() const
|
|
|
|
{
|
|
|
|
return DeploymentKnowledge::Perfect;
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::generateProjectTree()
|
2017-03-01 14:26:46 +01:00
|
|
|
{
|
2017-03-27 12:12:38 +02:00
|
|
|
if (!m_projectItem)
|
|
|
|
return;
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
auto newRoot = std::make_unique<QmlProjectNode>(project());
|
2017-03-01 14:26:46 +01:00
|
|
|
|
2020-07-20 16:25:53 +02:00
|
|
|
for (const QString &f : m_projectItem->files()) {
|
2019-05-28 13:49:26 +02:00
|
|
|
const Utils::FilePath fileName = Utils::FilePath::fromString(f);
|
2017-11-23 11:41:35 +01:00
|
|
|
const FileType fileType = (fileName == projectFilePath())
|
|
|
|
? FileType::Project : FileNode::fileTypeForFileName(fileName);
|
2019-02-25 12:08:58 +01:00
|
|
|
newRoot->addNestedNode(std::make_unique<FileNode>(fileName, fileType));
|
2017-03-10 17:30:40 +01:00
|
|
|
}
|
2019-02-25 12:08:58 +01:00
|
|
|
newRoot->addNestedNode(std::make_unique<FileNode>(projectFilePath(), FileType::Project));
|
2017-03-01 14:26:46 +01:00
|
|
|
|
2019-11-20 15:21:54 +01:00
|
|
|
setRootProjectNode(std::move(newRoot));
|
2017-11-28 15:57:15 +01:00
|
|
|
refreshTargetDirectory();
|
2017-03-01 14:26:46 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void QmlBuildSystem::updateDeploymentData()
|
2017-11-28 15:57:15 +01:00
|
|
|
{
|
|
|
|
if (!m_projectItem)
|
|
|
|
return;
|
|
|
|
|
2020-09-07 15:56:18 +02:00
|
|
|
if (DeviceTypeKitAspect::deviceTypeId(kit())
|
2017-11-28 15:57:15 +01:00
|
|
|
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::DeploymentData deploymentData;
|
|
|
|
for (const QString &file : m_projectItem->files()) {
|
|
|
|
deploymentData.addFile(
|
2021-09-13 12:55:01 +02:00
|
|
|
FilePath::fromString(file),
|
2019-10-25 09:55:32 +02:00
|
|
|
targetFile(Utils::FilePath::fromString(file)).parentDir().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
setDeploymentData(deploymentData);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant QmlBuildSystem::additionalData(Id id) const
|
|
|
|
{
|
|
|
|
if (id == Constants::customFileSelectorsData)
|
|
|
|
return customFileSelectors();
|
2019-12-06 13:04:17 +02:00
|
|
|
if (id == Constants::customForceFreeTypeData)
|
|
|
|
return forceFreeType();
|
2020-02-20 14:51:45 +01:00
|
|
|
if (id == Constants::customQtForMCUs)
|
|
|
|
return qtForMCUs();
|
2021-07-27 14:18:39 +02:00
|
|
|
if (id == Constants::customQt6Project)
|
|
|
|
return qt6Project();
|
2021-08-16 13:48:26 +02:00
|
|
|
if (id == Constants::mainFilePath)
|
|
|
|
return mainFilePath().toString();
|
|
|
|
if (id == Constants::customImportPaths)
|
|
|
|
return customImportPaths();
|
|
|
|
if (id == Constants::canonicalProjectDir)
|
|
|
|
return canonicalProjectDir().toString();
|
2019-10-25 09:55:32 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
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::qmlProject() const
|
|
|
|
{
|
|
|
|
return static_cast<QmlProject *>(BuildSystem::project());
|
|
|
|
}
|
|
|
|
|
2019-12-06 13:04:17 +02:00
|
|
|
bool QmlBuildSystem::forceFreeType() const
|
|
|
|
{
|
|
|
|
if (m_projectItem)
|
|
|
|
return m_projectItem.data()->forceFreeType();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
bool QmlBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FilePaths *)
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
|
|
|
if (!dynamic_cast<QmlProjectNode *>(context))
|
|
|
|
return false;
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
FilePaths toAdd;
|
|
|
|
for (const FilePath &filePath : filePaths) {
|
|
|
|
if (!m_projectItem.data()->matchesFile(filePath.toString()))
|
2019-10-25 09:55:32 +02:00
|
|
|
toAdd << filePaths;
|
|
|
|
}
|
|
|
|
return toAdd.isEmpty();
|
|
|
|
}
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
bool QmlBuildSystem::deleteFiles(Node *context, const FilePaths &filePaths)
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
|
|
|
if (dynamic_cast<QmlProjectNode *>(context))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return BuildSystem::deleteFiles(context, filePaths);
|
|
|
|
}
|
|
|
|
|
2021-06-11 14:34:34 +02:00
|
|
|
bool QmlBuildSystem::renameFile(Node * context, const FilePath &oldFilePath, const FilePath &newFilePath)
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
|
|
|
if (dynamic_cast<QmlProjectNode *>(context)) {
|
2021-06-11 14:34:34 +02:00
|
|
|
if (oldFilePath.endsWith(mainFile())) {
|
|
|
|
setMainFile(newFilePath.toString());
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
// make sure to change it also in the qmlproject file
|
2020-09-02 12:06:51 +02:00
|
|
|
const Utils::FilePath qmlProjectFilePath = project()->projectFilePath();
|
2021-06-09 09:59:37 +02:00
|
|
|
Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath);
|
2019-10-25 09:55:32 +02:00
|
|
|
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
|
2021-05-18 07:57:14 +02:00
|
|
|
if (Utils::TextFileFormat::readFile(qmlProjectFilePath, codec, &fileContent, &textFileFormat, &error)
|
2019-10-25 09:55:32 +02:00
|
|
|
!= 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 \.
|
2021-06-11 14:34:34 +02:00
|
|
|
QString originalFileName = oldFilePath.fileName();
|
2019-10-25 09:55:32 +02:00
|
|
|
originalFileName.replace(".", "\\.");
|
|
|
|
const QRegularExpression expression(QString("mainFile:\\s*\"(%1)\"").arg(originalFileName));
|
|
|
|
const QRegularExpressionMatch match = expression.match(fileContent);
|
|
|
|
|
2021-06-11 14:34:34 +02:00
|
|
|
fileContent.replace(match.capturedStart(1), match.capturedLength(1), newFilePath.fileName());
|
2019-10-25 09:55:32 +02:00
|
|
|
|
2021-05-18 07:57:14 +02:00
|
|
|
if (!textFileFormat.writeFile(qmlProjectFilePath, fileContent, &error))
|
2019-10-25 09:55:32 +02:00
|
|
|
qWarning() << "Failed to write file" << qmlProjectFilePath << ":" << error;
|
|
|
|
|
|
|
|
refresh(Everything);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
|
|
|
|
2021-06-11 14:34:34 +02:00
|
|
|
return BuildSystem::renameFile(context, oldFilePath, newFilePath);
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
2019-10-22 14:55:51 +02:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
} // namespace QmlProjectManager
|
2009-12-17 09:54:16 +01:00
|
|
|
|