Qmake: Warn when project uses unexpected compiler(s) to build

Change-Id: I28b45b2f994ce2dd030f5dae2ab78ecb0b547b1f
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Tobias Hunger
2016-09-23 15:53:31 +02:00
parent d5785d1c25
commit 8f73b24e87
4 changed files with 60 additions and 1 deletions

View File

@@ -2026,6 +2026,8 @@ EvalResult *QmakeProFileNode::evaluate(const EvalInput &input)
result->newVarValues[AndroidExtraLibs] = input.readerExact->values(QLatin1String("ANDROID_EXTRA_LIBS"));
result->newVarValues[IsoIconsVar] = input.readerExact->values(QLatin1String("ISO_ICONS"));
result->newVarValues[QmakeProjectName] = input.readerExact->values(QLatin1String("QMAKE_PROJECT_NAME"));
result->newVarValues[QmakeCc] = input.readerExact->values("QMAKE_CC");
result->newVarValues[QmakeCxx] = input.readerExact->values("QMAKE_CXX");
result->isDeployable = false;
if (result->projectType == ApplicationTemplate) {

View File

@@ -107,7 +107,9 @@ enum QmakeVariable {
AndroidPackageSourceDir,
AndroidExtraLibs,
IsoIconsVar,
QmakeProjectName
QmakeProjectName,
QmakeCc,
QmakeCxx
};
namespace Internal {

View File

@@ -49,6 +49,7 @@
#include <projectexplorer/toolchain.h>
#include <projectexplorer/headerpath.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
#include <projectexplorer/projectexplorer.h>
#include <proparser/qmakevfs.h>
#include <qtsupport/profilereader.h>
@@ -393,6 +394,8 @@ void QmakeProject::updateCodeModels()
void QmakeProject::updateCppCodeModel()
{
m_toolChainWarnings.clear();
typedef CppTools::ProjectPart ProjectPart;
typedef CppTools::ProjectFile ProjectFile;
@@ -420,6 +423,8 @@ void QmakeProject::updateCppCodeModel()
QList<ProjectExplorer::ExtraCompiler *> generators;
QStringList allFiles;
foreach (QmakeProFileNode *pro, proFiles) {
warnOnToolChainMismatch(pro);
ProjectPart::Ptr templatePart(new ProjectPart);
templatePart->project = this;
templatePart->displayName = pro->displayName();
@@ -1532,6 +1537,51 @@ bool QmakeProject::matchesKit(const Kit *kit)
return false;
}
static Utils::FileName getFullPathOf(const QString &exe, const BuildConfiguration *bc)
{
QTC_ASSERT(bc, return Utils::FileName::fromString(exe));
QFileInfo fi(exe);
if (fi.isAbsolute())
return Utils::FileName::fromString(exe);
return bc->environment().searchInPath(exe);
}
void QmakeProject::testToolChain(ToolChain *tc, const Utils::FileName &path) const
{
if (!tc || path.isEmpty())
return;
const Utils::FileName expected = tc->compilerCommand();
if (expected != path) {
const QPair<Utils::FileName, Utils::FileName> pair = qMakePair(expected, path);
if (!m_toolChainWarnings.contains(pair)) {
TaskHub::addTask(Task(Task::Warning,
QCoreApplication::translate("QmakeProjectManager", "\"%1\" is used by qmake, but \"%2\" is configured in the kit.\n"
"Please update your kit or choose a mkspec for qmake that matches your target environment better.").
arg(path.toUserOutput()).arg(expected.toUserOutput()),
Utils::FileName(), -1, ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
m_toolChainWarnings.insert(pair);
}
}
}
void QmakeProject::warnOnToolChainMismatch(const QmakeProFileNode *pro) const
{
Target *t = activeTarget();
if (!t)
return;
const BuildConfiguration *bc = t ? t->activeBuildConfiguration() : nullptr;
if (!bc)
return;
testToolChain(ToolChainKitInformation::toolChain(t->kit(), ToolChain::Language::C),
getFullPathOf(pro->singleVariableValue(QmakeCc), bc));
testToolChain(ToolChainKitInformation::toolChain(t->kit(), ToolChain::Language::Cxx),
getFullPathOf(pro->singleVariableValue(QmakeCxx), bc));
}
QString QmakeProject::executableFor(const QmakeProFileNode *node)
{
const Kit * const kit = activeTarget()->kit();

View File

@@ -173,6 +173,11 @@ private:
void startAsyncTimer(QmakeProFileNode::AsyncUpdateDelay delay);
bool matchesKit(const ProjectExplorer::Kit *kit);
void warnOnToolChainMismatch(const QmakeProFileNode *pro) const;
void testToolChain(ProjectExplorer::ToolChain *tc, const Utils::FileName &path) const;
mutable QSet<const QPair<Utils::FileName, Utils::FileName>> m_toolChainWarnings;
// Current configuration
QString m_oldQtIncludePath;
QString m_oldQtLibsPath;