Qmake: Improve the build dir location warning

The infamous "build dir is not at the same level at source dir" warning
for qmake projects has gone through a number of iterations in Qt
Creator, having been added, removed and re-added, always to the
criticism of some users. Our new approach is as follows:
    - The warning appears at the widgets where the build directory is
set, both in the target setup page and the build config widget.
    - The warning also appears in the issues pane, but only if the build
failed.
    - The user can disable the warning altogether in a newly introduced
qmake settings page.
    - This option is disabled by default on Unix, because to my
knowledge all failure reports have been for Windows hosts.
This should finally please everybody.

Fixes: QTCREATORBUG-16945
Change-Id: I638be1f15e8c260a5d72047d6850a3a0f685cf03
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Christian Kandeler
2019-03-04 17:29:57 +01:00
parent 8a5a4d4dc7
commit 9686c85a46
11 changed files with 280 additions and 15 deletions

View File

@@ -57,6 +57,7 @@ protected:
~AbstractProcessStep() override; ~AbstractProcessStep() override;
bool init() override; bool init() override;
void doRun() override; void doRun() override;
virtual void finish(bool success);
virtual void processStarted(); virtual void processStarted();
virtual void processFinished(int exitCode, QProcess::ExitStatus status); virtual void processFinished(int exitCode, QProcess::ExitStatus status);
@@ -68,7 +69,6 @@ protected:
void doCancel() override; void doCancel() override;
private: private:
virtual void finish(bool success);
void processReadyReadStdOutput(); void processReadyReadStdOutput();
void processReadyReadStdError(); void processReadyReadStdError();

View File

@@ -31,6 +31,7 @@
#include "qmakeprojectconfigwidget.h" #include "qmakeprojectconfigwidget.h"
#include "qmakeprojectmanagerconstants.h" #include "qmakeprojectmanagerconstants.h"
#include "qmakenodes.h" #include "qmakenodes.h"
#include "qmakesettings.h"
#include "qmakestep.h" #include "qmakestep.h"
#include "qmakemakestep.h" #include "qmakemakestep.h"
#include "makefileparse.h" #include "makefileparse.h"
@@ -293,6 +294,23 @@ void QmakeBuildConfiguration::emitProFileEvaluateNeeded()
static_cast<QmakeProject *>(p)->scheduleAsyncUpdate(); static_cast<QmakeProject *>(p)->scheduleAsyncUpdate();
} }
QString QmakeBuildConfiguration::unalignedBuildDirWarning()
{
return tr("The build directory should be at the same level as the source directory.");
}
bool QmakeBuildConfiguration::isBuildDirAtSafeLocation(const QString &sourceDir,
const QString &buildDir)
{
return buildDir.count('/') == sourceDir.count('/');
}
bool QmakeBuildConfiguration::isBuildDirAtSafeLocation() const
{
return isBuildDirAtSafeLocation(project()->projectDirectory().toString(),
buildDirectory().toString());
}
void QmakeBuildConfiguration::emitQMakeBuildConfigurationChanged() void QmakeBuildConfiguration::emitQMakeBuildConfigurationChanged()
{ {
emit qmakeBuildConfigurationChanged(); emit qmakeBuildConfigurationChanged();
@@ -571,19 +589,11 @@ QmakeBuildConfigurationFactory::QmakeBuildConfigurationFactory()
QList<Task> issues; QList<Task> issues;
if (version) if (version)
issues << version->reportIssues(projectPath, buildDir); issues << version->reportIssues(projectPath, buildDir);
if (QmakeSettings::warnAgainstUnalignedBuildDir()
QString tmpBuildDir = QDir(buildDir).absolutePath(); && !QmakeBuildConfiguration::isBuildDirAtSafeLocation(
const QChar slash = QLatin1Char('/'); QDir(projectPath).absolutePath(), QDir(buildDir).absolutePath())) {
if (!tmpBuildDir.endsWith(slash)) issues.append(Task(Task::Warning, QmakeBuildConfiguration::unalignedBuildDirWarning(),
tmpBuildDir.append(slash); Utils::FileName(), -1,
QString sourcePath = QFileInfo(projectPath).absolutePath();
if (!sourcePath.endsWith(slash))
sourcePath.append(slash);
if (tmpBuildDir.count(slash) != sourcePath.count(slash)) {
const QString msg = QCoreApplication::translate("QmakeProjectManager::QtVersion",
"The build directory needs to be at the same level as the source directory.");
issues.append(Task(Task::Warning, msg, Utils::FileName(), -1,
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)); ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
} }
return issues; return issues;

View File

@@ -101,6 +101,10 @@ public:
void emitProFileEvaluateNeeded(); void emitProFileEvaluateNeeded();
static QString unalignedBuildDirWarning();
static bool isBuildDirAtSafeLocation(const QString &sourceDir, const QString &buildDir);
bool isBuildDirAtSafeLocation() const;
signals: signals:
/// emitted for setQMakeBuildConfig, not emitted for Qt version changes, even /// emitted for setQMakeBuildConfig, not emitted for Qt version changes, even
/// if those change the qmakebuildconfig /// if those change the qmakebuildconfig

View File

@@ -30,6 +30,7 @@
#include "qmakenodes.h" #include "qmakenodes.h"
#include "qmakebuildconfiguration.h" #include "qmakebuildconfiguration.h"
#include "qmakeprojectmanagerconstants.h" #include "qmakeprojectmanagerconstants.h"
#include "qmakesettings.h"
#include <coreplugin/variablechooser.h> #include <coreplugin/variablechooser.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
@@ -38,6 +39,7 @@
#include <projectexplorer/gnumakeparser.h> #include <projectexplorer/gnumakeparser.h>
#include <projectexplorer/processparameters.h> #include <projectexplorer/processparameters.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/kitinformation.h> #include <projectexplorer/kitinformation.h>
#include <projectexplorer/xcodebuildparser.h> #include <projectexplorer/xcodebuildparser.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
@@ -168,6 +170,7 @@ bool QmakeMakeStep::init()
// it has a low priority. // it has a low priority.
m_scriptTarget = (static_cast<QmakeProject *>(bc->target()->project())->rootProjectNode()->projectType() == ProjectType::ScriptTemplate); m_scriptTarget = (static_cast<QmakeProject *>(bc->target()->project())->rootProjectNode()->projectType() == ProjectType::ScriptTemplate);
m_unalignedBuildDir = !bc->isBuildDirAtSafeLocation();
return AbstractProcessStep::init(); return AbstractProcessStep::init();
} }
@@ -190,6 +193,18 @@ void QmakeMakeStep::doRun()
AbstractProcessStep::doRun(); AbstractProcessStep::doRun();
} }
void QmakeMakeStep::finish(bool success)
{
if (!success && !isCanceled() && m_unalignedBuildDir
&& QmakeSettings::warnAgainstUnalignedBuildDir()) {
const QString msg = tr("The build directory is not at the same level as the source "
"directory, which could be the reason for the build failure.");
emit addTask(Task(Task::Warning, msg, Utils::FileName(), -1,
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
}
MakeStep::finish(success);
}
/// ///
// QmakeMakeStepFactory // QmakeMakeStepFactory
/// ///

View File

@@ -54,12 +54,14 @@ public:
QmakeBuildConfiguration *qmakeBuildConfiguration() const; QmakeBuildConfiguration *qmakeBuildConfiguration() const;
private:
void finish(bool success) override;
bool init() override; bool init() override;
void doRun() override; void doRun() override;
private:
bool m_scriptTarget = false; bool m_scriptTarget = false;
QString m_makeFileToCheck; QString m_makeFileToCheck;
bool m_unalignedBuildDir;
}; };
} // QmakeProjectManager } // QmakeProjectManager

View File

@@ -28,6 +28,7 @@
#include "qmakeproject.h" #include "qmakeproject.h"
#include "qmakebuildconfiguration.h" #include "qmakebuildconfiguration.h"
#include "qmakenodes.h" #include "qmakenodes.h"
#include "qmakesettings.h"
#include "ui_qmakeprojectconfigwidget.h" #include "ui_qmakeprojectconfigwidget.h"
#include <coreplugin/coreicons.h> #include <coreplugin/coreicons.h>
@@ -111,6 +112,8 @@ QmakeProjectConfigWidget::QmakeProjectConfigWidget(QmakeBuildConfiguration *bc)
this, &QmakeProjectConfigWidget::updateProblemLabel); this, &QmakeProjectConfigWidget::updateProblemLabel);
connect(project, &Project::parsingFinished, connect(project, &Project::parsingFinished,
this, &QmakeProjectConfigWidget::updateProblemLabel); this, &QmakeProjectConfigWidget::updateProblemLabel);
connect(&QmakeSettings::instance(), &QmakeSettings::settingsChanged,
this, &QmakeProjectConfigWidget::updateProblemLabel);
connect(bc->target(), &Target::kitChanged, this, &QmakeProjectConfigWidget::updateProblemLabel); connect(bc->target(), &Target::kitChanged, this, &QmakeProjectConfigWidget::updateProblemLabel);
@@ -250,6 +253,11 @@ void QmakeProjectConfigWidget::updateProblemLabel()
} }
} }
const bool unalignedBuildDir = QmakeSettings::warnAgainstUnalignedBuildDir()
&& !m_buildConfiguration->isBuildDirAtSafeLocation();
if (unalignedBuildDir)
allGood = false;
if (allGood) { if (allGood) {
QString buildDirectory = m_buildConfiguration->target()->project()->projectDirectory().toString(); QString buildDirectory = m_buildConfiguration->target()->project()->projectDirectory().toString();
if (m_buildConfiguration->isShadowBuild()) if (m_buildConfiguration->isShadowBuild())
@@ -293,6 +301,9 @@ void QmakeProjectConfigWidget::updateProblemLabel()
.arg(errorString) .arg(errorString)
.arg(m_buildConfiguration->buildDirectory().toUserOutput())); .arg(m_buildConfiguration->buildDirectory().toUserOutput()));
return; return;
} else if (unalignedBuildDir) {
setProblemLabel(m_buildConfiguration->unalignedBuildDirWarning());
return;
} }
setProblemLabel(QString()); setProblemLabel(QString());

View File

@@ -12,6 +12,7 @@ HEADERS += \
qmakeprojectmanagerplugin.h \ qmakeprojectmanagerplugin.h \
qmakeprojectmanager.h \ qmakeprojectmanager.h \
qmakeproject.h \ qmakeproject.h \
qmakesettings.h \
qmakenodes.h \ qmakenodes.h \
qmakenodetreebuilder.h \ qmakenodetreebuilder.h \
profileeditor.h \ profileeditor.h \
@@ -52,6 +53,7 @@ SOURCES += \
qmakeprojectmanager.cpp \ qmakeprojectmanager.cpp \
qmakeproject.cpp \ qmakeproject.cpp \
qmakenodes.cpp \ qmakenodes.cpp \
qmakesettings.cpp \
qmakenodetreebuilder.cpp \ qmakenodetreebuilder.cpp \
profileeditor.cpp \ profileeditor.cpp \
profilehighlighter.cpp \ profilehighlighter.cpp \

View File

@@ -41,6 +41,7 @@ Project {
"qmakeparser.cpp", "qmakeparser.h", "qmakeparser.cpp", "qmakeparser.h",
"qmakeparsernodes.cpp", "qmakeparsernodes.h", "qmakeparsernodes.cpp", "qmakeparsernodes.h",
"qmakeprojectimporter.cpp", "qmakeprojectimporter.h", "qmakeprojectimporter.cpp", "qmakeprojectimporter.h",
"qmakesettings.cpp", "qmakesettings.h",
"qmakestep.cpp", "qmakestep.h", "qmakestep.ui", "qmakestep.cpp", "qmakestep.h", "qmakestep.ui",
"qmakebuildconfiguration.cpp", "qmakebuildconfiguration.h", "qmakebuildconfiguration.cpp", "qmakebuildconfiguration.h",
"qmakenodes.cpp", "qmakenodes.h", "qmakenodes.cpp", "qmakenodes.h",

View File

@@ -28,6 +28,7 @@
#include "profileeditor.h" #include "profileeditor.h"
#include "qmakeprojectmanager.h" #include "qmakeprojectmanager.h"
#include "qmakenodes.h" #include "qmakenodes.h"
#include "qmakesettings.h"
#include "qmakestep.h" #include "qmakestep.h"
#include "qmakemakestep.h" #include "qmakemakestep.h"
#include "qmakebuildconfiguration.h" #include "qmakebuildconfiguration.h"
@@ -102,6 +103,8 @@ public:
ProFileEditorFactory profileEditorFactory; ProFileEditorFactory profileEditorFactory;
QmakeSettingsPage settingsPage;
ExternalQtEditor *m_designerEditor{ExternalQtEditor::createDesignerEditor()}; ExternalQtEditor *m_designerEditor{ExternalQtEditor::createDesignerEditor()};
ExternalQtEditor *m_linguistEditor{ExternalQtEditor::createLinguistEditor()}; ExternalQtEditor *m_linguistEditor{ExternalQtEditor::createLinguistEditor()};

View File

@@ -0,0 +1,141 @@
/****************************************************************************
**
** 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 "qmakesettings.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/hostosinfo.h>
#include <QCheckBox>
#include <QCoreApplication>
#include <QVBoxLayout>
namespace QmakeProjectManager {
namespace Internal {
const char BUILD_DIR_WARNING_KEY[] = "QmakeProjectManager/WarnAgainstUnalignedBuildDir";
static bool operator==(const QmakeSettingsData &s1, const QmakeSettingsData &s2)
{
return s1.warnAgainstUnalignedBuildDir == s2.warnAgainstUnalignedBuildDir;
}
static bool operator!=(const QmakeSettingsData &s1, const QmakeSettingsData &s2)
{
return !(s1 == s2);
}
bool QmakeSettings::warnAgainstUnalignedBuildDir()
{
return instance().m_settings.warnAgainstUnalignedBuildDir;
}
QmakeSettings &QmakeSettings::instance()
{
static QmakeSettings theSettings;
return theSettings;
}
void QmakeSettings::setSettingsData(const QmakeSettingsData &settings)
{
if (instance().m_settings != settings) {
instance().m_settings = settings;
instance().storeSettings();
emit instance().settingsChanged();
}
}
QmakeSettings::QmakeSettings()
{
loadSettings();
}
void QmakeSettings::loadSettings()
{
m_settings.warnAgainstUnalignedBuildDir = Core::ICore::settings()->value(
BUILD_DIR_WARNING_KEY, Utils::HostOsInfo::isWindowsHost()).toBool();
}
void QmakeSettings::storeSettings() const
{
Core::ICore::settings()->setValue(BUILD_DIR_WARNING_KEY, warnAgainstUnalignedBuildDir());
}
class QmakeSettingsPage::SettingsWidget : public QWidget
{
Q_DECLARE_TR_FUNCTIONS(QmakeProjectManager::Internal::QmakeSettingsPage)
public:
SettingsWidget()
{
m_warnAgainstUnalignedBuildDirCheckbox.setText(tr("Warn if a project's source and "
"build directories are not at the same level"));
m_warnAgainstUnalignedBuildDirCheckbox.setToolTip(tr("Qmake has subtle bugs that "
"can trigger if source and build directory are not at the same level."));
m_warnAgainstUnalignedBuildDirCheckbox.setChecked(
QmakeSettings::warnAgainstUnalignedBuildDir());
const auto layout = new QVBoxLayout(this);
layout->addWidget(&m_warnAgainstUnalignedBuildDirCheckbox);
layout->addStretch(1);
}
void apply()
{
QmakeSettingsData settings;
settings.warnAgainstUnalignedBuildDir = m_warnAgainstUnalignedBuildDirCheckbox.isChecked();
QmakeSettings::setSettingsData(settings);
}
private:
QCheckBox m_warnAgainstUnalignedBuildDirCheckbox;
};
QmakeSettingsPage::QmakeSettingsPage()
{
setId("K.QmakeProjectManager.QmakeSettings");
setDisplayName(tr("Qmake"));
setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY);
}
QWidget *QmakeSettingsPage::widget()
{
if (!m_widget)
m_widget = new SettingsWidget;
return m_widget;
}
void QmakeSettingsPage::apply()
{
if (m_widget)
m_widget->apply();
}
void QmakeSettingsPage::finish()
{
delete m_widget;
}
} // namespace Internal
} // namespace QmakeProjectManager

View File

@@ -0,0 +1,76 @@
/****************************************************************************
**
** 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 <coreplugin/dialogs/ioptionspage.h>
#include <QObject>
#include <QPointer>
namespace QmakeProjectManager {
namespace Internal {
class QmakeSettingsData {
public:
bool warnAgainstUnalignedBuildDir = false;
};
class QmakeSettings : public QObject
{
Q_OBJECT
public:
static QmakeSettings &instance();
static bool warnAgainstUnalignedBuildDir();
static void setSettingsData(const QmakeSettingsData &settings);
signals:
void settingsChanged();
private:
QmakeSettings();
void loadSettings();
void storeSettings() const;
QmakeSettingsData m_settings;
};
class QmakeSettingsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
QmakeSettingsPage();
private:
QWidget *widget() override;
void apply() override;
void finish() override;
class SettingsWidget;
QPointer<SettingsWidget> m_widget;
};
} // namespace Internal
} // namespace QmakeProjectManager