Convert macros from plain QByteArray to a vector of structs

The old code model expected the macros as C++ formatted text
("#define Foo 42) but newer targets like the Clang codemodel expect key
value arguments like "-DFoo=42". So instead of parsing the text again and
again we use an abstract data description.

Task-number: QTCREATORBUG-17915
Change-Id: I0179fd13c48a581e91ee79bba9d42d501c26f19f
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Marco Bubke
2017-02-07 15:00:38 +01:00
parent 3adb71d45e
commit b6e12f4a1c
60 changed files with 1144 additions and 420 deletions

View File

@@ -30,6 +30,7 @@
#include <utils/fileutils.h>
#include <utils/stringutils.h>
#include <utils/algorithm.h>
#include <projectexplorer/projectmacro.h>
#include <projectexplorer/projectnodes.h>
#include <QLoggingCategory>
@@ -71,8 +72,9 @@ void CMakeCbpParser::sortFiles()
qCDebug(log) << "# Pre Dump #";
qCDebug(log) << "###############";
foreach (const CMakeBuildTarget &target, m_buildTargets)
qCDebug(log) << target.title << target.sourceDirectory <<
target.includeFiles << target.defines << target.files << "\n";
qCDebug(log) << target.title << target.sourceDirectory << target.includeFiles
<< ProjectExplorer::Macro::toByteArray(target.macros)
<< target.files << "\n";
// find a good build target to fall back
int fallbackIndex = 0;
@@ -153,7 +155,9 @@ void CMakeCbpParser::sortFiles()
qCDebug(log) << "# After Dump #";
qCDebug(log) << "###############";
foreach (const CMakeBuildTarget &target, m_buildTargets)
qCDebug(log) << target.title << target.sourceDirectory << target.includeFiles << target.defines << target.files << "\n";
qCDebug(log) << target.title << target.sourceDirectory << target.includeFiles
<< ProjectExplorer::Macro::toByteArray(target.macros)
<< target.files << "\n";
}
bool CMakeCbpParser::parseCbpFile(CMakeTool::PathMapper mapper, const FileName &fileName,
@@ -397,12 +401,8 @@ void CMakeCbpParser::parseAdd()
m_buildTarget.compilerOptions.append(compilerOption);
int macroNameIndex = compilerOption.indexOf("-D") + 2;
if (macroNameIndex != 1) {
int assignIndex = compilerOption.indexOf('=', macroNameIndex);
if (assignIndex != -1)
compilerOption[assignIndex] = ' ';
m_buildTarget.defines.append("#define ");
m_buildTarget.defines.append(compilerOption.mid(macroNameIndex).toUtf8());
m_buildTarget.defines.append('\n');
const QString keyValue = compilerOption.mid(macroNameIndex);
m_buildTarget.macros.append(ProjectExplorer::Macro::fromKeyValue(keyValue));
}
}

View File

@@ -559,7 +559,7 @@ void CMakeBuildTarget::clear()
targetType = UtilityType;
includeFiles.clear();
compilerOptions.clear();
defines.clear();
macros.clear();
files.clear();
}

View File

@@ -30,6 +30,7 @@
#include "treescanner.h"
#include <projectexplorer/extracompiler.h>
#include <projectexplorer/projectmacro.h>
#include <projectexplorer/project.h>
#include <utils/fileutils.h>
@@ -72,7 +73,7 @@ public:
// code model
QList<Utils::FileName> includeFiles;
QStringList compilerOptions;
QByteArray defines;
ProjectExplorer::Macros macros;
QList<Utils::FileName> files;
void clear();

View File

@@ -45,6 +45,8 @@
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <QVector>
using namespace ProjectExplorer;
using namespace Utils;
@@ -325,14 +327,6 @@ void ServerModeReader::updateCodeModel(CppTools::RawProjectParts &rpps)
int counter = 0;
for (const FileGroup *fg : Utils::asConst(m_fileGroups)) {
++counter;
const QString defineArg
= transform(fg->defines, [](const QString &s) -> QString {
QString result = QString::fromLatin1("#define ") + s;
int assignIndex = result.indexOf('=');
if (assignIndex != -1)
result[assignIndex] = ' ';
return result;
}).join('\n');
const QStringList flags = QtcProcess::splitArgs(fg->compileFlags);
const QStringList includes = transform(fg->includePaths, [](const IncludePath *ip) { return ip->path.toString(); });
@@ -340,7 +334,7 @@ void ServerModeReader::updateCodeModel(CppTools::RawProjectParts &rpps)
rpp.setProjectFileLocation(fg->target->sourceDirectory.toString() + "/CMakeLists.txt");
rpp.setBuildSystemTarget(fg->target->name);
rpp.setDisplayName(fg->target->name + QString::number(counter));
rpp.setDefines(defineArg.toUtf8());
rpp.setMacros(fg->macros);
rpp.setIncludePaths(includes);
CppTools::RawProjectPartFlags cProjectFlags;
@@ -523,7 +517,9 @@ ServerModeReader::FileGroup *ServerModeReader::extractFileGroupData(const QVaria
auto fileGroup = new FileGroup;
fileGroup->target = t;
fileGroup->compileFlags = data.value("compileFlags").toString();
fileGroup->defines = data.value("defines").toStringList();
fileGroup->macros = Utils::transform<QVector>(data.value("defines").toStringList(), [](const QString &s) {
return ProjectExplorer::Macro::fromKeyValue(s);
});
fileGroup->includePaths = transform(data.value("includePath").toList(),
[](const QVariant &i) -> IncludePath* {
const QVariantMap iData = i.toMap();
@@ -662,7 +658,7 @@ void ServerModeReader::fixTarget(ServerModeReader::Target *target) const
for (const FileGroup *group : Utils::asConst(target->fileGroups)) {
if (group->includePaths.isEmpty() && group->compileFlags.isEmpty()
&& group->defines.isEmpty())
&& group->macros.isEmpty())
continue;
const FileGroup *fallback = languageFallbacks.value(group->language);
@@ -688,13 +684,13 @@ void ServerModeReader::fixTarget(ServerModeReader::Target *target) const
(*it)->language = fallback->language.isEmpty() ? "CXX" : fallback->language;
if (*it == fallback
|| !(*it)->includePaths.isEmpty() || !(*it)->defines.isEmpty()
|| !(*it)->includePaths.isEmpty() || !(*it)->macros.isEmpty()
|| !(*it)->compileFlags.isEmpty())
continue;
for (const IncludePath *ip : fallback->includePaths)
(*it)->includePaths.append(new IncludePath(*ip));
(*it)->defines = fallback->defines;
(*it)->macros = fallback->macros;
(*it)->compileFlags = fallback->compileFlags;
}
}

View File

@@ -86,7 +86,7 @@ private:
Target *target = nullptr;
QString compileFlags;
QStringList defines;
ProjectExplorer::Macros macros;
QList<IncludePath *> includePaths;
QString language;
QList<Utils::FileName> sources;

View File

@@ -384,7 +384,7 @@ void TeaLeafReader::updateCodeModel(CppTools::RawProjectParts &rpps)
cxxProjectFlags.commandLineFlags = cxxflags;
rpp.setFlagsForCxx(cxxProjectFlags);
rpp.setDefines(cbt.defines);
rpp.setMacros(cbt.macros);
rpp.setDisplayName(cbt.title);
rpp.setFiles(transform(cbt.files, [](const FileName &fn) { return fn.toString(); }));