forked from qt-creator/qt-creator
QbsProjectManager: Switch to an out-of-process approach
That is, do not link to the qbscore library anymore. Instead, use the
JSON-based API.
Advantages:
- We can build Qt Creator with qbs support without qbs being present
on the build machine.
- Smaller memory footprint for Qt Creator, as the qbs build graphs
are now being managed by a separate process.
- Potential crashes in qbs will not kill the Qt Creator process.
Fixes: QTCREATORBUG-20622
Task-number: QTCREATORBUG-22904
Change-Id: If7d344b0ac65a99ff0a3a3db215d61b8d903e47e
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
@@ -26,50 +26,111 @@
|
||||
#include "qbsprofilessettingspage.h"
|
||||
#include "ui_qbsprofilessettingswidget.h"
|
||||
|
||||
#include "qbsprojectmanager.h"
|
||||
#include "qbsprofilemanager.h"
|
||||
#include "qbsprojectmanagerconstants.h"
|
||||
#include "qbsprojectmanagersettings.h"
|
||||
#include "qbssettings.h"
|
||||
|
||||
#include <app/app_version.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectexplorericons.h>
|
||||
#include <projectexplorer/taskhub.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <qbs.h>
|
||||
#include <utils/treemodel.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QHash>
|
||||
#include <QWidget>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace QbsProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class ProfileTreeItem : public Utils::TypedTreeItem<ProfileTreeItem, ProfileTreeItem>
|
||||
{
|
||||
public:
|
||||
ProfileTreeItem() = default;
|
||||
ProfileTreeItem(const QString &key, const QString &value) : m_key(key), m_value(value) { }
|
||||
|
||||
private:
|
||||
QVariant data(int column, int role) const override
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return {};
|
||||
if (column == 0)
|
||||
return m_key;
|
||||
if (column == 1)
|
||||
return m_value;
|
||||
return {};
|
||||
}
|
||||
|
||||
const QString m_key;
|
||||
const QString m_value;
|
||||
};
|
||||
|
||||
class ProfileModel : public Utils::TreeModel<ProfileTreeItem>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProfileModel() : TreeModel(static_cast<QObject *>(nullptr))
|
||||
{
|
||||
setHeader(QStringList{tr("Key"), tr("Value")});
|
||||
reload();
|
||||
}
|
||||
|
||||
void reload()
|
||||
{
|
||||
ProfileTreeItem * const newRoot = new ProfileTreeItem(QString(), QString());
|
||||
QHash<QStringList, ProfileTreeItem *> itemMap;
|
||||
const QStringList output = QbsProfileManager::runQbsConfig(
|
||||
QbsProfileManager::QbsConfigOp::Get, "profiles").split('\n', QString::SkipEmptyParts);
|
||||
for (QString line : output) {
|
||||
line = line.trimmed();
|
||||
line = line.mid(QString("profiles.").length());
|
||||
const int colonIndex = line.indexOf(':');
|
||||
if (colonIndex == -1)
|
||||
continue;
|
||||
const QStringList key = line.left(colonIndex).trimmed()
|
||||
.split('.', QString::SkipEmptyParts);
|
||||
const QString value = line.mid(colonIndex + 1).trimmed();
|
||||
QStringList partialKey;
|
||||
ProfileTreeItem *parent = newRoot;
|
||||
for (const QString &keyComponent : key) {
|
||||
partialKey << keyComponent;
|
||||
ProfileTreeItem *&item = itemMap[partialKey];
|
||||
if (!item) {
|
||||
item = new ProfileTreeItem(keyComponent, partialKey == key ? value : QString());
|
||||
parent->appendChild(item);
|
||||
}
|
||||
parent = item;
|
||||
}
|
||||
}
|
||||
setRootItem(newRoot);
|
||||
}
|
||||
};
|
||||
|
||||
class QbsProfilesSettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QbsProfilesSettingsWidget();
|
||||
|
||||
void apply();
|
||||
|
||||
private:
|
||||
void refreshKitsList();
|
||||
void displayCurrentProfile();
|
||||
|
||||
Ui::QbsProfilesSettingsWidget m_ui;
|
||||
qbs::SettingsModel m_model;
|
||||
ProfileModel m_model;
|
||||
};
|
||||
|
||||
QbsProfilesSettingsPage::QbsProfilesSettingsPage()
|
||||
: m_useQtcSettingsDirPersistent(QbsProjectManagerSettings::useCreatorSettingsDirForQbs())
|
||||
{
|
||||
setId("Y.QbsProfiles");
|
||||
setDisplayName(QCoreApplication::translate("QbsProjectManager", "Qbs"));
|
||||
setCategory(ProjectExplorer::Constants::KITS_SETTINGS_CATEGORY);
|
||||
setDisplayName(QCoreApplication::translate("QbsProjectManager", "Profiles"));
|
||||
setCategory(Constants::QBS_SETTINGS_CATEGORY);
|
||||
}
|
||||
|
||||
QWidget *QbsProfilesSettingsPage::widget()
|
||||
@@ -79,38 +140,17 @@ QWidget *QbsProfilesSettingsPage::widget()
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
void QbsProfilesSettingsPage::apply()
|
||||
{
|
||||
if (m_widget)
|
||||
m_widget->apply();
|
||||
m_useQtcSettingsDirPersistent = QbsProjectManagerSettings::useCreatorSettingsDirForQbs();
|
||||
}
|
||||
|
||||
void QbsProfilesSettingsPage::finish()
|
||||
{
|
||||
delete m_widget;
|
||||
m_widget = nullptr;
|
||||
QbsProjectManagerSettings::setUseCreatorSettingsDirForQbs(m_useQtcSettingsDirPersistent);
|
||||
QbsProjectManagerSettings::writeSettings();
|
||||
}
|
||||
|
||||
|
||||
QbsProfilesSettingsWidget::QbsProfilesSettingsWidget()
|
||||
: m_model(QbsProjectManagerSettings::qbsSettingsBaseDir(), qbs::Settings::UserScope)
|
||||
{
|
||||
m_model.setEditable(false);
|
||||
m_ui.setupUi(this);
|
||||
m_ui.settingsDirCheckBox->setText(tr("Store profiles in %1 settings directory")
|
||||
.arg(Core::Constants::IDE_DISPLAY_NAME));
|
||||
m_ui.settingsDirCheckBox->setChecked(QbsProjectManagerSettings::useCreatorSettingsDirForQbs());
|
||||
m_ui.versionValueLabel->setText(qbs::LanguageInfo::qbsVersion().toString());
|
||||
connect(ProjectExplorer::KitManager::instance(), &ProjectExplorer::KitManager::kitsChanged,
|
||||
connect(QbsProfileManager::instance(), &QbsProfileManager::qbsProfilesUpdated,
|
||||
this, &QbsProfilesSettingsWidget::refreshKitsList);
|
||||
connect(m_ui.settingsDirCheckBox, &QCheckBox::stateChanged, [this]() {
|
||||
QbsProjectManagerSettings::setUseCreatorSettingsDirForQbs(m_ui.settingsDirCheckBox->isChecked());
|
||||
m_model.updateSettingsDir(QbsProjectManagerSettings::qbsSettingsBaseDir());
|
||||
displayCurrentProfile();
|
||||
});
|
||||
connect(m_ui.expandButton, &QAbstractButton::clicked,
|
||||
m_ui.propertiesView, &QTreeView::expandAll);
|
||||
connect(m_ui.collapseButton, &QAbstractButton::clicked,
|
||||
@@ -118,12 +158,6 @@ QbsProfilesSettingsWidget::QbsProfilesSettingsWidget()
|
||||
refreshKitsList();
|
||||
}
|
||||
|
||||
void QbsProfilesSettingsWidget::apply()
|
||||
{
|
||||
m_model.reload();
|
||||
displayCurrentProfile();
|
||||
}
|
||||
|
||||
void QbsProfilesSettingsWidget::refreshKitsList()
|
||||
{
|
||||
m_ui.kitsComboBox->disconnect(this);
|
||||
@@ -135,10 +169,10 @@ void QbsProfilesSettingsWidget::refreshKitsList()
|
||||
currentId = Core::Id::fromSetting(m_ui.kitsComboBox->currentData());
|
||||
m_ui.kitsComboBox->clear();
|
||||
int newCurrentIndex = -1;
|
||||
QList<ProjectExplorer::Kit *> validKits = ProjectExplorer::KitManager::kits();
|
||||
Utils::erase(validKits, [](const ProjectExplorer::Kit *k) { return !k->isValid(); });
|
||||
QList<Kit *> validKits = KitManager::kits();
|
||||
Utils::erase(validKits, [](const Kit *k) { return !k->isValid(); });
|
||||
const bool hasKits = !validKits.isEmpty();
|
||||
foreach (const ProjectExplorer::Kit * const kit, validKits) {
|
||||
for (const Kit * const kit : qAsConst(validKits)) {
|
||||
if (kit->id() == currentId)
|
||||
newCurrentIndex = m_ui.kitsComboBox->count();
|
||||
m_ui.kitsComboBox->addItem(kit->displayName(), kit->id().toSetting());
|
||||
@@ -159,24 +193,18 @@ void QbsProfilesSettingsWidget::displayCurrentProfile()
|
||||
if (m_ui.kitsComboBox->currentIndex() == -1)
|
||||
return;
|
||||
const Core::Id kitId = Core::Id::fromSetting(m_ui.kitsComboBox->currentData());
|
||||
const ProjectExplorer::Kit * const kit = ProjectExplorer::KitManager::kit(kitId);
|
||||
const Kit * const kit = KitManager::kit(kitId);
|
||||
QTC_ASSERT(kit, return);
|
||||
const QString profileName = QbsManager::profileForKit(kit);
|
||||
const QString profileName = QbsProfileManager::profileForKit(kit);
|
||||
m_ui.profileValueLabel->setText(profileName);
|
||||
for (int i = 0; i < m_model.rowCount(); ++i) {
|
||||
const QModelIndex profilesIndex = m_model.index(i, 0);
|
||||
if (m_model.data(profilesIndex).toString() != QLatin1String("profiles"))
|
||||
const QModelIndex currentProfileIndex = m_model.index(i, 0);
|
||||
if (m_model.data(currentProfileIndex, Qt::DisplayRole).toString() != profileName)
|
||||
continue;
|
||||
for (int i = 0; i < m_model.rowCount(profilesIndex); ++i) {
|
||||
const QModelIndex currentProfileIndex = m_model.index(i, 0, profilesIndex);
|
||||
if (m_model.data(currentProfileIndex).toString() != profileName)
|
||||
continue;
|
||||
m_ui.propertiesView->setModel(&m_model);
|
||||
m_ui.propertiesView->header()->setSectionResizeMode(m_model.keyColumn(),
|
||||
QHeaderView::ResizeToContents);
|
||||
m_ui.propertiesView->setRootIndex(currentProfileIndex);
|
||||
return;
|
||||
}
|
||||
m_ui.propertiesView->setModel(&m_model);
|
||||
m_ui.propertiesView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
m_ui.propertiesView->setRootIndex(currentProfileIndex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user