From 197f2b5f2a8d5335040e0b8012797bf47a29f397 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 23 Jan 2019 18:54:48 +0100 Subject: [PATCH] ClangSupport: Fix CommandLineBuilder Forgot to add macros. Change-Id: I4a5ab969a6b99c110b3ffd9e8f2b59560ccfc8b9 Reviewed-by: Ivan Donchevskii --- src/libs/clangsupport/commandlinebuilder.h | 15 +++++++++++++++ tests/unit/unittest/commandlinebuilder-test.cpp | 16 ++++++++++++++++ tests/unit/unittest/symbolindexer-test.cpp | 16 ++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/libs/clangsupport/commandlinebuilder.h b/src/libs/clangsupport/commandlinebuilder.h index af9c0f1bafb..6a9975a3ac9 100644 --- a/src/libs/clangsupport/commandlinebuilder.h +++ b/src/libs/clangsupport/commandlinebuilder.h @@ -52,6 +52,7 @@ public: addLanguage(projectInfo); addLanguageVersion(projectInfo); addNoStdIncAndNoStdLibInc(); + addCompilerMacros(projectInfo.compilerMacros); addProjectIncludeSearchPaths( sortedIncludeSearchPaths(projectInfo.projectIncludeSearchPaths)); addSystemAndBuiltInIncludeSearchPaths( @@ -177,6 +178,20 @@ public: commandLine.emplace_back(standardLanguageVersion(projectInfo.languageVersion)); } + void addCompilerMacros(const CompilerMacros &compilerMacros) + { + CompilerMacros macros = compilerMacros; + + std::sort(macros.begin(), + macros.end(), + [](const CompilerMacro &first, const CompilerMacro &second) { + return first.index < second.index; + }); + + for (const CompilerMacro ¯o : macros) + commandLine.emplace_back(Utils::SmallString{"-D", macro.key, "=", macro.value}); + } + IncludeSearchPaths sortedIncludeSearchPaths(const IncludeSearchPaths &unsortedPaths) { IncludeSearchPaths paths = unsortedPaths; diff --git a/tests/unit/unittest/commandlinebuilder-test.cpp b/tests/unit/unittest/commandlinebuilder-test.cpp index 07b5a5b8dfd..4548b57a9bd 100644 --- a/tests/unit/unittest/commandlinebuilder-test.cpp +++ b/tests/unit/unittest/commandlinebuilder-test.cpp @@ -509,4 +509,20 @@ TYPED_TEST(CommandLineBuilder, IncludePchPath) "/source/file.cpp")); } +TYPED_TEST(CommandLineBuilder, CompilerMacros) +{ + this->emptyProjectInfo.compilerMacros = {{"YI", "1", 2}, {"ER", "2", 1}}; + + Builder builder{this->emptyProjectInfo}; + + ASSERT_THAT(builder.commandLine, + ElementsAre("clang++", + "-x", + "c++-header", + "-std=c++98", + "-nostdinc", + "-nostdlibinc", + "-DER=2", + "-DYI=1")); +} } // namespace diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index f28d0e66968..23f469cd340 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -270,6 +270,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector) "-std=c++14", "-nostdinc", "-nostdlibinc", + "-DBAR=1", + "-DFOO=1", "-I", "/project/includes", "-I", @@ -298,6 +300,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInColl "-std=c++14", "-nostdinc", "-nostdlibinc", + "-DBAR=1", + "-DFOO=1", "-I", "/project/includes", "-I", @@ -329,6 +333,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInC "-std=c++14", "-nostdinc", "-nostdlibinc", + "-DBAR=1", + "-DFOO=1", "-I", "/project/includes", "-I", @@ -507,6 +513,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact) "-std=c++14", "-nostdinc", "-nostdlibinc", + "-DBAR=1", + "-DFOO=1", "-I", "/project/includes", "-I", @@ -557,6 +565,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact) "-std=c++14", "-nostdinc", "-nostdlibinc", + "-DBAR=1", + "-DFOO=1", "-I", "/project/includes", "-I", @@ -611,6 +621,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder) "-std=c++14", "-nostdinc", "-nostdlibinc", + "-DBAR=1", + "-DFOO=1", "-I", "/project/includes", "-I", @@ -671,6 +683,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader) "-std=c++14", "-nostdinc", "-nostdlibinc", + "-DBAR=1", + "-DFOO=1", "-I", "/project/includes", "-I", @@ -704,6 +718,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists) "-std=c++14", "-nostdinc", "-nostdlibinc", + "-DBAR=1", + "-DFOO=1", "-I", "/project/includes", "-I",