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

@@ -31,6 +31,7 @@
#include "qmakeprojectconfigwidget.h"
#include "qmakeprojectmanagerconstants.h"
#include "qmakenodes.h"
#include "qmakesettings.h"
#include "qmakestep.h"
#include "qmakemakestep.h"
#include "makefileparse.h"
@@ -293,6 +294,23 @@ void QmakeBuildConfiguration::emitProFileEvaluateNeeded()
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()
{
emit qmakeBuildConfigurationChanged();
@@ -571,19 +589,11 @@ QmakeBuildConfigurationFactory::QmakeBuildConfigurationFactory()
QList<Task> issues;
if (version)
issues << version->reportIssues(projectPath, buildDir);
QString tmpBuildDir = QDir(buildDir).absolutePath();
const QChar slash = QLatin1Char('/');
if (!tmpBuildDir.endsWith(slash))
tmpBuildDir.append(slash);
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,
if (QmakeSettings::warnAgainstUnalignedBuildDir()
&& !QmakeBuildConfiguration::isBuildDirAtSafeLocation(
QDir(projectPath).absolutePath(), QDir(buildDir).absolutePath())) {
issues.append(Task(Task::Warning, QmakeBuildConfiguration::unalignedBuildDirWarning(),
Utils::FileName(), -1,
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
}
return issues;