Commit 0d10ce38 authored by Tobias Hunger's avatar Tobias Hunger

CMake: Disable BC if there is an error during initial cmake run

* Disable the BC and give report the cmake error
* Show a warning label in the BC

Change-Id: If5737d033fa2682c264ab7ac1189c59947e3b28d
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 744008cc
......@@ -451,6 +451,14 @@ CMakeConfig BuildDirManager::parseConfiguration() const
CMakeConfigItem::Type t = fromByteArray(type);
if (t != CMakeConfigItem::INTERNAL)
result << CMakeConfigItem(key, t, documentation, value);
// Sanity checks:
if (key == "CMAKE_HOME_DIRECTORY") {
const Utils::FileName actualSourceDir = Utils::FileName::fromUserInput(QString::fromUtf8(value));
if (actualSourceDir != m_sourceDir)
emit errorOccured(tr("Build directory contains a build of the wrong project (%1).")
.arg(actualSourceDir.toUserOutput()));
}
}
}
......
......@@ -100,6 +100,7 @@ private:
const Utils::FileName m_sourceDir;
Utils::FileName m_buildDir;
Utils::FileName m_parsedSourceDir;
const ProjectExplorer::Kit *const m_kit;
Utils::Environment m_environment;
CMakeConfig m_inputConfig;
......
......@@ -81,6 +81,16 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(ProjectExplorer::Target *parent
displayName(), BuildConfiguration::Unknown));
}
bool CMakeBuildConfiguration::isEnabled() const
{
return m_error.isEmpty();
}
QString CMakeBuildConfiguration::disabledReason() const
{
return error();
}
CMakeBuildConfiguration::CMakeBuildConfiguration(ProjectExplorer::Target *parent,
CMakeBuildConfiguration *source) :
BuildConfiguration(parent, source),
......@@ -160,6 +170,20 @@ CMakeConfig CMakeBuildConfiguration::cmakeConfiguration() const
return m_configuration;
}
void CMakeBuildConfiguration::setError(const QString &message)
{
if (m_error == message)
return;
m_error = message;
emit enabledChanged();
emit errorOccured(m_error);
}
QString CMakeBuildConfiguration::error() const
{
return m_error;
}
ProjectExplorer::NamedWidget *CMakeBuildConfiguration::createConfigWidget()
{
return new CMakeBuildSettingsWidget(this);
......
......@@ -48,6 +48,9 @@ class CMakeBuildConfiguration : public ProjectExplorer::BuildConfiguration
public:
CMakeBuildConfiguration(ProjectExplorer::Target *parent);
bool isEnabled() const override;
QString disabledReason() const override;
ProjectExplorer::NamedWidget *createConfigWidget() override;
QVariantMap toMap() const override;
......@@ -59,6 +62,12 @@ public:
void setCMakeConfiguration(const CMakeConfig &config);
CMakeConfig cmakeConfiguration() const;
void setError(const QString &message);
QString error() const;
signals:
void errorOccured(const QString &message);
protected:
CMakeBuildConfiguration(ProjectExplorer::Target *parent, CMakeBuildConfiguration *source);
bool fromMap(const QVariantMap &map) override;
......@@ -66,6 +75,7 @@ protected:
private:
QString m_initialArguments;
CMakeConfig m_configuration;
QString m_error;
friend class CMakeProjectManager::CMakeProject;
};
......
......@@ -29,6 +29,7 @@
#include "cmakeproject.h"
#include "cmakebuildconfiguration.h"
#include <coreplugin/coreicons.h>
#include <coreplugin/icore.h>
#include <coreplugin/find/itemviewfind.h>
#include <projectexplorer/projectexplorer.h>
......@@ -94,7 +95,21 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
mainLayout->addWidget(buildDirChooser->buttonAtIndex(0), row, 2);
++row;
mainLayout->addItem(new QSpacerItem(20, 20), row, 0);
mainLayout->addItem(new QSpacerItem(20, 10), row, 0);
++row;
m_errorLabel = new QLabel;
m_errorLabel->setPixmap(Core::Icons::ERROR.pixmap());
m_errorLabel->setVisible(false);
m_errorMessageLabel = new QLabel;
m_errorMessageLabel->setVisible(false);
auto boxLayout = new QHBoxLayout;
boxLayout->addWidget(m_errorLabel);
boxLayout->addWidget(m_errorMessageLabel);
mainLayout->addLayout(boxLayout, row, 0, 1, 3, Qt::AlignHCenter);
++row;
mainLayout->addItem(new QSpacerItem(20, 10), row, 0);
++row;
auto tree = new Utils::TreeView;
......@@ -145,6 +160,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
mainLayout->addWidget(m_reconfigureButton, row, 0, 1, 3);
updateAdvancedCheckBox();
setError(bc->error());
connect(project, &CMakeProject::parsingStarted, this, [this]() {
updateButtonState();
......@@ -180,6 +196,24 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
m_configView->setCurrentIndex(idx);
m_configView->edit(idx);
});
connect(bc, &CMakeBuildConfiguration::errorOccured, this, &CMakeBuildSettingsWidget::setError);
}
void CMakeBuildSettingsWidget::setError(const QString &message)
{
bool showWarning = !message.isEmpty();
m_errorLabel->setVisible(showWarning);
m_errorLabel->setToolTip(message);
m_errorMessageLabel->setVisible(showWarning);
m_errorMessageLabel->setText(message);
m_errorMessageLabel->setToolTip(message);
m_configView->setVisible(!showWarning);
m_editButton->setVisible(!showWarning);
m_resetButton->setVisible(!showWarning);
m_showAdvancedCheckBox->setVisible(!showWarning);
m_reconfigureButton->setVisible(!showWarning);
}
void CMakeBuildSettingsWidget::updateButtonState()
......
......@@ -33,6 +33,7 @@
QT_BEGIN_NAMESPACE
class QCheckBox;
class QLabel;
class QPushButton;
class QTreeView;
class QSortFilterProxyModel;
......@@ -52,6 +53,8 @@ class CMakeBuildSettingsWidget : public ProjectExplorer::NamedWidget
public:
CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc);
void setError(const QString &message);
private:
void updateButtonState();
void updateAdvancedCheckBox();
......@@ -66,6 +69,8 @@ private:
QCheckBox *m_showAdvancedCheckBox;
QPushButton *m_reconfigureButton;
QTimer m_showProgressTimer;
QLabel *m_errorLabel;
QLabel *m_errorMessageLabel;
};
} // namespace Internal
......
......@@ -139,6 +139,8 @@ void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfigur
this, &CMakeProject::parsingStarted);
connect(m_buildDirManager, &BuildDirManager::dataAvailable,
this, &CMakeProject::parseCMakeOutput);
connect(m_buildDirManager, &BuildDirManager::errorOccured,
cmakebc, &CMakeBuildConfiguration::setError);
}
}
......
Markdown is supported
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