forked from qt-creator/qt-creator
CompilationDatabase: Fix command line parsing
Handle cased when -x{kind} is one option. Skip -o output files. Task-number: QTCREATORBUG-18402 Change-Id: Id8a8612bed2db2b35f17b0968a4ff529e7a66194 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -178,7 +178,7 @@ void addDriverModeFlagIfNeeded(const ToolChain *toolchain, QStringList &flags)
|
|||||||
if (toolchain->typeId() == ProjectExplorer::Constants::CLANG_CL_TOOLCHAIN_TYPEID
|
if (toolchain->typeId() == ProjectExplorer::Constants::CLANG_CL_TOOLCHAIN_TYPEID
|
||||||
&& !flags.empty() && !flags.front().endsWith("cl")
|
&& !flags.empty() && !flags.front().endsWith("cl")
|
||||||
&& !flags.front().endsWith("cl.exe")) {
|
&& !flags.front().endsWith("cl.exe")) {
|
||||||
flags.insert(1, "--driver-mode=g++");
|
flags.prepend("--driver-mode=g++");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -49,9 +49,12 @@ static QString updatedPathFlag(const QString &pathStr, const QString &workingDir
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CppTools::ProjectFile::Kind fileKindFromString(const QString &flag)
|
static CppTools::ProjectFile::Kind fileKindFromString(QString flag)
|
||||||
{
|
{
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
|
if (flag.startsWith("-x"))
|
||||||
|
flag = flag.mid(2);
|
||||||
|
|
||||||
if (flag == "c++-header")
|
if (flag == "c++-header")
|
||||||
return ProjectFile::CXXHeader;
|
return ProjectFile::CXXHeader;
|
||||||
if (flag == "c-header")
|
if (flag == "c-header")
|
||||||
@@ -118,8 +121,14 @@ void filteredFlags(const QString &fileName,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileKindIsNext || flag == "/TC" || flag == "/TP"
|
if (flag == "-o") {
|
||||||
|| flag.startsWith("/Tc") || flag.startsWith("/Tp")) {
|
skipNext = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag != "-x"
|
||||||
|
&& (fileKindIsNext || flag == "/TC" || flag == "/TP"
|
||||||
|
|| flag.startsWith("/Tc") || flag.startsWith("/Tp") || flag.startsWith("-x"))) {
|
||||||
fileKindIsNext = false;
|
fileKindIsNext = false;
|
||||||
fileKind = fileKindFromString(flag);
|
fileKind = fileKindFromString(flag);
|
||||||
continue;
|
continue;
|
||||||
|
@@ -166,4 +166,34 @@ TEST_F(CompilationDatabaseUtils, FilterCommand)
|
|||||||
ASSERT_THAT(fileKind, CppTools::ProjectFile::Kind::CXXSource);
|
ASSERT_THAT(fileKind, CppTools::ProjectFile::Kind::CXXSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilationDatabaseUtils, FileKindDifferentFromExtension)
|
||||||
|
{
|
||||||
|
fileName = "foo.c";
|
||||||
|
flags = QStringList{"-xc++"};
|
||||||
|
|
||||||
|
filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind);
|
||||||
|
|
||||||
|
ASSERT_THAT(fileKind, CppTools::ProjectFile::Kind::CXXSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilationDatabaseUtils, FileKindDifferentFromExtension2)
|
||||||
|
{
|
||||||
|
fileName = "foo.cpp";
|
||||||
|
flags = QStringList{"-x", "c"};
|
||||||
|
|
||||||
|
filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind);
|
||||||
|
|
||||||
|
ASSERT_THAT(fileKind, CppTools::ProjectFile::Kind::CSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilationDatabaseUtils, SkipOutputFiles)
|
||||||
|
{
|
||||||
|
fileName = "foo.cpp";
|
||||||
|
flags = QStringList{"-o", "foo.o"};
|
||||||
|
|
||||||
|
filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind);
|
||||||
|
|
||||||
|
ASSERT_THAT(flags.isEmpty(), true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user