QtSupport: Add a QmlDebuggingAspect

... and make use of it in the qbs build configuration.
We cannot use it for qmake yet, because the build config there still has
a custom, non-aspectified widget.

Change-Id: Iacf902a2d9384d0074b10fdc98e082fa906fb6d6
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2019-11-22 14:50:15 +01:00
parent 5795dc24c7
commit 72ca179633
14 changed files with 173 additions and 76 deletions

View File

@@ -244,6 +244,9 @@ bool DebuggerRunConfigurationAspect::useQmlDebugger() const
// (Using the Qt metatype system to avoid a hard qt4projectmanager dependency)
//
if (BuildConfiguration *bc = m_target->activeBuildConfiguration()) {
QVariant linkProperty = bc->property("linkQmlDebuggingLibrary");
if (linkProperty.isValid() && linkProperty.canConvert(QVariant::Bool))
return linkProperty.toBool();
if (BuildStepList *bsl = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD)) {
foreach (BuildStep *step, bsl->steps()) {
QVariant linkProperty = step->property("linkQmlDebuggingLibrary");

View File

@@ -394,6 +394,11 @@ void BaseBoolAspect::toMap(QVariantMap &data) const
data.insert(settingsKey(), d->m_value);
}
QCheckBox *BaseBoolAspect::checkBox() const
{
return d->m_checkBox;
}
bool BaseBoolAspect::defaultValue() const
{
return d->m_defaultValue;

View File

@@ -33,6 +33,10 @@
#include <memory>
QT_BEGIN_NAMESPACE
class QCheckBox;
QT_END_NAMESPACE
namespace ProjectExplorer {
namespace Internal {
@@ -64,6 +68,9 @@ public:
void fromMap(const QVariantMap &map) override;
void toMap(QVariantMap &map) const override;
protected:
QCheckBox *checkBox() const;
private:
std::unique_ptr<Internal::BaseBoolAspectPrivate> d;
};

View File

@@ -45,6 +45,7 @@
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <qtsupport/qtbuildaspects.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/mimetypes/mimedatabase.h>
@@ -87,6 +88,11 @@ QbsBuildConfiguration::QbsBuildConfiguration(Target *target, Core::Id id)
connect(m_configurationName, &BaseStringAspect::changed,
this, &BuildConfiguration::buildDirectoryChanged);
const auto qmlDebuggingAspect = addAspect<QtSupport::QmlDebuggingAspect>();
qmlDebuggingAspect->setKit(target->kit());
connect(qmlDebuggingAspect, &QtSupport::QmlDebuggingAspect::changed,
this, &QbsBuildConfiguration::qbsConfigurationChanged);
connect(this, &BuildConfiguration::environmentChanged,
this, &QbsBuildConfiguration::triggerReparseIfActive);
connect(this, &BuildConfiguration::buildDirectoryChanged,
@@ -144,11 +150,11 @@ void QbsBuildConfiguration::initialize()
+ '_' + kitHash.toHex().left(16);
m_configurationName->setValue(uniqueConfigName);
if (initialBuildType() == Release)
aspect<QtSupport::QmlDebuggingAspect>()->setDefaultValue(false);
BuildStepList *buildSteps = stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
auto bs = new QbsBuildStep(buildSteps);
if (initialBuildType() == Release)
bs->setQmlDebuggingEnabled(false);
bs->setQbsConfiguration(bd);
buildSteps->appendStep(bs);
@@ -369,6 +375,11 @@ QString QbsBuildConfiguration::equivalentCommandLine(const BuildStep *buildStep)
return commandLine.arguments();
}
bool QbsBuildConfiguration::isQmlDebuggingEnabled() const
{
return aspect<QtSupport::QmlDebuggingAspect>()->value();
}
// ---------------------------------------------------------------------------
// QbsBuildConfigurationFactory:
// ---------------------------------------------------------------------------

View File

@@ -44,6 +44,11 @@ class QbsBuildConfiguration : public ProjectExplorer::BuildConfiguration
{
Q_OBJECT
// used in DebuggerRunConfigurationAspect
Q_PROPERTY(bool linkQmlDebuggingLibrary
READ isQmlDebuggingEnabled
NOTIFY qbsConfigurationChanged)
friend class ProjectExplorer::BuildConfigurationFactory;
QbsBuildConfiguration(ProjectExplorer::Target *target, Core::Id id);
~QbsBuildConfiguration() final;
@@ -69,6 +74,8 @@ public:
QString configurationName() const;
QString equivalentCommandLine(const ProjectExplorer::BuildStep *buildStep) const;
bool isQmlDebuggingEnabled() const;
signals:
void qbsConfigurationChanged();

View File

@@ -43,7 +43,6 @@
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/utilsicons.h>
#include <QBoxLayout>
#include <QCheckBox>
@@ -82,7 +81,6 @@ public:
private:
void updateState();
void updateQmlDebuggingOption();
void updatePropertyEdit(const QVariantMap &data);
void changeBuildVariant(int);
@@ -98,9 +96,6 @@ private:
QbsBuildStep *qbsStep() const;
// QML debugging:
void linkQmlDebuggingLibraryChecked(bool checked);
bool validateProperties(Utils::FancyLineEdit *edit, QString *errorMessage);
class Property
@@ -127,11 +122,8 @@ private:
QComboBox *buildVariantComboBox;
QSpinBox *jobSpinBox;
QCheckBox *qmlDebuggingLibraryCheckBox;
FancyLineEdit *propertyEdit;
PathChooser *installDirChooser;
QLabel *qmlDebuggingWarningIcon;
QLabel *qmlDebuggingWarningText;
QCheckBox *keepGoingCheckBox;
QCheckBox *showCommandLinesCheckBox;
QCheckBox *forceProbesCheckBox;
@@ -146,8 +138,7 @@ private:
// --------------------------------------------------------------------
QbsBuildStep::QbsBuildStep(ProjectExplorer::BuildStepList *bsl) :
ProjectExplorer::BuildStep(bsl, Constants::QBS_BUILDSTEP_ID),
m_enableQmlDebugging(QtSupport::BaseQtVersion::isQmlDebuggingSupported(target()->kit()))
ProjectExplorer::BuildStep(bsl, Constants::QBS_BUILDSTEP_ID)
{
setDisplayName(tr("Qbs Build"));
setQbsConfiguration(QVariantMap());
@@ -222,7 +213,7 @@ QVariantMap QbsBuildStep::qbsConfiguration(VariableHandling variableHandling) co
{
QVariantMap config = m_qbsConfiguration;
config.insert(Constants::QBS_FORCE_PROBES_KEY, m_forceProbes);
if (m_enableQmlDebugging)
if (static_cast<QbsBuildConfiguration *>(buildConfiguration())->isQmlDebuggingEnabled())
config.insert(Constants::QBS_CONFIG_QUICK_DEBUG_KEY, true);
else
config.remove(Constants::QBS_CONFIG_QUICK_DEBUG_KEY);
@@ -278,7 +269,6 @@ int QbsBuildStep::maxJobs() const
}
static QString forceProbesKey() { return QLatin1String("Qbs.forceProbesKey"); }
static QString enableQmlDebuggingKey() { return QLatin1String("Qbs.enableQmlDebuggingKey"); }
bool QbsBuildStep::fromMap(const QVariantMap &map)
{
@@ -292,7 +282,6 @@ bool QbsBuildStep::fromMap(const QVariantMap &map)
m_install = map.value(QBS_INSTALL, true).toBool();
m_cleanInstallDir = map.value(QBS_CLEAN_INSTALL_ROOT).toBool();
m_forceProbes = map.value(forceProbesKey()).toBool();
m_enableQmlDebugging = map.value(enableQmlDebuggingKey()).toBool();
return true;
}
@@ -306,7 +295,6 @@ QVariantMap QbsBuildStep::toMap() const
map.insert(QBS_INSTALL, m_install);
map.insert(QBS_CLEAN_INSTALL_ROOT, m_cleanInstallDir);
map.insert(forceProbesKey(), m_forceProbes);
map.insert(enableQmlDebuggingKey(), m_enableQmlDebugging);
return map;
}
@@ -532,7 +520,8 @@ QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step) :
{
connect(step, &ProjectConfiguration::displayNameChanged,
this, &QbsBuildStepConfigWidget::updateState);
connect(step, &QbsBuildStep::qbsConfigurationChanged,
connect(static_cast<QbsBuildConfiguration *>(step->buildConfiguration()),
&QbsBuildConfiguration::qbsConfigurationChanged,
this, &QbsBuildStepConfigWidget::updateState);
connect(step, &QbsBuildStep::qbsBuildOptionsChanged,
this, &QbsBuildStepConfigWidget::updateState);
@@ -563,22 +552,9 @@ QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step) :
horizontalLayout_6->addWidget(jobSpinBox);
horizontalLayout_6->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
qmlDebuggingLibraryCheckBox = new QCheckBox(this);
qmlDebuggingWarningIcon = new QLabel(this);
qmlDebuggingWarningText = new QLabel(this);
auto qmlDebuggingLayout = new QHBoxLayout();
qmlDebuggingLayout->addWidget(qmlDebuggingLibraryCheckBox);
qmlDebuggingLayout->addWidget(qmlDebuggingWarningIcon);
qmlDebuggingLayout->addWidget(qmlDebuggingWarningText);
qmlDebuggingLayout->addItem(new QSpacerItem(40, 5, QSizePolicy::Expanding, QSizePolicy::Minimum));
propertyEdit = new FancyLineEdit(this);
keepGoingCheckBox = new QCheckBox(this);
showCommandLinesCheckBox = new QCheckBox(this);
forceProbesCheckBox = new QCheckBox(this);
auto flagsLayout = new QHBoxLayout();
@@ -610,7 +586,6 @@ QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step) :
auto formLayout = new QFormLayout(this);
formLayout->addRow(tr("Build variant:"), horizontalLayout_5);
formLayout->addRow(tr("Parallel jobs:"), horizontalLayout_6);
formLayout->addRow(tr("Enable QML debugging:"), qmlDebuggingLayout);
formLayout->addRow(tr("Properties:"), propertyEdit);
formLayout->addRow(tr("Flags:"), flagsLayout);
formLayout->addRow(tr("Installation flags:"), installLayout);
@@ -618,8 +593,7 @@ QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step) :
formLayout->addRow(tr("Equivalent command line:"), commandLineTextEdit);
QWidget::setTabOrder(buildVariantComboBox, jobSpinBox);
QWidget::setTabOrder(jobSpinBox, qmlDebuggingLibraryCheckBox);
QWidget::setTabOrder(qmlDebuggingLibraryCheckBox, propertyEdit);
QWidget::setTabOrder(jobSpinBox, propertyEdit);
QWidget::setTabOrder(propertyEdit, keepGoingCheckBox);
QWidget::setTabOrder(keepGoingCheckBox, showCommandLinesCheckBox);
QWidget::setTabOrder(showCommandLinesCheckBox, forceProbesCheckBox);
@@ -647,8 +621,6 @@ QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step) :
return validateProperties(edit, errorMessage);
});
qmlDebuggingWarningIcon->setPixmap(Utils::Icons::WARNING.pixmap());
connect(buildVariantComboBox,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &QbsBuildStepConfigWidget::changeBuildVariant);
@@ -668,8 +640,6 @@ QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step) :
&QbsBuildStepConfigWidget::changeInstallDir);
connect(forceProbesCheckBox, &QCheckBox::toggled, this,
&QbsBuildStepConfigWidget::changeForceProbes);
connect(qmlDebuggingLibraryCheckBox, &QAbstractButton::toggled,
this, &QbsBuildStepConfigWidget::linkQmlDebuggingLibraryChecked);
updateState();
}
@@ -683,43 +653,27 @@ void QbsBuildStepConfigWidget::updateState()
cleanInstallRootCheckBox->setChecked(qbsStep()->cleanInstallRoot());
forceProbesCheckBox->setChecked(qbsStep()->forceProbes());
updatePropertyEdit(qbsStep()->qbsConfiguration(QbsBuildStep::PreserveVariables));
qmlDebuggingLibraryCheckBox->setChecked(qbsStep()->isQmlDebuggingEnabled());
installDirChooser->setFileName(qbsStep()->installRoot(QbsBuildStep::PreserveVariables));
defaultInstallDirCheckBox->setChecked(!qbsStep()->hasCustomInstallRoot());
}
updateQmlDebuggingOption();
const QString buildVariant = qbsStep()->buildVariant();
const int idx = (buildVariant == Constants::QBS_VARIANT_DEBUG) ? 0 : 1;
buildVariantComboBox->setCurrentIndex(idx);
QString command = static_cast<QbsBuildConfiguration *>(step()->buildConfiguration())
->equivalentCommandLine(qbsStep());
const auto qbsBuildConfig = static_cast<QbsBuildConfiguration *>(step()->buildConfiguration());
QString command = qbsBuildConfig->equivalentCommandLine(qbsStep());
for (int i = 0; i < m_propertyCache.count(); ++i) {
command += ' ' + m_propertyCache.at(i).name + ':' + m_propertyCache.at(i).effectiveValue;
}
if (qbsStep()->isQmlDebuggingEnabled())
if (qbsBuildConfig->isQmlDebuggingEnabled())
command.append(' ').append(Constants::QBS_CONFIG_QUICK_DEBUG_KEY).append(":true");
commandLineTextEdit->setPlainText(command);
setSummaryText(tr("<b>Qbs:</b> %1").arg(command));
}
void QbsBuildStepConfigWidget::updateQmlDebuggingOption()
{
QString warningText;
bool supported = QtSupport::BaseQtVersion::isQmlDebuggingSupported(step()->target()->kit(),
&warningText);
qmlDebuggingLibraryCheckBox->setEnabled(supported);
if (supported && qbsStep()->isQmlDebuggingEnabled())
warningText = tr("Might make your application vulnerable. Only use in a safe environment.");
qmlDebuggingWarningText->setText(warningText);
qmlDebuggingWarningIcon->setVisible(!warningText.isEmpty());
}
void QbsBuildStepConfigWidget::updatePropertyEdit(const QVariantMap &data)
{
@@ -852,13 +806,6 @@ QbsBuildStep *QbsBuildStepConfigWidget::qbsStep() const
return static_cast<QbsBuildStep *>(step());
}
void QbsBuildStepConfigWidget::linkQmlDebuggingLibraryChecked(bool checked)
{
m_ignoreChange = true;
qbsStep()->setQmlDebuggingEnabled(checked);
m_ignoreChange = false;
}
bool QbsBuildStepConfigWidget::validateProperties(Utils::FancyLineEdit *edit, QString *errorMessage)
{
Utils::QtcProcess::SplitError err;

View File

@@ -44,10 +44,6 @@ class QbsBuildStep : public ProjectExplorer::BuildStep
{
Q_OBJECT
// used in DebuggerRunConfigurationAspect
Q_PROPERTY(bool linkQmlDebuggingLibrary READ isQmlDebuggingEnabled
WRITE setQmlDebuggingEnabled NOTIFY qbsConfigurationChanged)
public:
enum VariableHandling
{
@@ -73,12 +69,6 @@ public:
void setForceProbes(bool force) { m_forceProbes = force; emit qbsConfigurationChanged(); }
bool forceProbes() const { return m_forceProbes; }
void setQmlDebuggingEnabled(bool debug) {
m_enableQmlDebugging = debug;
emit qbsConfigurationChanged();
}
bool isQmlDebuggingEnabled() const { return m_enableQmlDebugging; }
QbsBuildSystem *qbsBuildSystem() const;
signals:
@@ -129,7 +119,6 @@ private:
bool m_install = true;
bool m_cleanInstallDir = false;
bool m_forceProbes = false;
bool m_enableQmlDebugging;
// Temporary data:
QStringList m_changedFiles;

View File

@@ -13,6 +13,7 @@ add_qtc_plugin(QtSupport
profilereader.cpp profilereader.h
qmldumptool.cpp qmldumptool.h
qscxmlcgenerator.cpp qscxmlcgenerator.h
qtbuildaspects.cpp qtbuildaspects.h
qtconfigwidget.cpp qtconfigwidget.h
qtcppkitinfo.cpp qtcppkitinfo.h
qtkitinformation.cpp qtkitinformation.h

View File

@@ -1937,7 +1937,7 @@ bool BaseQtVersion::isSubProject(const FilePath &filePath) const
return false;
}
bool BaseQtVersion::isQmlDebuggingSupported(Kit *k, QString *reason)
bool BaseQtVersion::isQmlDebuggingSupported(const Kit *k, QString *reason)
{
QTC_ASSERT(k, return false);
BaseQtVersion *version = QtKitAspect::qtVersion(k);

View File

@@ -174,7 +174,7 @@ public:
/// warnings and finally info items.
ProjectExplorer::Tasks reportIssues(const QString &proFile, const QString &buildDir) const;
static bool isQmlDebuggingSupported(ProjectExplorer::Kit *k, QString *reason = nullptr);
static bool isQmlDebuggingSupported(const ProjectExplorer::Kit *k, QString *reason = nullptr);
bool isQmlDebuggingSupported(QString *reason = nullptr) const;
static bool isQtQuickCompilerSupported(ProjectExplorer::Kit *k, QString *reason = nullptr);
bool isQtQuickCompilerSupported(QString *reason = nullptr) const;

View File

@@ -0,0 +1,75 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#include "qtbuildaspects.h"
#include "baseqtversion.h"
#include <projectexplorer/kitmanager.h>
#include <utils/utilsicons.h>
#include <QCheckBox>
#include <QLabel>
#include <QLayout>
using namespace ProjectExplorer;
namespace QtSupport {
QmlDebuggingAspect::QmlDebuggingAspect() : BaseBoolAspect("EnableQmlDebugging")
{
setDefaultValue(true);
setLabel(tr("Enable QML debugging and profiling"));
}
void QmlDebuggingAspect::addToLayout(LayoutBuilder &builder)
{
BaseBoolAspect::addToLayout(builder);
const auto warningIconLabel = new QLabel;
warningIconLabel->setAlignment(Qt::AlignTop);
warningIconLabel->setPixmap(Utils::Icons::WARNING.pixmap());
const auto warningTextLabel = new QLabel;
warningTextLabel->setAlignment(Qt::AlignTop);
builder.startNewRow().addItems(QString(), warningIconLabel, warningTextLabel);
const auto changeHandler = [this, warningIconLabel, warningTextLabel] {
QString warningText;
const bool supported = m_kit && BaseQtVersion::isQmlDebuggingSupported(m_kit, &warningText);
if (!supported) {
setValue(false);
} else if (value()) {
warningText = tr("Might make your application vulnerable.<br/>"
"Only use in a safe environment.");
}
warningTextLabel->setText(warningText);
checkBox()->setVisible(supported);
warningIconLabel->setVisible(supported && !warningText.isEmpty());
warningTextLabel->setVisible(supported);
};
connect(KitManager::instance(), &KitManager::kitsChanged, builder.layout(), changeHandler);
connect(this, &QmlDebuggingAspect::changed, builder.layout(), changeHandler);
changeHandler();
}
} // namespace QtSupport

View File

@@ -0,0 +1,48 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include "qtsupport_global.h"
#include <projectexplorer/projectconfigurationaspects.h>
namespace QtSupport {
class QTSUPPORT_EXPORT QmlDebuggingAspect : public ProjectExplorer::BaseBoolAspect
{
Q_OBJECT
public:
QmlDebuggingAspect();
void setKit(const ProjectExplorer::Kit *kit) { m_kit = kit; }
private:
void addToLayout(ProjectExplorer::LayoutBuilder &builder) override;
const ProjectExplorer::Kit *m_kit = nullptr;
};
} // namespace QtSupport

View File

@@ -11,6 +11,7 @@ HEADERS += \
codegensettings.h \
codegensettingspage.h \
gettingstartedwelcomepage.h \
qtbuildaspects.h \
qtcppkitinfo.h \
qtprojectimporter.h \
qtsupportplugin.h \
@@ -39,6 +40,7 @@ SOURCES += \
codegensettings.cpp \
codegensettingspage.cpp \
gettingstartedwelcomepage.cpp \
qtbuildaspects.cpp \
qtcppkitinfo.cpp \
qtprojectimporter.cpp \
qtsupportplugin.cpp \

View File

@@ -66,6 +66,8 @@ Project {
"codegensettingspage.cpp",
"codegensettingspage.h",
"codegensettingspagewidget.ui",
"qtbuildaspects.cpp",
"qtbuildaspects.h",
"qtconfigwidget.cpp",
"qtconfigwidget.h",
"qtcppkitinfo.cpp",