Commit b6e12f4a authored by Marco Bubke's avatar Marco Bubke

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's avatarTobias Hunger <tobias.hunger@qt.io>
parent 3adb71d4
...@@ -86,7 +86,7 @@ static bool qtTestLibDefined(const QString &fileName) ...@@ -86,7 +86,7 @@ static bool qtTestLibDefined(const QString &fileName)
const QList<CppTools::ProjectPart::Ptr> parts = const QList<CppTools::ProjectPart::Ptr> parts =
CppTools::CppModelManager::instance()->projectPart(fileName); CppTools::CppModelManager::instance()->projectPart(fileName);
if (parts.size() > 0) if (parts.size() > 0)
return parts.at(0)->projectDefines.contains("#define QT_TESTLIB_LIB"); return parts.at(0)->projectMacros.contains({"QT_TESTLIB_LIB"});
return false; return false;
} }
......
...@@ -89,20 +89,21 @@ static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc, ...@@ -89,20 +89,21 @@ static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc,
static QString quickTestSrcDir(const CppTools::CppModelManager *cppMM, static QString quickTestSrcDir(const CppTools::CppModelManager *cppMM,
const QString &fileName) const QString &fileName)
{ {
static const QByteArray qtsd(" QUICK_TEST_SOURCE_DIR ");
const QList<CppTools::ProjectPart::Ptr> parts = cppMM->projectPart(fileName); const QList<CppTools::ProjectPart::Ptr> parts = cppMM->projectPart(fileName);
if (parts.size() > 0) { if (parts.size() > 0) {
QByteArray projDefines(parts.at(0)->projectDefines); const ProjectExplorer::Macros &macros = parts.at(0)->projectMacros;
for (const QByteArray &line : projDefines.split('\n')) { auto found = std::find_if(
if (line.contains(qtsd)) { macros.begin(),
QByteArray result = line.mid(line.indexOf(qtsd) + qtsd.length()); macros.end(),
if (result.startsWith('"')) [] (const ProjectExplorer::Macro &macro) { return macro.key == "QUICK_TEST_SOURCE_DIR"; });
result.remove(result.length() - 1, 1).remove(0, 1); if (found != macros.end()) {
if (result.startsWith("\\\"")) QByteArray result = found->value;
result.remove(result.length() - 2, 2).remove(0, 2); if (result.startsWith('"'))
return QLatin1String(result); result.remove(result.length() - 1, 1).remove(0, 1);
} if (result.startsWith("\\\""))
} result.remove(result.length() - 2, 2).remove(0, 2);
return QLatin1String(result);
}
} }
return QString(); return QString();
} }
......
...@@ -298,7 +298,7 @@ void AutotoolsProject::updateCppCodeModel() ...@@ -298,7 +298,7 @@ void AutotoolsProject::updateCppCodeModel()
? target->activeBuildConfiguration()->buildDirectory().toString() : QString(); ? target->activeBuildConfiguration()->buildDirectory().toString() : QString();
rpp.setIncludePaths(filterIncludes(absSrc, absBuild, m_makefileParserThread->includePaths())); rpp.setIncludePaths(filterIncludes(absSrc, absBuild, m_makefileParserThread->includePaths()));
rpp.setDefines(m_makefileParserThread->defines()); rpp.setMacros(m_makefileParserThread->macros());
rpp.setFiles(m_files); rpp.setFiles(m_files);
m_cppCodeModelUpdater->update({this, cToolChain, cxxToolChain, k, {rpp}}); m_cppCodeModelUpdater->update({this, cToolChain, cxxToolChain, k, {rpp}});
......
...@@ -108,9 +108,9 @@ QStringList MakefileParser::includePaths() const ...@@ -108,9 +108,9 @@ QStringList MakefileParser::includePaths() const
return m_includePaths; return m_includePaths;
} }
QByteArray MakefileParser::defines() const ProjectExplorer::Macros MakefileParser::macros() const
{ {
return m_defines; return m_macros;
} }
QStringList MakefileParser::cflags() const QStringList MakefileParser::cflags() const
...@@ -449,11 +449,7 @@ bool MakefileParser::maybeParseDefine(const QString &term) ...@@ -449,11 +449,7 @@ bool MakefileParser::maybeParseDefine(const QString &term)
{ {
if (term.startsWith(QLatin1String("-D"))) { if (term.startsWith(QLatin1String("-D"))) {
QString def = term.mid(2); // remove the "-D" QString def = term.mid(2); // remove the "-D"
QByteArray data = def.toUtf8(); m_macros += ProjectExplorer::Macro::fromKeyValue(def);
int pos = data.indexOf('=');
if (pos >= 0)
data[pos] = ' ';
m_defines += (QByteArray("#define ") + data + '\n');
return true; return true;
} }
return false; return false;
......
...@@ -27,10 +27,13 @@ ...@@ -27,10 +27,13 @@
#pragma once #pragma once
#include <projectexplorer/projectmacro.h>
#include <QMutex> #include <QMutex>
#include <QStringList> #include <QStringList>
#include <QTextStream> #include <QTextStream>
#include <QObject> #include <QObject>
#include <QVector>
QT_FORWARD_DECLARE_CLASS(QDir) QT_FORWARD_DECLARE_CLASS(QDir)
...@@ -49,6 +52,8 @@ class MakefileParser : public QObject ...@@ -49,6 +52,8 @@ class MakefileParser : public QObject
{ {
Q_OBJECT Q_OBJECT
using Macros = ProjectExplorer::Macros;
public: public:
/** /**
* @param makefile Filename including path of the autotools * @param makefile Filename including path of the autotools
...@@ -98,7 +103,7 @@ public: ...@@ -98,7 +103,7 @@ public:
* #define X12_HAS_DEPRECATED * #define X12_HAS_DEPRECATED
* @endcode * @endcode
*/ */
QByteArray defines() const; Macros macros() const;
/** /**
* @return List of compiler flags for C. * @return List of compiler flags for C.
...@@ -267,7 +272,7 @@ private: ...@@ -267,7 +272,7 @@ private:
QStringList m_sources; ///< Return value for MakefileParser::sources() QStringList m_sources; ///< Return value for MakefileParser::sources()
QStringList m_makefiles; ///< Return value for MakefileParser::makefiles() QStringList m_makefiles; ///< Return value for MakefileParser::makefiles()
QStringList m_includePaths; ///< Return value for MakefileParser::includePaths() QStringList m_includePaths; ///< Return value for MakefileParser::includePaths()
QByteArray m_defines; ///< Return value for MakefileParser::defines() Macros m_macros; ///< Return value for MakefileParser::macros()
QStringList m_cflags; ///< Return value for MakefileParser::cflags() QStringList m_cflags; ///< Return value for MakefileParser::cflags()
QStringList m_cxxflags; ///< Return value for MakefileParser::cxxflags() QStringList m_cxxflags; ///< Return value for MakefileParser::cxxflags()
QStringList m_cppflags; ///< The cpp flags, which will be part of both cflags and cxxflags QStringList m_cppflags; ///< The cpp flags, which will be part of both cflags and cxxflags
......
...@@ -61,10 +61,10 @@ QStringList MakefileParserThread::includePaths() const ...@@ -61,10 +61,10 @@ QStringList MakefileParserThread::includePaths() const
return m_includePaths; return m_includePaths;
} }
QByteArray MakefileParserThread::defines() const ProjectExplorer::Macros MakefileParserThread::macros() const
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
return m_defines; return m_macros;
} }
QStringList MakefileParserThread::cflags() const QStringList MakefileParserThread::cflags() const
...@@ -109,7 +109,7 @@ void MakefileParserThread::run() ...@@ -109,7 +109,7 @@ void MakefileParserThread::run()
m_sources = m_parser.sources(); m_sources = m_parser.sources();
m_makefiles = m_parser.makefiles(); m_makefiles = m_parser.makefiles();
m_includePaths = m_parser.includePaths(); m_includePaths = m_parser.includePaths();
m_defines = m_parser.defines(); m_macros = m_parser.macros();
m_cflags = m_parser.cflags(); m_cflags = m_parser.cflags();
m_cxxflags = m_parser.cxxflags(); m_cxxflags = m_parser.cxxflags();
} }
...@@ -29,9 +29,12 @@ ...@@ -29,9 +29,12 @@
#include "makefileparser.h" #include "makefileparser.h"
#include <projectexplorer/projectmacro.h>
#include <QMutex> #include <QMutex>
#include <QStringList> #include <QStringList>
#include <QThread> #include <QThread>
#include <QVector>
namespace AutotoolsProjectManager { namespace AutotoolsProjectManager {
namespace Internal { namespace Internal {
...@@ -47,6 +50,8 @@ class MakefileParserThread : public QThread ...@@ -47,6 +50,8 @@ class MakefileParserThread : public QThread
{ {
Q_OBJECT Q_OBJECT
using Macros = ProjectExplorer::Macros;
public: public:
MakefileParserThread(const QString &makefile); MakefileParserThread(const QString &makefile);
...@@ -82,10 +87,10 @@ public: ...@@ -82,10 +87,10 @@ public:
QStringList includePaths() const; QStringList includePaths() const;
/** /**
* @return Concatenated defines. Should be invoked, after the signal * @return Concatenated macros. Should be invoked, after the signal
* finished() has been emitted. * finished() has been emitted.
*/ */
QByteArray defines() const; Macros macros() const;
/** /**
* @return List of compiler flags for C. Should be invoked, after the signal * @return List of compiler flags for C. Should be invoked, after the signal
...@@ -134,7 +139,7 @@ private: ...@@ -134,7 +139,7 @@ private:
QStringList m_sources; ///< Return value for MakefileParserThread::sources() QStringList m_sources; ///< Return value for MakefileParserThread::sources()
QStringList m_makefiles; ///< Return value for MakefileParserThread::makefiles() QStringList m_makefiles; ///< Return value for MakefileParserThread::makefiles()
QStringList m_includePaths; ///< Return value for MakefileParserThread::includePaths() QStringList m_includePaths; ///< Return value for MakefileParserThread::includePaths()
QByteArray m_defines; ///< Return value for MakefileParserThread::defines() Macros m_macros; ///< Return value for MakefileParserThread::macros()
QStringList m_cflags; ///< Return value for MakefileParserThread::cflags() QStringList m_cflags; ///< Return value for MakefileParserThread::cflags()
QStringList m_cxxflags; ///< Return value for MakefileParserThread::cxxflags() QStringList m_cxxflags; ///< Return value for MakefileParserThread::cxxflags()
}; };
......
...@@ -512,7 +512,7 @@ bool OpenEditorAtCursorPosition::waitUntil(const std::function<bool ()> &conditi ...@@ -512,7 +512,7 @@ bool OpenEditorAtCursorPosition::waitUntil(const std::function<bool ()> &conditi
} }
CppTools::ProjectPart::Ptr createProjectPart(const QStringList &files, CppTools::ProjectPart::Ptr createProjectPart(const QStringList &files,
const QString &defines) const ProjectExplorer::Macros &macros)
{ {
using namespace CppTools; using namespace CppTools;
...@@ -521,19 +521,19 @@ CppTools::ProjectPart::Ptr createProjectPart(const QStringList &files, ...@@ -521,19 +521,19 @@ CppTools::ProjectPart::Ptr createProjectPart(const QStringList &files,
foreach (const QString &file, files) foreach (const QString &file, files)
projectPart->files.append(ProjectFile(file, ProjectFile::classify(file))); projectPart->files.append(ProjectFile(file, ProjectFile::classify(file)));
projectPart->qtVersion = ProjectPart::NoQt; projectPart->qtVersion = ProjectPart::NoQt;
projectPart->projectDefines = defines.toUtf8(); projectPart->projectMacros = macros;
return projectPart; return projectPart;
} }
CppTools::ProjectInfo createProjectInfo(ProjectExplorer::Project *project, CppTools::ProjectInfo createProjectInfo(ProjectExplorer::Project *project,
const QStringList &files, const QStringList &files,
const QString &defines) const ProjectExplorer::Macros &macros)
{ {
using namespace CppTools; using namespace CppTools;
QTC_ASSERT(project, return ProjectInfo()); QTC_ASSERT(project, return ProjectInfo());
const CppTools::ProjectPart::Ptr projectPart = createProjectPart(files, defines); const CppTools::ProjectPart::Ptr projectPart = createProjectPart(files, macros);
ProjectInfo projectInfo = ProjectInfo(project); ProjectInfo projectInfo = ProjectInfo(project);
projectInfo.appendProjectPart(projectPart); projectInfo.appendProjectPart(projectPart);
return projectInfo; return projectInfo;
...@@ -543,11 +543,11 @@ class ProjectLoader ...@@ -543,11 +543,11 @@ class ProjectLoader
{ {
public: public:
ProjectLoader(const QStringList &projectFiles, ProjectLoader(const QStringList &projectFiles,
const QString &projectDefines, const ProjectExplorer::Macros &projectMacros,
bool testOnlyForCleanedProjects = false) bool testOnlyForCleanedProjects = false)
: m_project(0) : m_project(0)
, m_projectFiles(projectFiles) , m_projectFiles(projectFiles)
, m_projectDefines(projectDefines) , m_projectMacros(projectMacros)
, m_helper(0, testOnlyForCleanedProjects) , m_helper(0, testOnlyForCleanedProjects)
{ {
} }
...@@ -557,17 +557,17 @@ public: ...@@ -557,17 +557,17 @@ public:
m_project = m_helper.createProject(QLatin1String("testProject")); m_project = m_helper.createProject(QLatin1String("testProject"));
const CppTools::ProjectInfo projectInfo = createProjectInfo(m_project, const CppTools::ProjectInfo projectInfo = createProjectInfo(m_project,
m_projectFiles, m_projectFiles,
m_projectDefines); m_projectMacros);
const QSet<QString> filesIndexedAfterLoading = m_helper.updateProjectInfo(projectInfo); const QSet<QString> filesIndexedAfterLoading = m_helper.updateProjectInfo(projectInfo);
return m_projectFiles.size() == filesIndexedAfterLoading.size(); return m_projectFiles.size() == filesIndexedAfterLoading.size();
} }
bool updateProject(const QString &updatedProjectDefines) bool updateProject(const ProjectExplorer::Macros &updatedProjectMacros)
{ {
QTC_ASSERT(m_project, return false); QTC_ASSERT(m_project, return false);
const CppTools::ProjectInfo updatedProjectInfo = createProjectInfo(m_project, const CppTools::ProjectInfo updatedProjectInfo = createProjectInfo(m_project,
m_projectFiles, m_projectFiles,
updatedProjectDefines); updatedProjectMacros);
return updateProjectInfo(updatedProjectInfo); return updateProjectInfo(updatedProjectInfo);
} }
...@@ -581,7 +581,7 @@ private: ...@@ -581,7 +581,7 @@ private:
ProjectExplorer::Project *m_project; ProjectExplorer::Project *m_project;
QStringList m_projectFiles; QStringList m_projectFiles;
QString m_projectDefines; ProjectExplorer::Macros m_projectMacros;
CppTools::Tests::ModelManagerTestHelper m_helper; CppTools::Tests::ModelManagerTestHelper m_helper;
}; };
...@@ -865,8 +865,7 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCode() ...@@ -865,8 +865,7 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCode()
const TestDocument testDocument("completionWithProject.cpp"); const TestDocument testDocument("completionWithProject.cpp");
QVERIFY(testDocument.isCreatedAndHasValidCursorPosition()); QVERIFY(testDocument.isCreatedAndHasValidCursorPosition());
ProjectLoader projectLoader(QStringList(testDocument.filePath), ProjectLoader projectLoader(QStringList(testDocument.filePath), {{"PROJECT_CONFIGURATION_1"}});
_("#define PROJECT_CONFIGURATION_1\n"));
QVERIFY(projectLoader.load()); QVERIFY(projectLoader.load());
OpenEditorAtCursorPosition openEditor(testDocument); OpenEditorAtCursorPosition openEditor(testDocument);
...@@ -891,7 +890,7 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeAfterChangingProje ...@@ -891,7 +890,7 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeAfterChangingProje
{ {
// Check completion with project configuration 1 // Check completion with project configuration 1
ProjectLoader projectLoader(QStringList(testDocument.filePath), ProjectLoader projectLoader(QStringList(testDocument.filePath),
_("#define PROJECT_CONFIGURATION_1\n"), {{"PROJECT_CONFIGURATION_1"}},
/* testOnlyForCleanedProjects= */ true); /* testOnlyForCleanedProjects= */ true);
QVERIFY(projectLoader.load()); QVERIFY(projectLoader.load());
openEditor.waitUntilProjectPartChanged(QLatin1String("myproject.project")); openEditor.waitUntilProjectPartChanged(QLatin1String("myproject.project"));
...@@ -902,7 +901,7 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeAfterChangingProje ...@@ -902,7 +901,7 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeAfterChangingProje
QVERIFY(!hasItem(proposal, "projectConfiguration2")); QVERIFY(!hasItem(proposal, "projectConfiguration2"));
// Check completion with project configuration 2 // Check completion with project configuration 2
QVERIFY(projectLoader.updateProject(_("#define PROJECT_CONFIGURATION_2\n"))); QVERIFY(projectLoader.updateProject({{"PROJECT_CONFIGURATION_2"}}));
proposal = completionResults(openEditor.editor()); proposal = completionResults(openEditor.editor());
QVERIFY(!hasItem(proposal, "projectConfiguration1")); QVERIFY(!hasItem(proposal, "projectConfiguration1"));
......
...@@ -224,8 +224,8 @@ public: ...@@ -224,8 +224,8 @@ public:
optionsBuilder.addDefineToAvoidIncludingGccOrMinGwIntrinsics(); optionsBuilder.addDefineToAvoidIncludingGccOrMinGwIntrinsics();
const Core::Id type = projectPart.toolchainType; const Core::Id type = projectPart.toolchainType;
if (type != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) if (type != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
optionsBuilder.addDefines(projectPart.toolchainDefines); optionsBuilder.addMacros(projectPart.toolChainMacros);
optionsBuilder.addDefines(projectPart.projectDefines); optionsBuilder.addMacros(projectPart.projectMacros);
optionsBuilder.undefineClangVersionMacrosForMsvc(); optionsBuilder.undefineClangVersionMacrosForMsvc();
optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015(); optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
optionsBuilder.addHeaderPathOptions(); optionsBuilder.addHeaderPathOptions();
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <projectexplorer/projectmacro.h>
#include <projectexplorer/projectnodes.h> #include <projectexplorer/projectnodes.h>
#include <QLoggingCategory> #include <QLoggingCategory>
...@@ -71,8 +72,9 @@ void CMakeCbpParser::sortFiles() ...@@ -71,8 +72,9 @@ void CMakeCbpParser::sortFiles()
qCDebug(log) << "# Pre Dump #"; qCDebug(log) << "# Pre Dump #";
qCDebug(log) << "###############"; qCDebug(log) << "###############";
foreach (const CMakeBuildTarget &target, m_buildTargets) foreach (const CMakeBuildTarget &target, m_buildTargets)
qCDebug(log) << target.title << target.sourceDirectory << qCDebug(log) << target.title << target.sourceDirectory << target.includeFiles
target.includeFiles << target.defines << target.files << "\n"; << ProjectExplorer::Macro::toByteArray(target.macros)
<< target.files << "\n";
// find a good build target to fall back // find a good build target to fall back
int fallbackIndex = 0; int fallbackIndex = 0;
...@@ -153,7 +155,9 @@ void CMakeCbpParser::sortFiles() ...@@ -153,7 +155,9 @@ void CMakeCbpParser::sortFiles()
qCDebug(log) << "# After Dump #"; qCDebug(log) << "# After Dump #";
qCDebug(log) << "###############"; qCDebug(log) << "###############";
foreach (const CMakeBuildTarget &target, m_buildTargets) 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, bool CMakeCbpParser::parseCbpFile(CMakeTool::PathMapper mapper, const FileName &fileName,
...@@ -397,12 +401,8 @@ void CMakeCbpParser::parseAdd() ...@@ -397,12 +401,8 @@ void CMakeCbpParser::parseAdd()
m_buildTarget.compilerOptions.append(compilerOption); m_buildTarget.compilerOptions.append(compilerOption);
int macroNameIndex = compilerOption.indexOf("-D") + 2; int macroNameIndex = compilerOption.indexOf("-D") + 2;
if (macroNameIndex != 1) { if (macroNameIndex != 1) {
int assignIndex = compilerOption.indexOf('=', macroNameIndex); const QString keyValue = compilerOption.mid(macroNameIndex);
if (assignIndex != -1) m_buildTarget.macros.append(ProjectExplorer::Macro::fromKeyValue(keyValue));
compilerOption[assignIndex] = ' ';
m_buildTarget.defines.append("#define ");
m_buildTarget.defines.append(compilerOption.mid(macroNameIndex).toUtf8());
m_buildTarget.defines.append('\n');
} }
} }
......
...@@ -559,7 +559,7 @@ void CMakeBuildTarget::clear() ...@@ -559,7 +559,7 @@ void CMakeBuildTarget::clear()
targetType = UtilityType; targetType = UtilityType;
includeFiles.clear(); includeFiles.clear();
compilerOptions.clear(); compilerOptions.clear();
defines.clear(); macros.clear();
files.clear(); files.clear();
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "treescanner.h" #include "treescanner.h"
#include <projectexplorer/extracompiler.h> #include <projectexplorer/extracompiler.h>
#include <projectexplorer/projectmacro.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
...@@ -72,7 +73,7 @@ public: ...@@ -72,7 +73,7 @@ public:
// code model // code model
QList<Utils::FileName> includeFiles; QList<Utils::FileName> includeFiles;
QStringList compilerOptions; QStringList compilerOptions;
QByteArray defines; ProjectExplorer::Macros macros;
QList<Utils::FileName> files; QList<Utils::FileName> files;
void clear(); void clear();
......
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <QVector>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
...@@ -325,14 +327,6 @@ void ServerModeReader::updateCodeModel(CppTools::RawProjectParts &rpps) ...@@ -325,14 +327,6 @@ void ServerModeReader::updateCodeModel(CppTools::RawProjectParts &rpps)
int counter = 0; int counter = 0;
for (const FileGroup *fg : Utils::asConst(m_fileGroups)) { for (const FileGroup *fg : Utils::asConst(m_fileGroups)) {
++counter; ++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 flags = QtcProcess::splitArgs(fg->compileFlags);
const QStringList includes = transform(fg->includePaths, [](const IncludePath *ip) { return ip->path.toString(); }); const QStringList includes = transform(fg->includePaths, [](const IncludePath *ip) { return ip->path.toString(); });
...@@ -340,7 +334,7 @@ void ServerModeReader::updateCodeModel(CppTools::RawProjectParts &rpps) ...@@ -340,7 +334,7 @@ void ServerModeReader::updateCodeModel(CppTools::RawProjectParts &rpps)
rpp.setProjectFileLocation(fg->target->sourceDirectory.toString() + "/CMakeLists.txt"); rpp.setProjectFileLocation(fg->target->sourceDirectory.toString() + "/CMakeLists.txt");
rpp.setBuildSystemTarget(fg->target->name); rpp.setBuildSystemTarget(fg->target->name);
rpp.setDisplayName(fg->target->name + QString::number(counter)); rpp.setDisplayName(fg->target->name + QString::number(counter));
rpp.setDefines(defineArg.toUtf8()); rpp.setMacros(fg->macros);
rpp.setIncludePaths(includes); rpp.setIncludePaths(includes);
CppTools::RawProjectPartFlags cProjectFlags; CppTools::RawProjectPartFlags cProjectFlags;
...@@ -523,7 +517,9 @@ ServerModeReader::FileGroup *ServerModeReader::extractFileGroupData(const QVaria ...@@ -523,7 +517,9 @@ ServerModeReader::FileGroup *ServerModeReader::extractFileGroupData(const QVaria
auto fileGroup = new FileGroup; auto fileGroup = new FileGroup;
fileGroup->target = t; fileGroup->target = t;
fileGroup->compileFlags = data.value("compileFlags").toString(); 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(), fileGroup->includePaths = transform(data.value("includePath").toList(),
[](const QVariant &i) -> IncludePath* { [](const QVariant &i) -> IncludePath* {
const QVariantMap iData = i.toMap(); const QVariantMap iData = i.toMap();
...@@ -662,7 +658,7 @@ void ServerModeReader::fixTarget(ServerModeReader::Target *target) const ...@@ -662,7 +658,7 @@ void ServerModeReader::fixTarget(ServerModeReader::Target *target) const
for (const FileGroup *group : Utils::asConst(target->fileGroups)) { for (const FileGroup *group : Utils::asConst(target->fileGroups)) {
if (group->includePaths.isEmpty() && group->compileFlags.isEmpty() if (group->includePaths.isEmpty() && group->compileFlags.isEmpty()
&& group->defines.isEmpty()) && group->macros.isEmpty())
continue; continue;
const FileGroup *fallback = languageFallbacks.value(group->language); const FileGroup *fallback = languageFallbacks.value(group->language);
...@@ -688,13 +684,13 @@ void ServerModeReader::fixTarget(ServerModeReader::Target *target) const ...@@ -688,13 +684,13 @@ void ServerModeReader::fixTarget(ServerModeReader::Target *target) const
(*it)->language = fallback->language.isEmpty() ? "CXX" : fallback->language; (*it)->language = fallback->language.isEmpty() ? "CXX" : fallback->language;
if (*it == fallback if (*it == fallback
|| !(*it)->includePaths.isEmpty() || !(*it)->defines.isEmpty() || !(*it)->includePaths.isEmpty() || !(*it)->macros.isEmpty()
|| !(*it)->compileFlags.isEmpty()) || !(*it)->compileFlags.isEmpty())
continue; continue;
for (const IncludePath *ip : fallback->includePaths) for (const IncludePath *ip : fallback->includePaths)
(*it)->includePaths.append(new IncludePath(*ip)); (*it)->includePaths.append(new IncludePath(*ip));
(*it)->defines = fallback->defines; (*it)->macros = fallback->macros;
(*it)->compileFlags = fallback->compileFlags; (*it)->compileFlags = fallback->compileFlags;
} }
} }
......
...@@ -86,7 +86,7 @@ private: ...@@ -86,7 +86,7 @@ private:
Target *target = nullptr; Target *target = nullptr;
QString compileFlags; QString compileFlags;
QStringList defines; ProjectExplorer::Macros macros;
QList<IncludePath *> includePaths; QList<IncludePath *> includePaths;
QString language; QString language;