Clang: Use full paths in compilation database for symbol collector

We we FilePath and NativeFilePath so that compiler warns us if we mix them
up.

Change-Id: I33d7abc7e4e724dff2a9b2b9b23deea8b358ccfd
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2019-01-31 10:30:58 +01:00
parent 874dde6863
commit dd778bcb23
27 changed files with 355 additions and 304 deletions

View File

@@ -25,7 +25,7 @@
#pragma once
#include "filepathview.h"
#include "filepath.h"
#include <compilermacro.h>
#include <includesearchpath.h>
@@ -35,7 +35,7 @@
namespace ClangBackEnd {
template<typename ProjectInfo, typename OutputContainer = std::vector<std::string>>
template<typename ProjectInfo, typename OutputContainer = Utils::SmallStringVector>
class CommandLineBuilder
{
public:
@@ -213,7 +213,7 @@ public:
{
for (const IncludeSearchPath &path : projectIncludeSearchPaths) {
commandLine.emplace_back("-I");
commandLine.emplace_back(path.path);
commandLine.emplace_back(NativeFilePath(FilePathView(path.path)));
}
}
@@ -228,7 +228,7 @@ public:
for (const IncludeSearchPath &path : systemIncludeSearchPaths) {
if (path.type != IncludeSearchPathType::BuiltIn) {
commandLine.emplace_back(includeOption(path.type));
commandLine.emplace_back(path.path);
commandLine.emplace_back(NativeFilePath(FilePathView(path.path)));
}
}
}
@@ -238,7 +238,7 @@ public:
for (const IncludeSearchPath &path : systemIncludeSearchPaths) {
if (path.type == IncludeSearchPathType::BuiltIn) {
commandLine.emplace_back(includeOption(path.type));
commandLine.emplace_back(path.path);
commandLine.emplace_back(NativeFilePath(FilePathView(path.path)));
}
}
}
@@ -247,23 +247,24 @@ public:
{
if (!outputPath.isEmpty()) {
commandLine.emplace_back("-o");
commandLine.emplace_back(outputPath);
commandLine.emplace_back(NativeFilePath(outputPath));
}
}
void addSourcePath(FilePathView sourcePath)
{
if (!sourcePath.isEmpty())
commandLine.emplace_back(sourcePath);
commandLine.emplace_back(NativeFilePath(sourcePath));
}
void addIncludePchPath(FilePathView includePchPath)
{
if (!includePchPath.isEmpty()) {
commandLine.emplace_back("-Xclang");
commandLine.emplace_back("-include-pch");
commandLine.emplace_back("-Xclang");
commandLine.emplace_back(includePchPath);
commandLine.emplace_back(NativeFilePath(includePchPath));
}
}

View File

@@ -28,7 +28,7 @@
#include "clangsupport_global.h"
#include "filepathview.h"
#include "filepathview.h"
#include "nativefilepath.h"
#include <utils/hostosinfo.h>
#include <utils/smallstringio.h>
@@ -37,6 +37,8 @@
namespace ClangBackEnd {
class NativeFilePath;
class FilePath : public Utils::PathString
{
using size_type = Utils::PathString::size_type;

View File

@@ -26,13 +26,15 @@
#pragma once
#include "filepathview.h"
#include "filepathview.h"
#include "filepath.h"
#include <utils/hostosinfo.h>
#include <utils/smallstringio.h>
namespace ClangBackEnd {
class FilePath;
class NativeFilePath
{
using size_type = Utils::PathString::size_type;
@@ -50,8 +52,13 @@ public:
NativeFilePath(NativeFilePathView filePathView)
: m_path(filePathView.toStringView()),
m_slashIndex(filePathView.slashIndex())
{
}
{}
explicit NativeFilePath(FilePathView filePathView) { *this = fromFilePath(filePathView); }
explicit NativeFilePath(const FilePath &filePath)
: NativeFilePath{FilePathView{filePath}}
{}
template<size_type Size>
NativeFilePath(const char(&string)[Size]) noexcept

View File

@@ -90,8 +90,7 @@ public:
SmallStringView(const String &string) noexcept
: m_pointer(string.data()),
m_size(string.size())
{
}
{}
static
SmallStringView fromUtf8(const char *const characterPointer)

View File

@@ -94,10 +94,9 @@ FilePath PchCreator::generatePchFilePath() const
".pch"}};
}
std::vector<std::string> PchCreator::generateClangCompilerArguments(
const PchTask &pchTask,
FilePathView sourceFilePath,
FilePathView pchOutputPath)
Utils::SmallStringVector PchCreator::generateClangCompilerArguments(const PchTask &pchTask,
FilePathView sourceFilePath,
FilePathView pchOutputPath)
{
CommandLineBuilder<PchTask> builder{pchTask,
pchTask.toolChainArguments,
@@ -114,10 +113,12 @@ void PchCreator::generatePch(PchTask &&pchTask)
auto content = generatePchIncludeFileContent(pchTask.includes);
auto pchOutputPath = generatePchFilePath();
m_clangTool.addFile(m_environment.pchBuildDirectory().toStdString(),
"dummy.h",
Utils::SmallStringView(content),
generateClangCompilerArguments(pchTask, "dummy.h", pchOutputPath));
FilePath headerFilePath{m_environment.pchBuildDirectory().toStdString(), "dummy.h"};
Utils::SmallStringVector commandLine = generateClangCompilerArguments(pchTask,
headerFilePath,
pchOutputPath);
m_clangTool.addFile(std::move(headerFilePath), std::move(content), std::move(commandLine));
bool success = generatePch();

View File

@@ -84,7 +84,7 @@ public:
bool generatePch();
FilePath generatePchFilePath() const;
static std::vector<std::string> generateClangCompilerArguments(const PchTask &pchTask,
static Utils::SmallStringVector generateClangCompilerArguments(const PchTask &pchTask,
FilePathView includePchHeaderPath,
FilePathView pchPath);

View File

@@ -50,10 +50,9 @@ ClangQueryGatherer::createSourceRangesForSource(
{
ClangQuery clangQuery(*filePathCache, std::move(query));
clangQuery.addFile(std::string(source.filePath.directory()),
std::string(source.filePath.name()),
std::string(source.unsavedFileContent),
std::vector<std::string>(source.commandLineArguments));
clangQuery.addFile(std::move(source.filePath),
std::move(source.unsavedFileContent),
std::move(source.commandLineArguments));
clangQuery.addUnsavedFiles(unsaved);

View File

@@ -27,6 +27,8 @@
#include <iostream>
#include <nativefilepath.h>
namespace ClangBackEnd {
namespace {
@@ -44,67 +46,37 @@ String toNativePath(String &&path)
}
}
void ClangTool::addFile(std::string &&directory,
std::string &&fileName,
std::string &&content,
std::vector<std::string> &&commandLine)
void ClangTool::addFile(FilePath &&filePath,
Utils::SmallString &&content,
Utils::SmallStringVector &&commandLine)
{
m_fileContents.emplace_back(toNativePath(std::move(directory)),
std::move(fileName),
std::move(content),
std::move(commandLine));
NativeFilePath nativeFilePath{filePath};
const auto &fileContent = m_fileContents.back();
m_compilationDatabase.addFile(nativeFilePath, std::move(commandLine));
m_sourceFilePaths.push_back(Utils::SmallStringView{nativeFilePath});
m_compilationDatabase.addFile(fileContent.directory, fileContent.fileName, fileContent.commandLine);
m_sourceFilePaths.push_back(fileContent.filePath);
m_fileContents.emplace_back(std::move(nativeFilePath), std::move(content));
}
void ClangTool::addFiles(const FilePaths &filePaths, const Utils::SmallStringVector &arguments)
{
for (const FilePath &filePath : filePaths) {
std::vector<std::string> commandLine(arguments.begin(), arguments.end());
commandLine.push_back(std::string(filePath.name()));
std::string filePathStr(filePath.path());
auto commandLine = arguments;
NativeFilePath nativeFilePath{filePath};
addFile(filePath.directory(),
filePath.name(),
{},
std::move(commandLine));
commandLine.push_back(nativeFilePath.path());
addFile(filePath.clone(), {}, std::move(commandLine));
}
}
template <typename Container>
void ClangTool::addFiles(const Container &filePaths,
const Utils::SmallStringVector &arguments)
{
for (const typename Container::value_type &filePath : filePaths) {
auto found = std::find(filePath.rbegin(), filePath.rend(), '/');
auto fileNameBegin = found.base();
std::vector<std::string> commandLine(arguments.begin(), arguments.end());
commandLine.push_back(std::string(filePath));
addFile({filePath.begin(), std::prev(fileNameBegin)},
{fileNameBegin, filePath.end()},
{},
std::move(commandLine));
}
}
template
void ClangTool::addFiles<Utils::SmallStringVector>(const Utils::SmallStringVector &filePaths,
const Utils::SmallStringVector &arguments);
template
void ClangTool::addFiles<Utils::PathStringVector>(const Utils::PathStringVector &filePaths,
const Utils::SmallStringVector &arguments);
void ClangTool::addUnsavedFiles(const V2::FileContainers &unsavedFiles)
{
m_unsavedFileContents.reserve(m_unsavedFileContents.size() + unsavedFiles.size());
auto convertToUnsavedFileContent = [] (const V2::FileContainer &unsavedFile) {
return UnsavedFileContent{toNativePath(unsavedFile.filePath.path().clone()),
auto convertToUnsavedFileContent = [](const V2::FileContainer &unsavedFile) {
return UnsavedFileContent{NativeFilePath{unsavedFile.filePath},
unsavedFile.unsavedFileContent.clone()};
};
@@ -120,7 +92,12 @@ llvm::StringRef toStringRef(const String &string)
{
return llvm::StringRef(string.data(), string.size());
}
llvm::StringRef toStringRef(const NativeFilePath &path)
{
return llvm::StringRef(path.path().data(), path.path().size());
}
} // namespace
clang::tooling::ClangTool ClangTool::createTool() const
{
@@ -128,7 +105,7 @@ clang::tooling::ClangTool ClangTool::createTool() const
for (const auto &fileContent : m_fileContents) {
if (!fileContent.content.empty())
tool.mapVirtualFile(fileContent.filePath, fileContent.content);
tool.mapVirtualFile(toStringRef(fileContent.filePath), fileContent.content);
}
for (const auto &unsavedFileContent : m_unsavedFileContents)

View File

@@ -30,6 +30,7 @@
#include <clangrefactoringbackend_global.h>
#include <filecontainerv2.h>
#include <nativefilepath.h>
#include <sourcelocationscontainer.h>
#include <clang/Tooling/Refactoring.h>
@@ -43,50 +44,34 @@ namespace ClangBackEnd {
struct FileContent
{
FileContent(const std::string &directory,
const std::string &fileName,
const std::string &content,
const std::vector<std::string> &commandLine)
: directory(directory),
fileName(fileName),
filePath(directory + nativeSeparator + fileName),
content(content),
commandLine(commandLine)
FileContent(NativeFilePath &&filePath, const Utils::SmallString &content)
: filePath(std::move(filePath))
, content(std::move(content))
{}
std::string directory;
std::string fileName;
std::string filePath;
NativeFilePath filePath;
std::string content;
std::vector<std::string> commandLine;
};
struct UnsavedFileContent
{
UnsavedFileContent(Utils::PathString &&filePath,
Utils::SmallString &&content)
: filePath(std::move(filePath)),
content(std::move(content))
UnsavedFileContent(NativeFilePath &&filePath, Utils::SmallString &&content)
: filePath(std::move(filePath))
, content(std::move(content))
{}
Utils::PathString filePath;
NativeFilePath filePath;
Utils::SmallString content;
};
class ClangTool
{
public:
void addFile(std::string &&directory,
std::string &&fileName,
std::string &&content,
std::vector<std::string> &&commandLine);
template <typename Container>
void addFiles(const Container &filePaths,
const Utils::SmallStringVector &arguments);
void addFiles(const FilePaths &filePaths,
const Utils::SmallStringVector &arguments);
void addFile(FilePath &&filePath,
Utils::SmallString &&content,
Utils::SmallStringVector &&commandLine);
void addFiles(const FilePaths &filePaths, const Utils::SmallStringVector &arguments);
void addUnsavedFiles(const V2::FileContainers &unsavedFiles);
@@ -102,11 +87,4 @@ private:
std::vector<UnsavedFileContent> m_unsavedFileContents;
};
extern template
void ClangTool::addFiles<Utils::SmallStringVector>(const Utils::SmallStringVector &filePaths,
const Utils::SmallStringVector &arguments);
extern template
void ClangTool::addFiles<Utils::PathStringVector>(const Utils::PathStringVector &filePaths,
const Utils::SmallStringVector &arguments);
} // namespace ClangBackEnd

View File

@@ -27,20 +27,15 @@
#include "clangrefactoringbackend_global.h"
#include <filepath.h>
#include <nativefilepath.h>
namespace ClangBackEnd {
RefactoringCompilationDatabase::RefactoringCompilationDatabase()
{
}
namespace {
std::string concatFilePath(const clang::tooling::CompileCommand &compileCommand)
{
return compileCommand.Directory + nativeSeparator + compileCommand.Filename;
}
}
std::vector<clang::tooling::CompileCommand>
RefactoringCompilationDatabase::getCompileCommands(llvm::StringRef filePath) const
{
@@ -50,7 +45,7 @@ RefactoringCompilationDatabase::getCompileCommands(llvm::StringRef filePath) con
m_compileCommands.end(),
std::back_inserter(foundCommands),
[&] (const clang::tooling::CompileCommand &compileCommand) {
return filePath == concatFilePath(compileCommand);
return filePath == compileCommand.Filename;
});
return foundCommands;
@@ -66,7 +61,7 @@ RefactoringCompilationDatabase::getAllFiles() const
m_compileCommands.end(),
std::back_inserter(filePaths),
[&] (const clang::tooling::CompileCommand &compileCommand) {
return concatFilePath(compileCommand);
return compileCommand.Filename;
});
return filePaths;
@@ -78,12 +73,13 @@ RefactoringCompilationDatabase::getAllCompileCommands() const
return m_compileCommands;
}
void RefactoringCompilationDatabase::addFile(const std::string &directory,
const std::string &fileName,
const std::vector<std::string> &commandLine)
void RefactoringCompilationDatabase::addFile(NativeFilePathView filePath,
Utils::SmallStringVector &&commandLine)
{
m_compileCommands.emplace_back(directory, fileName, commandLine, llvm::StringRef());
m_compileCommands.emplace_back(std::string(filePath.directory()),
std::string(filePath),
std::vector<std::string>(commandLine),
llvm::StringRef());
}
} // namespace ClangBackEnd

View File

@@ -27,6 +27,8 @@
#include "clang/Tooling/CompilationDatabase.h"
#include <nativefilepath.h>
namespace ClangBackEnd {
@@ -39,9 +41,7 @@ public:
std::vector<std::string> getAllFiles() const override;
std::vector<clang::tooling::CompileCommand> getAllCompileCommands() const override;
void addFile(const std::string &directory,
const std::string &fileName,
const std::vector<std::string> &commandLine);
void addFile(NativeFilePathView filePath, Utils::SmallStringVector &&commandLine);
private:
std::vector<clang::tooling::CompileCommand> m_compileCommands;

View File

@@ -62,10 +62,9 @@ void RefactoringServer::requestSourceLocationsForRenamingMessage(RequestSourceLo
{
SymbolFinder symbolFinder(message.line, message.column, m_filePathCache);
symbolFinder.addFile(std::string(message.filePath.directory()),
std::string(message.filePath.name()),
std::string(message.unsavedContent),
std::vector<std::string>(message.commandLine));
symbolFinder.addFile(std::move(message.filePath),
std::move(message.unsavedContent),
std::move(message.commandLine));
symbolFinder.findSymbol();
@@ -79,10 +78,9 @@ void RefactoringServer::requestSourceRangesAndDiagnosticsForQueryMessage(
{
ClangQuery clangQuery(m_filePathCache, message.takeQuery());
clangQuery.addFile(std::string(message.source.filePath.directory()),
std::string(message.source.filePath.name()),
std::string(message.source.unsavedFileContent),
std::vector<std::string>(message.source.commandLineArguments));
clangQuery.addFile(std::move(message.source.filePath),
std::move(message.source.unsavedFileContent),
std::move(message.source.commandLineArguments));
clangQuery.findLocations();

View File

@@ -94,7 +94,9 @@ TEST_F(ClangQuerySlowTest, RootSourceRangeForSimpleFunctionDeclarationRange)
TEST_F(ClangQuerySlowTest, SourceRangeInUnsavedFileDeclarationRange)
{
::ClangQuery query(filePathCache);
query.addFile(TESTDATA_DIR, "query_simplefunction.cpp", "#include \"unsaved.h\"", {"cc", toNativePath(TESTDATA_DIR"/query_simplefunction.cpp"), "-std=c++14"});
query.addFile({TESTDATA_DIR "/query_simplefunction.cpp"},
"#include \"unsaved.h\"",
{"cc", toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path(), "-std=c++14"});
query.setQuery("functionDecl()");
ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR, "unsaved.h"}, "void unsaved();", {}};
query.addUnsavedFiles({unsavedFile});
@@ -108,7 +110,9 @@ TEST_F(ClangQuerySlowTest, SourceRangeInUnsavedFileDeclarationRange)
TEST_F(ClangQuerySlowTest, FileIsNotExistingButTheUnsavedDataIsParsed)
{
::ClangQuery query(filePathCache);
query.addFile(TESTDATA_DIR, "foo.cpp", "void f() {}", {"cc", toNativePath(TESTDATA_DIR"/foo.cpp"), "-std=c++14"});
query.addFile({TESTDATA_DIR "/foo.cpp"},
"void f() {}",
{"cc", toNativePath(TESTDATA_DIR "/foo.cpp").path(), "-std=c++14"});
query.setQuery("functionDecl()");
query.findLocations();
@@ -120,9 +124,13 @@ TEST_F(ClangQuerySlowTest, FileIsNotExistingButTheUnsavedDataIsParsed)
TEST_F(ClangQuerySlowTest, DISABLED_SourceRangeInUnsavedFileDeclarationRangeOverride) // seems not to work in Clang
{
::ClangQuery query(filePathCache);
query.addFile(TESTDATA_DIR, "query_simplefunction.cpp", "void f() {}", {"cc", toNativePath(TESTDATA_DIR"/query_simplefunction.cpp"), "-std=c++14"});
query.addFile({TESTDATA_DIR "/query_simplefunction.cpp"},
"void f() {}",
{"cc", toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path(), "-std=c++14"});
query.setQuery("functionDecl()");
ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR, "query_simplefunction.cpp"}, "void unsaved();", {}};
ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR "/query_simplefunction.cpp"},
"void unsaved();",
{}};
query.addUnsavedFiles({unsavedFile});
query.findLocations();
@@ -215,8 +223,15 @@ TEST_F(ClangQuerySlowTest, DiagnosticForWrongArgumenType)
void ClangQuery::SetUp()
{
simpleFunctionQuery.addFile(TESTDATA_DIR, "query_simplefunction.cpp", "", {"cc", toNativePath(TESTDATA_DIR"/query_simplefunction.cpp"), "-std=c++14"});
simpleClassQuery.addFile(TESTDATA_DIR, "query_simpleclass.cpp", "", {"cc", "query_simpleclass.cpp", "-std=c++14"});
}
simpleFunctionQuery.addFile({TESTDATA_DIR "/query_simplefunction.cpp"},
"",
{"cc",
toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path(),
"-std=c++14"});
simpleClassQuery.addFile({TESTDATA_DIR "/query_simpleclass.cpp"},
"",
{"cc",
toNativePath(TESTDATA_DIR "/query_simpleclass.cpp").path(),
"-std=c++14"});
}
} // namespace

View File

@@ -87,13 +87,22 @@ protected:
Utils::SmallString sourceContent{"#include \"query_simplefunction.h\"\nvoid f() {}"};
FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"},
sourceContent.clone(),
{"cc", toNativePath(TESTDATA_DIR"/query_simplefunction.cpp"), "-I", TESTDATA_DIR}};
{"cc",
toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path(),
"-I",
TESTDATA_DIR}};
FileContainer source2{{TESTDATA_DIR, "query_simplefunction2.cpp"},
{},
{"cc", toNativePath(TESTDATA_DIR"/query_simplefunction2.cpp"), "-I", TESTDATA_DIR}};
{"cc",
toNativePath(TESTDATA_DIR "/query_simplefunction2.cpp").path(),
"-I",
TESTDATA_DIR}};
FileContainer source3{{TESTDATA_DIR, "query_simplefunction3.cpp"},
{},
{"cc", toNativePath(TESTDATA_DIR"/query_simplefunction3.cpp"), "-I", TESTDATA_DIR}};
{"cc",
toNativePath(TESTDATA_DIR "/query_simplefunction3.cpp").path(),
"-I",
TESTDATA_DIR}};
Utils::SmallString unsavedContent{"void f();"};
FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"},
unsavedContent.clone(),

View File

@@ -25,6 +25,8 @@
#include "googletest.h"
#include "filesystem-utilities.h"
#include <commandlinebuilder.h>
#include <pchtask.h>
#include <projectpartcontainer.h>
@@ -136,7 +138,7 @@ TYPED_TEST(CommandLineBuilder, CTask)
ASSERT_THAT(
builder.commandLine,
ElementsAre("clang", "-x", "c-header", "-std=c11", "-nostdinc", "-nostdinc++", "/source/file.c"));
ElementsAre("clang", "-x", "c-header", "-std=c11", "-nostdinc", "-nostdinc++", toNativePath("/source/file.c").path()));
}
TYPED_TEST(CommandLineBuilder, ObjectiveCTask)
@@ -154,7 +156,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCTask)
"-std=c11",
"-nostdinc",
"-nostdinc++",
"/source/file.c"));
toNativePath("/source/file.c").path()));
}
TYPED_TEST(CommandLineBuilder, CppTask)
@@ -171,7 +173,7 @@ TYPED_TEST(CommandLineBuilder, CppTask)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"/source/file.cpp"));
toNativePath("/source/file.cpp").path()));
}
TYPED_TEST(CommandLineBuilder, ObjectiveCppTask)
@@ -189,7 +191,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCppTask)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"/source/file.cpp"));
toNativePath("/source/file.cpp").path()));
}
TYPED_TEST(CommandLineBuilder, Cpp98)
@@ -422,18 +424,18 @@ TYPED_TEST(CommandLineBuilder, IncludesOrder)
"-nostdinc",
"-nostdinc++",
"-I",
"/include/foo",
toNativePath("/include/foo").path(),
"-I",
"/include/bar",
toNativePath("/include/bar").path(),
"-F",
"/system/foo",
toNativePath("/system/foo").path(),
"-isystem",
"/system/bar",
toNativePath("/system/bar").path(),
"-isystem",
"/builtin/foo",
toNativePath("/builtin/foo").path(),
"-isystem",
"/builtin/bar",
"/source/file.cpp"));
toNativePath("/builtin/bar").path(),
toNativePath("/source/file.cpp").path()));
}
TYPED_TEST(CommandLineBuilder, EmptySourceFile)
@@ -455,7 +457,7 @@ TYPED_TEST(CommandLineBuilder, SourceFile)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"/source/file.cpp"));
toNativePath("/source/file.cpp").path()));
}
@@ -470,7 +472,7 @@ TYPED_TEST(CommandLineBuilder, EmptyOutputFile)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"/source/file.cpp"));
toNativePath("/source/file.cpp").path()));
}
TYPED_TEST(CommandLineBuilder, OutputFile)
@@ -485,8 +487,8 @@ TYPED_TEST(CommandLineBuilder, OutputFile)
"-nostdinc",
"-nostdinc++",
"-o",
"/output/file.o",
"/source/file.cpp"));
toNativePath("/output/file.o").path(),
toNativePath("/source/file.cpp").path()));
}
TYPED_TEST(CommandLineBuilder, IncludePchPath)
@@ -503,10 +505,10 @@ TYPED_TEST(CommandLineBuilder, IncludePchPath)
"-Xclang",
"-include-pch",
"-Xclang",
"/pch/file.pch",
toNativePath("/pch/file.pch").path(),
"-o",
"/output/file.o",
"/source/file.cpp"));
toNativePath("/output/file.o").path(),
toNativePath("/source/file.cpp").path()));
}
TYPED_TEST(CommandLineBuilder, CompilerMacros)

View File

@@ -26,32 +26,27 @@
#pragma once
#include <utils/hostosinfo.h>
#include <utils/smallstring.h>
#include <string>
#include <nativefilepath.h>
// use std::filesystem::path if it is supported by all compilers
static const char nativeSeparator = Utils::HostOsInfo::isWindowsHost() ? '\\' : '/';
template <std::size_t Size>
std::string toNativePath(const char (&text)[Size])
template<std::size_t Size>
ClangBackEnd::NativeFilePath toNativePath(const char (&text)[Size])
{
std::string path = text;
ClangBackEnd::FilePath path = text;
if (Utils::HostOsInfo::isWindowsHost())
std::replace(path.begin(), path.end(), '/', '\\');
return path;
return ClangBackEnd::NativeFilePath{path};
}
inline
std::string toNativePath(const QString &qStringPath)
inline ClangBackEnd::NativeFilePath toNativePath(const QString &text)
{
auto path = qStringPath.toStdString();
ClangBackEnd::FilePath path{text};
if (Utils::HostOsInfo::isWindowsHost())
std::replace(path.begin(), path.end(), '/', '\\');
return path;
return ClangBackEnd::NativeFilePath{path};
}
inline ClangBackEnd::NativeFilePath toNativePath(Utils::SmallStringView text)
{
ClangBackEnd::FilePath path{text};
return ClangBackEnd::NativeFilePath{path};
}

View File

@@ -69,10 +69,24 @@
#include <coreplugin/find/searchresultitem.h>
#include <coreplugin/locator/ilocatorfilter.h>
#include <clang/Tooling/CompilationDatabase.h>
namespace {
ClangBackEnd::FilePathCaching *filePathCache = nullptr;
}
namespace clang {
namespace tooling {
struct CompileCommand;
std::ostream &operator<<(std::ostream &out, const CompileCommand &command)
{
return out << "(" << command.Directory << ", " << command.Filename << ", "
<< command.CommandLine << ", " << command.Output << ")";
}
} // namespace tooling
} // namespace clang
void PrintTo(const Utf8String &text, ::std::ostream *os)
{
*os << text;

View File

@@ -40,6 +40,14 @@
class Utf8String;
void PrintTo(const Utf8String &text, ::std::ostream *os);
namespace clang {
namespace tooling {
struct CompileCommand;
std::ostream &operator<<(std::ostream &out, const CompileCommand &command);
} // namespace tooling
} // namespace clang
namespace Core {
class LocatorFilterEntry;

View File

@@ -25,6 +25,7 @@
#include "googletest.h"
#include <filepath.h>
#include <nativefilepath.h>
namespace {

View File

@@ -26,6 +26,7 @@
#include "googletest.h"
#include "fakeprocess.h"
#include "filesystem-utilities.h"
#include "mockclangpathwatcher.h"
#include "mockpchmanagerclient.h"
@@ -144,11 +145,11 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArguments)
"-nostdinc",
"-nostdinc++",
"-I",
TESTDATA_DIR "/builddependencycollector/project",
toNativePath(TESTDATA_DIR "/builddependencycollector/project").path(),
"-isystem",
TESTDATA_DIR "/builddependencycollector/external",
toNativePath(TESTDATA_DIR "/builddependencycollector/external").path(),
"-isystem",
TESTDATA_DIR "/builddependencycollector/system",
toNativePath(TESTDATA_DIR "/builddependencycollector/system").path(),
"-o",
"project.pch",
"project.h"));
@@ -170,11 +171,11 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArgumentsWithSystemPch)
"-nostdinc",
"-nostdinc++",
"-I",
TESTDATA_DIR "/builddependencycollector/project",
toNativePath(TESTDATA_DIR "/builddependencycollector/project").path(),
"-isystem",
TESTDATA_DIR "/builddependencycollector/external",
toNativePath(TESTDATA_DIR "/builddependencycollector/external").path(),
"-isystem",
TESTDATA_DIR "/builddependencycollector/system",
toNativePath(TESTDATA_DIR "/builddependencycollector/system").path(),
"-Xclang",
"-include-pch",
"-Xclang",

View File

@@ -24,8 +24,10 @@
****************************************************************************/
#include "googletest.h"
#include "filesystem-utilities.h"
#include <refactoringcompilationdatabase.h>
#include <nativefilepath.h>
#include <utils/smallstring.h>
@@ -38,16 +40,16 @@ using testing::PrintToString;
namespace {
MATCHER_P3(IsCompileCommand, directory, fileName, commandLine,
std::string(negation ? "isn't" : "is")
+ " compile command with directory "+ PrintToString(directory)
+ ", file name " + PrintToString(fileName)
+ " and command line " + PrintToString(commandLine)
)
MATCHER_P3(IsCompileCommand,
directory,
filePath,
commandLine,
std::string(negation ? "isn't" : "is") + " compile command with directory "
+ PrintToString(directory) + ", file name " + PrintToString(filePath)
+ " and command line " + PrintToString(commandLine))
{
if (arg.Directory != directory
|| arg.Filename != fileName
|| arg.CommandLine != commandLine)
if (arg.Directory != std::string(directory) || arg.Filename != std::string(filePath)
|| arg.CommandLine != commandLine)
return false;
return true;
@@ -56,7 +58,11 @@ MATCHER_P3(IsCompileCommand, directory, fileName, commandLine,
class RefactoringCompilationDatabase : public ::testing::Test
{
protected:
void SetUp();
RefactoringCompilationDatabase()
{
database.addFile(ClangBackEnd::NativeFilePathView{temporarySourceFilePath},
{"cc", toNativePath(temporaryDirectoryPath + "/data.cpp").path(), "-DNO_DEBUG"});
}
protected:
ClangBackEnd::RefactoringCompilationDatabase database;
@@ -76,18 +82,28 @@ TEST_F(RefactoringCompilationDatabase, CompileCommandForFilePath)
{
auto compileCommands = database.getAllCompileCommands();
ASSERT_THAT(compileCommands, Contains(IsCompileCommand(temporaryDirectoryPath,
"data.cpp",
std::vector<std::string>{"cc", "data.cpp", "-DNO_DEBUG"})));
ASSERT_THAT(compileCommands,
Contains(IsCompileCommand(
temporaryDirectoryPath,
toNativePath(temporaryDirectoryPath + "/data.cpp").path(),
std::vector<std::string>{
"cc",
std::string(toNativePath(temporaryDirectoryPath + "/data.cpp").path()),
"-DNO_DEBUG"})));
}
TEST_F(RefactoringCompilationDatabase, NoCompileCommandForFilePath)
{
auto compileCommands = database.getAllCompileCommands();
ASSERT_THAT(compileCommands, Not(Contains(IsCompileCommand(temporaryDirectoryPath,
"data.cpp2",
std::vector<std::string>{"cc", "data.cpp", "-DNO_DEBUG"}))));
ASSERT_THAT(compileCommands,
Not(Contains(IsCompileCommand(
temporaryDirectoryPath,
toNativePath(temporaryDirectoryPath + "/data.cpp2").path(),
std::vector<std::string>{
"cc",
std::string(toNativePath(temporaryDirectoryPath + "/data.cpp").path()),
"-DNO_DEBUG"}))));
}
TEST_F(RefactoringCompilationDatabase, FilePaths)
@@ -96,10 +112,4 @@ TEST_F(RefactoringCompilationDatabase, FilePaths)
ASSERT_THAT(filePaths, Contains(std::string(temporarySourceFilePath)));
}
void RefactoringCompilationDatabase::SetUp()
{
database.addFile(std::string(temporaryDirectoryPath), "data.cpp", {"cc", "data.cpp", "-DNO_DEBUG"});
}
}
} // namespace

View File

@@ -102,8 +102,9 @@ protected:
Utils::SmallString sourceContent{"void f()\n {}"};
FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"},
sourceContent.clone(),
{"cc", toNativePath(TESTDATA_DIR"/query_simplefunction.cpp")}};
QTemporaryFile temporaryFile{Utils::TemporaryDirectory::masterDirectoryPath() + "/clangQuery-XXXXXX.cpp"};
{"cc", toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path()}};
QTemporaryFile temporaryFile{Utils::TemporaryDirectory::masterDirectoryPath()
+ "/clangQuery-XXXXXX.cpp"};
int processingSlotCount = 2;
};
@@ -266,10 +267,11 @@ TEST_F(RefactoringServer, PollTimerNotIsActiveAfterCanceling)
TEST_F(RefactoringServerSlowTest, ForValidRequestSourceRangesAndDiagnosticsGetSourceRange)
{
RequestSourceRangesAndDiagnosticsForQueryMessage message("functionDecl()",
{FilePath(temporaryFile.fileName()),
"void f() {}",
{"cc", toNativePath(temporaryFile.fileName())}});
RequestSourceRangesAndDiagnosticsForQueryMessage message(
"functionDecl()",
{FilePath(temporaryFile.fileName()),
"void f() {}",
{"cc", toNativePath(temporaryFile.fileName()).path()}});
EXPECT_CALL(mockRefactoringClient,
sourceRangesAndDiagnosticsForQueryMessage(
@@ -285,10 +287,11 @@ TEST_F(RefactoringServerSlowTest, ForValidRequestSourceRangesAndDiagnosticsGetSo
TEST_F(RefactoringServerSlowTest, ForInvalidRequestSourceRangesAndDiagnosticsGetDiagnostics)
{
RequestSourceRangesAndDiagnosticsForQueryMessage message("func()",
{FilePath(temporaryFile.fileName()),
"void f() {}",
{"cc", toNativePath(temporaryFile.fileName())}});
RequestSourceRangesAndDiagnosticsForQueryMessage message(
"func()",
{FilePath(temporaryFile.fileName()),
"void f() {}",
{"cc", toNativePath(temporaryFile.fileName()).path()}});
EXPECT_CALL(mockRefactoringClient,
sourceRangesAndDiagnosticsForQueryMessage(

View File

@@ -57,7 +57,9 @@ protected:
void TearDown() override;
protected:
TestClangTool clangTool{TESTDATA_DIR, "sourcerangeextractor_location.cpp", "", {"cc", "sourcerangeextractor_location.cpp"}};
TestClangTool clangTool{{TESTDATA_DIR "/sourcerangeextractor_location.cpp"},
"",
{"cc", "sourcerangeextractor_location.cpp"}};
ClangBackEnd::SourceRangesContainer sourceRangesContainer;
const clang::SourceManager &sourceManager{clangTool.sourceManager()};
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};

View File

@@ -31,28 +31,30 @@
#include "filesystem-utilities.h"
using ClangBackEnd::SymbolFinder;
using ClangBackEnd::FileContent;
using ClangBackEnd::FilePathView;
using ClangBackEnd::NativeFilePath;
using ClangBackEnd::NativeFilePathView;
using ClangBackEnd::SymbolFinder;
namespace {
MATCHER_P2(IsSourceLocation, line, column,
std::string(negation ? "isn't" : "is")
+ "line " + PrintToString(line)
+ ", column " + PrintToString(column)
)
inline bool operator==(const ClangBackEnd::NativeFilePath &first, const std::string &second)
{
return first.path() == second;
}
MATCHER_P2(IsSourceLocation,
line,
column,
std::string(negation ? "isn't" : "is") + "line " + PrintToString(line) + ", column "
+ PrintToString(column))
{
return arg.line == uint(line) && arg.column == uint(column);
}
MATCHER_P(StrEq, text,
std::string(negation ? "isn't" : "is")
+ " text " + PrintToString(text)
)
MATCHER_P(StrEq, text, std::string(negation ? "isn't" : "is") + " text " + PrintToString(text))
{
return std::string(arg.data(), arg.size()) == std::string(text);
}
using Finder = SymbolFinder;
class SymbolFinder : public testing::Test
@@ -65,7 +67,7 @@ using SymbolFinderSlowTest = SymbolFinder;
TEST_F(SymbolFinder, FileContentFilePath)
{
FileContent fileContent(toNativePath("/tmp"), "data.cpp", "int variable;", {"cc", "data.cpp"});
FileContent fileContent(NativeFilePath{FilePathView{"/tmp/data.cpp"}}, "int variable;");
ASSERT_THAT(fileContent.filePath, toNativePath("/tmp/data.cpp"));
}
@@ -73,7 +75,9 @@ TEST_F(SymbolFinder, FileContentFilePath)
TEST_F(SymbolFinderSlowTest, FindName)
{
Finder finder(1, 5, filePathCaching);
finder.addFile(TESTDATA_DIR, "renamevariable.cpp", "int variable;", {"cc", "renamevariable.cpp"});
finder.addFile({TESTDATA_DIR "/renamevariable.cpp"},
"int variable;",
{"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path()});
finder.findSymbol();
@@ -83,7 +87,9 @@ TEST_F(SymbolFinderSlowTest, FindName)
TEST_F(SymbolFinderSlowTest, FindNameInUnsavedFile)
{
Finder finder(1, 5, filePathCaching);
finder.addFile(TESTDATA_DIR, "renamevariable.cpp", "int newVariable;", {"cc", "renamevariable.cpp"});
finder.addFile({TESTDATA_DIR "/renamevariable.cpp"},
"int newVariable;",
{"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path()});
finder.findSymbol();
@@ -93,7 +99,9 @@ TEST_F(SymbolFinderSlowTest, FindNameInUnsavedFile)
TEST_F(SymbolFinderSlowTest, FindUsrs)
{
Finder finder(1, 5, filePathCaching);
finder.addFile(TESTDATA_DIR, "renamevariable.cpp", "int variable;", {"cc", "renamevariable.cpp", "-std=c++14"});
finder.addFile({TESTDATA_DIR "/renamevariable.cpp"},
"int variable;",
{"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"});
finder.findSymbol();
@@ -103,7 +111,9 @@ TEST_F(SymbolFinderSlowTest, FindUsrs)
TEST_F(SymbolFinderSlowTest, VariableDeclarationSourceLocations)
{
Finder finder(1, 5, filePathCaching);
finder.addFile(TESTDATA_DIR, "renamevariable.cpp", "", {"cc", "renamevariable.cpp", "-std=c++14"});
finder.addFile({TESTDATA_DIR "/renamevariable.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"});
finder.findSymbol();
@@ -115,7 +125,9 @@ TEST_F(SymbolFinderSlowTest, VariableDeclarationSourceLocations)
TEST_F(SymbolFinderSlowTest, VariableUsageSourceLocations)
{
Finder finder(3, 9, filePathCaching);
finder.addFile(TESTDATA_DIR, "renamevariable.cpp", "", {"cc", "renamevariable.cpp", "-std=c++14"});
finder.addFile({TESTDATA_DIR "/renamevariable.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"});
finder.findSymbol();
@@ -127,7 +139,9 @@ TEST_F(SymbolFinderSlowTest, VariableUsageSourceLocations)
TEST_F(SymbolFinderSlowTest, TemplateMemberVariableDeclarationSourceLocations)
{
Finder finder(8, 18, filePathCaching);
finder.addFile(TESTDATA_DIR, "renamevariable.cpp", "", {"cc", "renamevariable.cpp", "-std=c++14"});
finder.addFile({TESTDATA_DIR "/renamevariable.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"});
finder.findSymbol();
@@ -140,7 +154,9 @@ TEST_F(SymbolFinderSlowTest, TemplateMemberVariableDeclarationSourceLocations)
TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageSourceLocations)
{
Finder finder(15, 14, filePathCaching);
finder.addFile(TESTDATA_DIR, "renamevariable.cpp", "", {"cc", "renamevariable.cpp", "-std=c++14"});
finder.addFile({TESTDATA_DIR "/renamevariable.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"});
finder.findSymbol();
@@ -153,7 +169,9 @@ TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageSourceLocations)
TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageInLambdaSourceLocations)
{
Finder finder(18, 19, filePathCaching);
finder.addFile(TESTDATA_DIR, "renamevariable.cpp", "", {"cc", "renamevariable.cpp", "-std=c++14"});
finder.addFile({TESTDATA_DIR "/renamevariable.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"});
finder.findSymbol();
@@ -166,7 +184,9 @@ TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageInLambdaSourceLocations)
TEST_F(SymbolFinderSlowTest, CursorOverMacroDefintionSymbolName)
{
Finder finder(1, 9, filePathCaching);
finder.addFile(TESTDATA_DIR, "symbolfinder_macro.cpp", "", {"cc", "symbolfinder_macro.cpp"});
finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()});
finder.findSymbol();
@@ -176,7 +196,9 @@ TEST_F(SymbolFinderSlowTest, CursorOverMacroDefintionSymbolName)
TEST_F(SymbolFinderSlowTest, CursorOverMacroExpansionSymbolName)
{
Finder finder(10, 10, filePathCaching);
finder.addFile(TESTDATA_DIR, "symbolfinder_macro.cpp", "", {"cc", "symbolfinder_macro.cpp"});
finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()});
finder.findSymbol();
@@ -186,7 +208,9 @@ TEST_F(SymbolFinderSlowTest, CursorOverMacroExpansionSymbolName)
TEST_F(SymbolFinderSlowTest, FindMacroDefinition)
{
Finder finder(1, 9, filePathCaching);
finder.addFile(TESTDATA_DIR, "symbolfinder_macro.cpp", "", {"cc", "symbolfinder_macro.cpp"});
finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()});
finder.findSymbol();
@@ -197,7 +221,9 @@ TEST_F(SymbolFinderSlowTest, FindMacroDefinition)
TEST_F(SymbolFinderSlowTest, FindMacroExpansion)
{
Finder finder(1, 9, filePathCaching);
finder.addFile(TESTDATA_DIR, "symbolfinder_macro.cpp", "", {"cc", "symbolfinder_macro.cpp"});
finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()});
finder.findSymbol();
@@ -208,7 +234,9 @@ TEST_F(SymbolFinderSlowTest, FindMacroExpansion)
TEST_F(SymbolFinderSlowTest, DoNotFindUndedefinedMacroExpansion)
{
Finder finder(1, 9, filePathCaching);
finder.addFile(TESTDATA_DIR, "symbolfinder_macro.cpp", "", {"cc", "symbolfinder_macro.cpp"});
finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()});
finder.findSymbol();
@@ -219,7 +247,9 @@ TEST_F(SymbolFinderSlowTest, DoNotFindUndedefinedMacroExpansion)
TEST_F(SymbolFinderSlowTest, FindMacroDefinitionFromMacroExpansion)
{
Finder finder(10, 10, filePathCaching);
finder.addFile(TESTDATA_DIR, "symbolfinder_macro.cpp", "", {"cc", "symbolfinder_macro.cpp"});
finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()});
finder.findSymbol();
@@ -231,7 +261,9 @@ TEST_F(SymbolFinderSlowTest, FindMacroDefinitionFromMacroExpansion)
TEST_F(SymbolFinderSlowTest, FindMacroExpansionBeforeMacroExpansionWithCursor)
{
Finder finder(12, 10, filePathCaching);
finder.addFile(TESTDATA_DIR, "symbolfinder_macro.cpp", "", {"cc", "symbolfinder_macro.cpp"});
finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()});
finder.findSymbol();
@@ -242,7 +274,9 @@ TEST_F(SymbolFinderSlowTest, FindMacroExpansionBeforeMacroExpansionWithCursor)
TEST_F(SymbolFinderSlowTest, FindMacroExpansionAfterMacroExpansionWithCursor)
{
Finder finder(10, 10, filePathCaching);
finder.addFile(TESTDATA_DIR, "symbolfinder_macro.cpp", "", {"cc", "symbolfinder_macro.cpp"});
finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"},
"",
{"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()});
finder.findSymbol();
@@ -250,4 +284,4 @@ TEST_F(SymbolFinderSlowTest, FindMacroExpansionAfterMacroExpansionWithCursor)
Contains(IsSourceLocation(12, 10)));
}
}
} // namespace

View File

@@ -24,6 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "filesystem-utilities.h"
#include "mockclangpathwatcher.h"
#include "mocksymbolscollector.h"
#include "mocksymbolstorage.h"
@@ -273,15 +274,15 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector)
"-DBAR=1",
"-DFOO=1",
"-I",
"/project/includes",
toNativePath("/project/includes").path(),
"-I",
"/other/project/includes",
toNativePath("/other/project/includes").path(),
"-isystem",
TESTDATA_DIR,
toNativePath(TESTDATA_DIR).path(),
"-isystem",
"/other/includes",
toNativePath("/other/includes").path(),
"-isystem",
"/includes")));
toNativePath("/includes").path())));
indexer.updateProjectParts({projectPart1});
}
@@ -303,19 +304,19 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInColl
"-DBAR=1",
"-DFOO=1",
"-I",
"/project/includes",
toNativePath("/project/includes").path(),
"-I",
"/other/project/includes",
toNativePath("/other/project/includes").path(),
"-isystem",
TESTDATA_DIR,
toNativePath(TESTDATA_DIR).path(),
"-isystem",
"/other/includes",
toNativePath("/other/includes").path(),
"-isystem",
"/includes",
toNativePath("/includes").path(),
"-Xclang",
"-include-pch",
"-Xclang",
"/path/to/pch")));
toNativePath("/path/to/pch").path())));
indexer.updateProjectParts({projectPart1});
}
@@ -336,15 +337,15 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInC
"-DBAR=1",
"-DFOO=1",
"-I",
"/project/includes",
toNativePath("/project/includes").path(),
"-I",
"/other/project/includes",
toNativePath("/other/project/includes").path(),
"-isystem",
TESTDATA_DIR,
toNativePath(TESTDATA_DIR).path(),
"-isystem",
"/other/includes",
toNativePath("/other/includes").path(),
"-isystem",
"/includes")));
toNativePath("/includes").path())));
indexer.updateProjectParts({projectPart1});
}
@@ -516,15 +517,15 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact)
"-DBAR=1",
"-DFOO=1",
"-I",
"/project/includes",
toNativePath("/project/includes").path(),
"-I",
"/other/project/includes",
toNativePath("/other/project/includes").path(),
"-isystem",
TESTDATA_DIR,
toNativePath(TESTDATA_DIR).path(),
"-isystem",
"/other/includes",
toNativePath("/other/includes").path(),
"-isystem",
"/includes")));
toNativePath("/includes").path())));
EXPECT_CALL(mockCollector, collectSymbols());
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
@@ -568,15 +569,15 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact)
"-DBAR=1",
"-DFOO=1",
"-I",
"/project/includes",
toNativePath("/project/includes").path(),
"-I",
"/other/project/includes",
toNativePath("/other/project/includes").path(),
"-isystem",
TESTDATA_DIR,
toNativePath(TESTDATA_DIR).path(),
"-isystem",
"/other/includes",
toNativePath("/other/includes").path(),
"-isystem",
"/includes")));
toNativePath("/includes").path())));
EXPECT_CALL(mockCollector, collectSymbols());
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
@@ -624,15 +625,15 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder)
"-DBAR=1",
"-DFOO=1",
"-I",
"/project/includes",
toNativePath("/project/includes").path(),
"-I",
"/other/project/includes",
toNativePath("/other/project/includes").path(),
"-isystem",
TESTDATA_DIR,
toNativePath(TESTDATA_DIR).path(),
"-isystem",
"/other/includes",
toNativePath("/other/includes").path(),
"-isystem",
"/includes")));
toNativePath("/includes").path())));
EXPECT_CALL(mockCollector, collectSymbols());
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
@@ -686,19 +687,19 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader)
"-DBAR=1",
"-DFOO=1",
"-I",
"/project/includes",
toNativePath("/project/includes").path(),
"-I",
"/other/project/includes",
toNativePath("/other/project/includes").path(),
"-isystem",
TESTDATA_DIR,
toNativePath(TESTDATA_DIR).path(),
"-isystem",
"/other/includes",
toNativePath("/other/includes").path(),
"-isystem",
"/includes",
toNativePath("/includes").path(),
"-Xclang",
"-include-pch",
"-Xclang",
"/path/to/pch")));
toNativePath("/path/to/pch").path())));
indexer.pathsChanged({sourceFileIds[0]});
}
@@ -721,15 +722,15 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists)
"-DBAR=1",
"-DFOO=1",
"-I",
"/project/includes",
toNativePath("/project/includes").path(),
"-I",
"/other/project/includes",
toNativePath("/other/project/includes").path(),
"-isystem",
TESTDATA_DIR,
toNativePath(TESTDATA_DIR).path(),
"-isystem",
"/other/includes",
toNativePath("/other/includes").path(),
"-isystem",
"/includes")));
toNativePath("/includes").path())));
indexer.pathsChanged({sourceFileIds[0]});
}

View File

@@ -25,12 +25,11 @@
#include "testclangtool.h"
TestClangTool::TestClangTool(std::string &&directory,
std::string &&fileName,
std::string &&content,
std::vector<std::string> &&commandLine)
TestClangTool::TestClangTool(ClangBackEnd::FilePath &&filePath,
Utils::SmallString &&content,
Utils::SmallStringVector &&commandLine)
{
addFile(std::move(directory), std::move(fileName), std::move(content), std::move(commandLine));
addFile(std::move(filePath), std::move(content), std::move(commandLine));
auto clangTool = createTool();

View File

@@ -30,10 +30,9 @@
class TestClangTool : public ClangBackEnd::ClangTool
{
public:
TestClangTool(std::string &&directory,
std::string &&fileName,
std::string &&content,
std::vector<std::string> &&commandLine);
TestClangTool(ClangBackEnd::FilePath &&filePath,
Utils::SmallString &&content,
Utils::SmallStringVector &&commandLine);
const clang::ASTUnit *ast() const;
const clang::SourceManager &sourceManager() const;