forked from qt-creator/qt-creator
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:
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "filepathview.h"
|
#include "filepath.h"
|
||||||
|
|
||||||
#include <compilermacro.h>
|
#include <compilermacro.h>
|
||||||
#include <includesearchpath.h>
|
#include <includesearchpath.h>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
template<typename ProjectInfo, typename OutputContainer = std::vector<std::string>>
|
template<typename ProjectInfo, typename OutputContainer = Utils::SmallStringVector>
|
||||||
class CommandLineBuilder
|
class CommandLineBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -213,7 +213,7 @@ public:
|
|||||||
{
|
{
|
||||||
for (const IncludeSearchPath &path : projectIncludeSearchPaths) {
|
for (const IncludeSearchPath &path : projectIncludeSearchPaths) {
|
||||||
commandLine.emplace_back("-I");
|
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) {
|
for (const IncludeSearchPath &path : systemIncludeSearchPaths) {
|
||||||
if (path.type != IncludeSearchPathType::BuiltIn) {
|
if (path.type != IncludeSearchPathType::BuiltIn) {
|
||||||
commandLine.emplace_back(includeOption(path.type));
|
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) {
|
for (const IncludeSearchPath &path : systemIncludeSearchPaths) {
|
||||||
if (path.type == IncludeSearchPathType::BuiltIn) {
|
if (path.type == IncludeSearchPathType::BuiltIn) {
|
||||||
commandLine.emplace_back(includeOption(path.type));
|
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()) {
|
if (!outputPath.isEmpty()) {
|
||||||
commandLine.emplace_back("-o");
|
commandLine.emplace_back("-o");
|
||||||
commandLine.emplace_back(outputPath);
|
commandLine.emplace_back(NativeFilePath(outputPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addSourcePath(FilePathView sourcePath)
|
void addSourcePath(FilePathView sourcePath)
|
||||||
{
|
{
|
||||||
if (!sourcePath.isEmpty())
|
if (!sourcePath.isEmpty())
|
||||||
commandLine.emplace_back(sourcePath);
|
commandLine.emplace_back(NativeFilePath(sourcePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addIncludePchPath(FilePathView includePchPath)
|
void addIncludePchPath(FilePathView includePchPath)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!includePchPath.isEmpty()) {
|
if (!includePchPath.isEmpty()) {
|
||||||
commandLine.emplace_back("-Xclang");
|
commandLine.emplace_back("-Xclang");
|
||||||
commandLine.emplace_back("-include-pch");
|
commandLine.emplace_back("-include-pch");
|
||||||
commandLine.emplace_back("-Xclang");
|
commandLine.emplace_back("-Xclang");
|
||||||
commandLine.emplace_back(includePchPath);
|
commandLine.emplace_back(NativeFilePath(includePchPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "clangsupport_global.h"
|
#include "clangsupport_global.h"
|
||||||
|
|
||||||
#include "filepathview.h"
|
#include "filepathview.h"
|
||||||
#include "filepathview.h"
|
#include "nativefilepath.h"
|
||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/smallstringio.h>
|
#include <utils/smallstringio.h>
|
||||||
@@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
|
class NativeFilePath;
|
||||||
|
|
||||||
class FilePath : public Utils::PathString
|
class FilePath : public Utils::PathString
|
||||||
{
|
{
|
||||||
using size_type = Utils::PathString::size_type;
|
using size_type = Utils::PathString::size_type;
|
||||||
|
@@ -26,13 +26,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "filepathview.h"
|
#include "filepathview.h"
|
||||||
#include "filepathview.h"
|
#include "filepath.h"
|
||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/smallstringio.h>
|
#include <utils/smallstringio.h>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
|
class FilePath;
|
||||||
|
|
||||||
class NativeFilePath
|
class NativeFilePath
|
||||||
{
|
{
|
||||||
using size_type = Utils::PathString::size_type;
|
using size_type = Utils::PathString::size_type;
|
||||||
@@ -50,8 +52,13 @@ public:
|
|||||||
NativeFilePath(NativeFilePathView filePathView)
|
NativeFilePath(NativeFilePathView filePathView)
|
||||||
: m_path(filePathView.toStringView()),
|
: m_path(filePathView.toStringView()),
|
||||||
m_slashIndex(filePathView.slashIndex())
|
m_slashIndex(filePathView.slashIndex())
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
explicit NativeFilePath(FilePathView filePathView) { *this = fromFilePath(filePathView); }
|
||||||
|
|
||||||
|
explicit NativeFilePath(const FilePath &filePath)
|
||||||
|
: NativeFilePath{FilePathView{filePath}}
|
||||||
|
{}
|
||||||
|
|
||||||
template<size_type Size>
|
template<size_type Size>
|
||||||
NativeFilePath(const char(&string)[Size]) noexcept
|
NativeFilePath(const char(&string)[Size]) noexcept
|
||||||
|
@@ -90,8 +90,7 @@ public:
|
|||||||
SmallStringView(const String &string) noexcept
|
SmallStringView(const String &string) noexcept
|
||||||
: m_pointer(string.data()),
|
: m_pointer(string.data()),
|
||||||
m_size(string.size())
|
m_size(string.size())
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
static
|
static
|
||||||
SmallStringView fromUtf8(const char *const characterPointer)
|
SmallStringView fromUtf8(const char *const characterPointer)
|
||||||
|
@@ -94,8 +94,7 @@ FilePath PchCreator::generatePchFilePath() const
|
|||||||
".pch"}};
|
".pch"}};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> PchCreator::generateClangCompilerArguments(
|
Utils::SmallStringVector PchCreator::generateClangCompilerArguments(const PchTask &pchTask,
|
||||||
const PchTask &pchTask,
|
|
||||||
FilePathView sourceFilePath,
|
FilePathView sourceFilePath,
|
||||||
FilePathView pchOutputPath)
|
FilePathView pchOutputPath)
|
||||||
{
|
{
|
||||||
@@ -114,10 +113,12 @@ void PchCreator::generatePch(PchTask &&pchTask)
|
|||||||
auto content = generatePchIncludeFileContent(pchTask.includes);
|
auto content = generatePchIncludeFileContent(pchTask.includes);
|
||||||
auto pchOutputPath = generatePchFilePath();
|
auto pchOutputPath = generatePchFilePath();
|
||||||
|
|
||||||
m_clangTool.addFile(m_environment.pchBuildDirectory().toStdString(),
|
FilePath headerFilePath{m_environment.pchBuildDirectory().toStdString(), "dummy.h"};
|
||||||
"dummy.h",
|
Utils::SmallStringVector commandLine = generateClangCompilerArguments(pchTask,
|
||||||
Utils::SmallStringView(content),
|
headerFilePath,
|
||||||
generateClangCompilerArguments(pchTask, "dummy.h", pchOutputPath));
|
pchOutputPath);
|
||||||
|
|
||||||
|
m_clangTool.addFile(std::move(headerFilePath), std::move(content), std::move(commandLine));
|
||||||
|
|
||||||
bool success = generatePch();
|
bool success = generatePch();
|
||||||
|
|
||||||
|
@@ -84,7 +84,7 @@ public:
|
|||||||
bool generatePch();
|
bool generatePch();
|
||||||
|
|
||||||
FilePath generatePchFilePath() const;
|
FilePath generatePchFilePath() const;
|
||||||
static std::vector<std::string> generateClangCompilerArguments(const PchTask &pchTask,
|
static Utils::SmallStringVector generateClangCompilerArguments(const PchTask &pchTask,
|
||||||
FilePathView includePchHeaderPath,
|
FilePathView includePchHeaderPath,
|
||||||
FilePathView pchPath);
|
FilePathView pchPath);
|
||||||
|
|
||||||
|
@@ -50,10 +50,9 @@ ClangQueryGatherer::createSourceRangesForSource(
|
|||||||
{
|
{
|
||||||
ClangQuery clangQuery(*filePathCache, std::move(query));
|
ClangQuery clangQuery(*filePathCache, std::move(query));
|
||||||
|
|
||||||
clangQuery.addFile(std::string(source.filePath.directory()),
|
clangQuery.addFile(std::move(source.filePath),
|
||||||
std::string(source.filePath.name()),
|
std::move(source.unsavedFileContent),
|
||||||
std::string(source.unsavedFileContent),
|
std::move(source.commandLineArguments));
|
||||||
std::vector<std::string>(source.commandLineArguments));
|
|
||||||
|
|
||||||
clangQuery.addUnsavedFiles(unsaved);
|
clangQuery.addUnsavedFiles(unsaved);
|
||||||
|
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <nativefilepath.h>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -44,67 +46,37 @@ String toNativePath(String &&path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangTool::addFile(std::string &&directory,
|
void ClangTool::addFile(FilePath &&filePath,
|
||||||
std::string &&fileName,
|
Utils::SmallString &&content,
|
||||||
std::string &&content,
|
Utils::SmallStringVector &&commandLine)
|
||||||
std::vector<std::string> &&commandLine)
|
|
||||||
{
|
{
|
||||||
m_fileContents.emplace_back(toNativePath(std::move(directory)),
|
NativeFilePath nativeFilePath{filePath};
|
||||||
std::move(fileName),
|
|
||||||
std::move(content),
|
|
||||||
std::move(commandLine));
|
|
||||||
|
|
||||||
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_fileContents.emplace_back(std::move(nativeFilePath), std::move(content));
|
||||||
m_sourceFilePaths.push_back(fileContent.filePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangTool::addFiles(const FilePaths &filePaths, const Utils::SmallStringVector &arguments)
|
void ClangTool::addFiles(const FilePaths &filePaths, const Utils::SmallStringVector &arguments)
|
||||||
{
|
{
|
||||||
for (const FilePath &filePath : filePaths) {
|
for (const FilePath &filePath : filePaths) {
|
||||||
std::vector<std::string> commandLine(arguments.begin(), arguments.end());
|
std::string filePathStr(filePath.path());
|
||||||
commandLine.push_back(std::string(filePath.name()));
|
auto commandLine = arguments;
|
||||||
|
NativeFilePath nativeFilePath{filePath};
|
||||||
|
|
||||||
addFile(filePath.directory(),
|
commandLine.push_back(nativeFilePath.path());
|
||||||
filePath.name(),
|
|
||||||
{},
|
addFile(filePath.clone(), {}, std::move(commandLine));
|
||||||
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)
|
void ClangTool::addUnsavedFiles(const V2::FileContainers &unsavedFiles)
|
||||||
{
|
{
|
||||||
m_unsavedFileContents.reserve(m_unsavedFileContents.size() + unsavedFiles.size());
|
m_unsavedFileContents.reserve(m_unsavedFileContents.size() + unsavedFiles.size());
|
||||||
|
|
||||||
auto convertToUnsavedFileContent = [](const V2::FileContainer &unsavedFile) {
|
auto convertToUnsavedFileContent = [](const V2::FileContainer &unsavedFile) {
|
||||||
return UnsavedFileContent{toNativePath(unsavedFile.filePath.path().clone()),
|
return UnsavedFileContent{NativeFilePath{unsavedFile.filePath},
|
||||||
unsavedFile.unsavedFileContent.clone()};
|
unsavedFile.unsavedFileContent.clone()};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -120,7 +92,12 @@ llvm::StringRef toStringRef(const String &string)
|
|||||||
{
|
{
|
||||||
return llvm::StringRef(string.data(), string.size());
|
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
|
clang::tooling::ClangTool ClangTool::createTool() const
|
||||||
{
|
{
|
||||||
@@ -128,7 +105,7 @@ clang::tooling::ClangTool ClangTool::createTool() const
|
|||||||
|
|
||||||
for (const auto &fileContent : m_fileContents) {
|
for (const auto &fileContent : m_fileContents) {
|
||||||
if (!fileContent.content.empty())
|
if (!fileContent.content.empty())
|
||||||
tool.mapVirtualFile(fileContent.filePath, fileContent.content);
|
tool.mapVirtualFile(toStringRef(fileContent.filePath), fileContent.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &unsavedFileContent : m_unsavedFileContents)
|
for (const auto &unsavedFileContent : m_unsavedFileContents)
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <clangrefactoringbackend_global.h>
|
#include <clangrefactoringbackend_global.h>
|
||||||
|
|
||||||
#include <filecontainerv2.h>
|
#include <filecontainerv2.h>
|
||||||
|
#include <nativefilepath.h>
|
||||||
#include <sourcelocationscontainer.h>
|
#include <sourcelocationscontainer.h>
|
||||||
|
|
||||||
#include <clang/Tooling/Refactoring.h>
|
#include <clang/Tooling/Refactoring.h>
|
||||||
@@ -43,50 +44,34 @@ namespace ClangBackEnd {
|
|||||||
|
|
||||||
struct FileContent
|
struct FileContent
|
||||||
{
|
{
|
||||||
FileContent(const std::string &directory,
|
FileContent(NativeFilePath &&filePath, const Utils::SmallString &content)
|
||||||
const std::string &fileName,
|
: filePath(std::move(filePath))
|
||||||
const std::string &content,
|
, content(std::move(content))
|
||||||
const std::vector<std::string> &commandLine)
|
|
||||||
: directory(directory),
|
|
||||||
fileName(fileName),
|
|
||||||
filePath(directory + nativeSeparator + fileName),
|
|
||||||
content(content),
|
|
||||||
commandLine(commandLine)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string directory;
|
NativeFilePath filePath;
|
||||||
std::string fileName;
|
|
||||||
std::string filePath;
|
|
||||||
std::string content;
|
std::string content;
|
||||||
std::vector<std::string> commandLine;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UnsavedFileContent
|
struct UnsavedFileContent
|
||||||
{
|
{
|
||||||
UnsavedFileContent(Utils::PathString &&filePath,
|
UnsavedFileContent(NativeFilePath &&filePath, Utils::SmallString &&content)
|
||||||
Utils::SmallString &&content)
|
: filePath(std::move(filePath))
|
||||||
: filePath(std::move(filePath)),
|
, content(std::move(content))
|
||||||
content(std::move(content))
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Utils::PathString filePath;
|
NativeFilePath filePath;
|
||||||
Utils::SmallString content;
|
Utils::SmallString content;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClangTool
|
class ClangTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void addFile(std::string &&directory,
|
void addFile(FilePath &&filePath,
|
||||||
std::string &&fileName,
|
Utils::SmallString &&content,
|
||||||
std::string &&content,
|
Utils::SmallStringVector &&commandLine);
|
||||||
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 addFiles(const FilePaths &filePaths, const Utils::SmallStringVector &arguments);
|
||||||
|
|
||||||
void addUnsavedFiles(const V2::FileContainers &unsavedFiles);
|
void addUnsavedFiles(const V2::FileContainers &unsavedFiles);
|
||||||
|
|
||||||
@@ -102,11 +87,4 @@ private:
|
|||||||
std::vector<UnsavedFileContent> m_unsavedFileContents;
|
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
|
} // namespace ClangBackEnd
|
||||||
|
@@ -27,20 +27,15 @@
|
|||||||
|
|
||||||
#include "clangrefactoringbackend_global.h"
|
#include "clangrefactoringbackend_global.h"
|
||||||
|
|
||||||
|
#include <filepath.h>
|
||||||
|
#include <nativefilepath.h>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
RefactoringCompilationDatabase::RefactoringCompilationDatabase()
|
RefactoringCompilationDatabase::RefactoringCompilationDatabase()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
std::string concatFilePath(const clang::tooling::CompileCommand &compileCommand)
|
|
||||||
{
|
|
||||||
return compileCommand.Directory + nativeSeparator + compileCommand.Filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<clang::tooling::CompileCommand>
|
std::vector<clang::tooling::CompileCommand>
|
||||||
RefactoringCompilationDatabase::getCompileCommands(llvm::StringRef filePath) const
|
RefactoringCompilationDatabase::getCompileCommands(llvm::StringRef filePath) const
|
||||||
{
|
{
|
||||||
@@ -50,7 +45,7 @@ RefactoringCompilationDatabase::getCompileCommands(llvm::StringRef filePath) con
|
|||||||
m_compileCommands.end(),
|
m_compileCommands.end(),
|
||||||
std::back_inserter(foundCommands),
|
std::back_inserter(foundCommands),
|
||||||
[&] (const clang::tooling::CompileCommand &compileCommand) {
|
[&] (const clang::tooling::CompileCommand &compileCommand) {
|
||||||
return filePath == concatFilePath(compileCommand);
|
return filePath == compileCommand.Filename;
|
||||||
});
|
});
|
||||||
|
|
||||||
return foundCommands;
|
return foundCommands;
|
||||||
@@ -66,7 +61,7 @@ RefactoringCompilationDatabase::getAllFiles() const
|
|||||||
m_compileCommands.end(),
|
m_compileCommands.end(),
|
||||||
std::back_inserter(filePaths),
|
std::back_inserter(filePaths),
|
||||||
[&] (const clang::tooling::CompileCommand &compileCommand) {
|
[&] (const clang::tooling::CompileCommand &compileCommand) {
|
||||||
return concatFilePath(compileCommand);
|
return compileCommand.Filename;
|
||||||
});
|
});
|
||||||
|
|
||||||
return filePaths;
|
return filePaths;
|
||||||
@@ -78,12 +73,13 @@ RefactoringCompilationDatabase::getAllCompileCommands() const
|
|||||||
return m_compileCommands;
|
return m_compileCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefactoringCompilationDatabase::addFile(const std::string &directory,
|
void RefactoringCompilationDatabase::addFile(NativeFilePathView filePath,
|
||||||
const std::string &fileName,
|
Utils::SmallStringVector &&commandLine)
|
||||||
const std::vector<std::string> &commandLine)
|
|
||||||
{
|
{
|
||||||
|
m_compileCommands.emplace_back(std::string(filePath.directory()),
|
||||||
m_compileCommands.emplace_back(directory, fileName, commandLine, llvm::StringRef());
|
std::string(filePath),
|
||||||
|
std::vector<std::string>(commandLine),
|
||||||
|
llvm::StringRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include "clang/Tooling/CompilationDatabase.h"
|
#include "clang/Tooling/CompilationDatabase.h"
|
||||||
|
|
||||||
|
#include <nativefilepath.h>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
|
|
||||||
@@ -39,9 +41,7 @@ public:
|
|||||||
std::vector<std::string> getAllFiles() const override;
|
std::vector<std::string> getAllFiles() const override;
|
||||||
std::vector<clang::tooling::CompileCommand> getAllCompileCommands() const override;
|
std::vector<clang::tooling::CompileCommand> getAllCompileCommands() const override;
|
||||||
|
|
||||||
void addFile(const std::string &directory,
|
void addFile(NativeFilePathView filePath, Utils::SmallStringVector &&commandLine);
|
||||||
const std::string &fileName,
|
|
||||||
const std::vector<std::string> &commandLine);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<clang::tooling::CompileCommand> m_compileCommands;
|
std::vector<clang::tooling::CompileCommand> m_compileCommands;
|
||||||
|
@@ -62,10 +62,9 @@ void RefactoringServer::requestSourceLocationsForRenamingMessage(RequestSourceLo
|
|||||||
{
|
{
|
||||||
SymbolFinder symbolFinder(message.line, message.column, m_filePathCache);
|
SymbolFinder symbolFinder(message.line, message.column, m_filePathCache);
|
||||||
|
|
||||||
symbolFinder.addFile(std::string(message.filePath.directory()),
|
symbolFinder.addFile(std::move(message.filePath),
|
||||||
std::string(message.filePath.name()),
|
std::move(message.unsavedContent),
|
||||||
std::string(message.unsavedContent),
|
std::move(message.commandLine));
|
||||||
std::vector<std::string>(message.commandLine));
|
|
||||||
|
|
||||||
symbolFinder.findSymbol();
|
symbolFinder.findSymbol();
|
||||||
|
|
||||||
@@ -79,10 +78,9 @@ void RefactoringServer::requestSourceRangesAndDiagnosticsForQueryMessage(
|
|||||||
{
|
{
|
||||||
ClangQuery clangQuery(m_filePathCache, message.takeQuery());
|
ClangQuery clangQuery(m_filePathCache, message.takeQuery());
|
||||||
|
|
||||||
clangQuery.addFile(std::string(message.source.filePath.directory()),
|
clangQuery.addFile(std::move(message.source.filePath),
|
||||||
std::string(message.source.filePath.name()),
|
std::move(message.source.unsavedFileContent),
|
||||||
std::string(message.source.unsavedFileContent),
|
std::move(message.source.commandLineArguments));
|
||||||
std::vector<std::string>(message.source.commandLineArguments));
|
|
||||||
|
|
||||||
clangQuery.findLocations();
|
clangQuery.findLocations();
|
||||||
|
|
||||||
|
@@ -94,7 +94,9 @@ TEST_F(ClangQuerySlowTest, RootSourceRangeForSimpleFunctionDeclarationRange)
|
|||||||
TEST_F(ClangQuerySlowTest, SourceRangeInUnsavedFileDeclarationRange)
|
TEST_F(ClangQuerySlowTest, SourceRangeInUnsavedFileDeclarationRange)
|
||||||
{
|
{
|
||||||
::ClangQuery query(filePathCache);
|
::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()");
|
query.setQuery("functionDecl()");
|
||||||
ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR, "unsaved.h"}, "void unsaved();", {}};
|
ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR, "unsaved.h"}, "void unsaved();", {}};
|
||||||
query.addUnsavedFiles({unsavedFile});
|
query.addUnsavedFiles({unsavedFile});
|
||||||
@@ -108,7 +110,9 @@ TEST_F(ClangQuerySlowTest, SourceRangeInUnsavedFileDeclarationRange)
|
|||||||
TEST_F(ClangQuerySlowTest, FileIsNotExistingButTheUnsavedDataIsParsed)
|
TEST_F(ClangQuerySlowTest, FileIsNotExistingButTheUnsavedDataIsParsed)
|
||||||
{
|
{
|
||||||
::ClangQuery query(filePathCache);
|
::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.setQuery("functionDecl()");
|
||||||
|
|
||||||
query.findLocations();
|
query.findLocations();
|
||||||
@@ -120,9 +124,13 @@ TEST_F(ClangQuerySlowTest, FileIsNotExistingButTheUnsavedDataIsParsed)
|
|||||||
TEST_F(ClangQuerySlowTest, DISABLED_SourceRangeInUnsavedFileDeclarationRangeOverride) // seems not to work in Clang
|
TEST_F(ClangQuerySlowTest, DISABLED_SourceRangeInUnsavedFileDeclarationRangeOverride) // seems not to work in Clang
|
||||||
{
|
{
|
||||||
::ClangQuery query(filePathCache);
|
::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()");
|
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.addUnsavedFiles({unsavedFile});
|
||||||
|
|
||||||
query.findLocations();
|
query.findLocations();
|
||||||
@@ -215,8 +223,15 @@ TEST_F(ClangQuerySlowTest, DiagnosticForWrongArgumenType)
|
|||||||
|
|
||||||
void ClangQuery::SetUp()
|
void ClangQuery::SetUp()
|
||||||
{
|
{
|
||||||
simpleFunctionQuery.addFile(TESTDATA_DIR, "query_simplefunction.cpp", "", {"cc", toNativePath(TESTDATA_DIR"/query_simplefunction.cpp"), "-std=c++14"});
|
simpleFunctionQuery.addFile({TESTDATA_DIR "/query_simplefunction.cpp"},
|
||||||
simpleClassQuery.addFile(TESTDATA_DIR, "query_simpleclass.cpp", "", {"cc", "query_simpleclass.cpp", "-std=c++14"});
|
"",
|
||||||
|
{"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
|
||||||
|
@@ -87,13 +87,22 @@ protected:
|
|||||||
Utils::SmallString sourceContent{"#include \"query_simplefunction.h\"\nvoid f() {}"};
|
Utils::SmallString sourceContent{"#include \"query_simplefunction.h\"\nvoid f() {}"};
|
||||||
FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"},
|
FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"},
|
||||||
sourceContent.clone(),
|
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"},
|
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"},
|
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();"};
|
Utils::SmallString unsavedContent{"void f();"};
|
||||||
FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"},
|
FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"},
|
||||||
unsavedContent.clone(),
|
unsavedContent.clone(),
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
|
||||||
|
#include "filesystem-utilities.h"
|
||||||
|
|
||||||
#include <commandlinebuilder.h>
|
#include <commandlinebuilder.h>
|
||||||
#include <pchtask.h>
|
#include <pchtask.h>
|
||||||
#include <projectpartcontainer.h>
|
#include <projectpartcontainer.h>
|
||||||
@@ -136,7 +138,7 @@ TYPED_TEST(CommandLineBuilder, CTask)
|
|||||||
|
|
||||||
ASSERT_THAT(
|
ASSERT_THAT(
|
||||||
builder.commandLine,
|
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)
|
TYPED_TEST(CommandLineBuilder, ObjectiveCTask)
|
||||||
@@ -154,7 +156,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCTask)
|
|||||||
"-std=c11",
|
"-std=c11",
|
||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-nostdinc++",
|
"-nostdinc++",
|
||||||
"/source/file.c"));
|
toNativePath("/source/file.c").path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(CommandLineBuilder, CppTask)
|
TYPED_TEST(CommandLineBuilder, CppTask)
|
||||||
@@ -171,7 +173,7 @@ TYPED_TEST(CommandLineBuilder, CppTask)
|
|||||||
"-std=c++98",
|
"-std=c++98",
|
||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-nostdinc++",
|
"-nostdinc++",
|
||||||
"/source/file.cpp"));
|
toNativePath("/source/file.cpp").path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(CommandLineBuilder, ObjectiveCppTask)
|
TYPED_TEST(CommandLineBuilder, ObjectiveCppTask)
|
||||||
@@ -189,7 +191,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCppTask)
|
|||||||
"-std=c++98",
|
"-std=c++98",
|
||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-nostdinc++",
|
"-nostdinc++",
|
||||||
"/source/file.cpp"));
|
toNativePath("/source/file.cpp").path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(CommandLineBuilder, Cpp98)
|
TYPED_TEST(CommandLineBuilder, Cpp98)
|
||||||
@@ -422,18 +424,18 @@ TYPED_TEST(CommandLineBuilder, IncludesOrder)
|
|||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-nostdinc++",
|
"-nostdinc++",
|
||||||
"-I",
|
"-I",
|
||||||
"/include/foo",
|
toNativePath("/include/foo").path(),
|
||||||
"-I",
|
"-I",
|
||||||
"/include/bar",
|
toNativePath("/include/bar").path(),
|
||||||
"-F",
|
"-F",
|
||||||
"/system/foo",
|
toNativePath("/system/foo").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/system/bar",
|
toNativePath("/system/bar").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/builtin/foo",
|
toNativePath("/builtin/foo").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/builtin/bar",
|
toNativePath("/builtin/bar").path(),
|
||||||
"/source/file.cpp"));
|
toNativePath("/source/file.cpp").path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(CommandLineBuilder, EmptySourceFile)
|
TYPED_TEST(CommandLineBuilder, EmptySourceFile)
|
||||||
@@ -455,7 +457,7 @@ TYPED_TEST(CommandLineBuilder, SourceFile)
|
|||||||
"-std=c++98",
|
"-std=c++98",
|
||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-nostdinc++",
|
"-nostdinc++",
|
||||||
"/source/file.cpp"));
|
toNativePath("/source/file.cpp").path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -470,7 +472,7 @@ TYPED_TEST(CommandLineBuilder, EmptyOutputFile)
|
|||||||
"-std=c++98",
|
"-std=c++98",
|
||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-nostdinc++",
|
"-nostdinc++",
|
||||||
"/source/file.cpp"));
|
toNativePath("/source/file.cpp").path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(CommandLineBuilder, OutputFile)
|
TYPED_TEST(CommandLineBuilder, OutputFile)
|
||||||
@@ -485,8 +487,8 @@ TYPED_TEST(CommandLineBuilder, OutputFile)
|
|||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-nostdinc++",
|
"-nostdinc++",
|
||||||
"-o",
|
"-o",
|
||||||
"/output/file.o",
|
toNativePath("/output/file.o").path(),
|
||||||
"/source/file.cpp"));
|
toNativePath("/source/file.cpp").path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(CommandLineBuilder, IncludePchPath)
|
TYPED_TEST(CommandLineBuilder, IncludePchPath)
|
||||||
@@ -503,10 +505,10 @@ TYPED_TEST(CommandLineBuilder, IncludePchPath)
|
|||||||
"-Xclang",
|
"-Xclang",
|
||||||
"-include-pch",
|
"-include-pch",
|
||||||
"-Xclang",
|
"-Xclang",
|
||||||
"/pch/file.pch",
|
toNativePath("/pch/file.pch").path(),
|
||||||
"-o",
|
"-o",
|
||||||
"/output/file.o",
|
toNativePath("/output/file.o").path(),
|
||||||
"/source/file.cpp"));
|
toNativePath("/source/file.cpp").path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(CommandLineBuilder, CompilerMacros)
|
TYPED_TEST(CommandLineBuilder, CompilerMacros)
|
||||||
|
@@ -26,32 +26,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/smallstring.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
// use std::filesystem::path if it is supported by all compilers
|
|
||||||
static const char nativeSeparator = Utils::HostOsInfo::isWindowsHost() ? '\\' : '/';
|
|
||||||
|
|
||||||
|
#include <nativefilepath.h>
|
||||||
|
|
||||||
template<std::size_t Size>
|
template<std::size_t Size>
|
||||||
std::string toNativePath(const char (&text)[Size])
|
ClangBackEnd::NativeFilePath toNativePath(const char (&text)[Size])
|
||||||
{
|
{
|
||||||
std::string path = text;
|
ClangBackEnd::FilePath path = text;
|
||||||
|
|
||||||
if (Utils::HostOsInfo::isWindowsHost())
|
return ClangBackEnd::NativeFilePath{path};
|
||||||
std::replace(path.begin(), path.end(), '/', '\\');
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline ClangBackEnd::NativeFilePath toNativePath(const QString &text)
|
||||||
std::string toNativePath(const QString &qStringPath)
|
|
||||||
{
|
{
|
||||||
auto path = qStringPath.toStdString();
|
ClangBackEnd::FilePath path{text};
|
||||||
|
|
||||||
if (Utils::HostOsInfo::isWindowsHost())
|
return ClangBackEnd::NativeFilePath{path};
|
||||||
std::replace(path.begin(), path.end(), '/', '\\');
|
}
|
||||||
|
|
||||||
return path;
|
inline ClangBackEnd::NativeFilePath toNativePath(Utils::SmallStringView text)
|
||||||
|
{
|
||||||
|
ClangBackEnd::FilePath path{text};
|
||||||
|
|
||||||
|
return ClangBackEnd::NativeFilePath{path};
|
||||||
}
|
}
|
||||||
|
@@ -69,10 +69,24 @@
|
|||||||
#include <coreplugin/find/searchresultitem.h>
|
#include <coreplugin/find/searchresultitem.h>
|
||||||
#include <coreplugin/locator/ilocatorfilter.h>
|
#include <coreplugin/locator/ilocatorfilter.h>
|
||||||
|
|
||||||
|
#include <clang/Tooling/CompilationDatabase.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
ClangBackEnd::FilePathCaching *filePathCache = nullptr;
|
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)
|
void PrintTo(const Utf8String &text, ::std::ostream *os)
|
||||||
{
|
{
|
||||||
*os << text;
|
*os << text;
|
||||||
|
@@ -40,6 +40,14 @@
|
|||||||
class Utf8String;
|
class Utf8String;
|
||||||
void PrintTo(const Utf8String &text, ::std::ostream *os);
|
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 {
|
namespace Core {
|
||||||
class LocatorFilterEntry;
|
class LocatorFilterEntry;
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
|
||||||
|
#include <filepath.h>
|
||||||
#include <nativefilepath.h>
|
#include <nativefilepath.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
|
||||||
#include "fakeprocess.h"
|
#include "fakeprocess.h"
|
||||||
|
#include "filesystem-utilities.h"
|
||||||
|
|
||||||
#include "mockclangpathwatcher.h"
|
#include "mockclangpathwatcher.h"
|
||||||
#include "mockpchmanagerclient.h"
|
#include "mockpchmanagerclient.h"
|
||||||
@@ -144,11 +145,11 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArguments)
|
|||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-nostdinc++",
|
"-nostdinc++",
|
||||||
"-I",
|
"-I",
|
||||||
TESTDATA_DIR "/builddependencycollector/project",
|
toNativePath(TESTDATA_DIR "/builddependencycollector/project").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR "/builddependencycollector/external",
|
toNativePath(TESTDATA_DIR "/builddependencycollector/external").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR "/builddependencycollector/system",
|
toNativePath(TESTDATA_DIR "/builddependencycollector/system").path(),
|
||||||
"-o",
|
"-o",
|
||||||
"project.pch",
|
"project.pch",
|
||||||
"project.h"));
|
"project.h"));
|
||||||
@@ -170,11 +171,11 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArgumentsWithSystemPch)
|
|||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-nostdinc++",
|
"-nostdinc++",
|
||||||
"-I",
|
"-I",
|
||||||
TESTDATA_DIR "/builddependencycollector/project",
|
toNativePath(TESTDATA_DIR "/builddependencycollector/project").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR "/builddependencycollector/external",
|
toNativePath(TESTDATA_DIR "/builddependencycollector/external").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR "/builddependencycollector/system",
|
toNativePath(TESTDATA_DIR "/builddependencycollector/system").path(),
|
||||||
"-Xclang",
|
"-Xclang",
|
||||||
"-include-pch",
|
"-include-pch",
|
||||||
"-Xclang",
|
"-Xclang",
|
||||||
|
@@ -24,8 +24,10 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
#include "filesystem-utilities.h"
|
||||||
|
|
||||||
#include <refactoringcompilationdatabase.h>
|
#include <refactoringcompilationdatabase.h>
|
||||||
|
#include <nativefilepath.h>
|
||||||
|
|
||||||
#include <utils/smallstring.h>
|
#include <utils/smallstring.h>
|
||||||
|
|
||||||
@@ -38,15 +40,15 @@ using testing::PrintToString;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
MATCHER_P3(IsCompileCommand, directory, fileName, commandLine,
|
MATCHER_P3(IsCompileCommand,
|
||||||
std::string(negation ? "isn't" : "is")
|
directory,
|
||||||
+ " compile command with directory "+ PrintToString(directory)
|
filePath,
|
||||||
+ ", file name " + PrintToString(fileName)
|
commandLine,
|
||||||
+ " and command line " + PrintToString(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
|
if (arg.Directory != std::string(directory) || arg.Filename != std::string(filePath)
|
||||||
|| arg.Filename != fileName
|
|
||||||
|| arg.CommandLine != commandLine)
|
|| arg.CommandLine != commandLine)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -56,7 +58,11 @@ MATCHER_P3(IsCompileCommand, directory, fileName, commandLine,
|
|||||||
class RefactoringCompilationDatabase : public ::testing::Test
|
class RefactoringCompilationDatabase : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void SetUp();
|
RefactoringCompilationDatabase()
|
||||||
|
{
|
||||||
|
database.addFile(ClangBackEnd::NativeFilePathView{temporarySourceFilePath},
|
||||||
|
{"cc", toNativePath(temporaryDirectoryPath + "/data.cpp").path(), "-DNO_DEBUG"});
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ClangBackEnd::RefactoringCompilationDatabase database;
|
ClangBackEnd::RefactoringCompilationDatabase database;
|
||||||
@@ -76,18 +82,28 @@ TEST_F(RefactoringCompilationDatabase, CompileCommandForFilePath)
|
|||||||
{
|
{
|
||||||
auto compileCommands = database.getAllCompileCommands();
|
auto compileCommands = database.getAllCompileCommands();
|
||||||
|
|
||||||
ASSERT_THAT(compileCommands, Contains(IsCompileCommand(temporaryDirectoryPath,
|
ASSERT_THAT(compileCommands,
|
||||||
"data.cpp",
|
Contains(IsCompileCommand(
|
||||||
std::vector<std::string>{"cc", "data.cpp", "-DNO_DEBUG"})));
|
temporaryDirectoryPath,
|
||||||
|
toNativePath(temporaryDirectoryPath + "/data.cpp").path(),
|
||||||
|
std::vector<std::string>{
|
||||||
|
"cc",
|
||||||
|
std::string(toNativePath(temporaryDirectoryPath + "/data.cpp").path()),
|
||||||
|
"-DNO_DEBUG"})));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RefactoringCompilationDatabase, NoCompileCommandForFilePath)
|
TEST_F(RefactoringCompilationDatabase, NoCompileCommandForFilePath)
|
||||||
{
|
{
|
||||||
auto compileCommands = database.getAllCompileCommands();
|
auto compileCommands = database.getAllCompileCommands();
|
||||||
|
|
||||||
ASSERT_THAT(compileCommands, Not(Contains(IsCompileCommand(temporaryDirectoryPath,
|
ASSERT_THAT(compileCommands,
|
||||||
"data.cpp2",
|
Not(Contains(IsCompileCommand(
|
||||||
std::vector<std::string>{"cc", "data.cpp", "-DNO_DEBUG"}))));
|
temporaryDirectoryPath,
|
||||||
|
toNativePath(temporaryDirectoryPath + "/data.cpp2").path(),
|
||||||
|
std::vector<std::string>{
|
||||||
|
"cc",
|
||||||
|
std::string(toNativePath(temporaryDirectoryPath + "/data.cpp").path()),
|
||||||
|
"-DNO_DEBUG"}))));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RefactoringCompilationDatabase, FilePaths)
|
TEST_F(RefactoringCompilationDatabase, FilePaths)
|
||||||
@@ -96,10 +112,4 @@ TEST_F(RefactoringCompilationDatabase, FilePaths)
|
|||||||
|
|
||||||
ASSERT_THAT(filePaths, Contains(std::string(temporarySourceFilePath)));
|
ASSERT_THAT(filePaths, Contains(std::string(temporarySourceFilePath)));
|
||||||
}
|
}
|
||||||
|
} // namespace
|
||||||
void RefactoringCompilationDatabase::SetUp()
|
|
||||||
{
|
|
||||||
database.addFile(std::string(temporaryDirectoryPath), "data.cpp", {"cc", "data.cpp", "-DNO_DEBUG"});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@@ -102,8 +102,9 @@ protected:
|
|||||||
Utils::SmallString sourceContent{"void f()\n {}"};
|
Utils::SmallString sourceContent{"void f()\n {}"};
|
||||||
FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"},
|
FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"},
|
||||||
sourceContent.clone(),
|
sourceContent.clone(),
|
||||||
{"cc", toNativePath(TESTDATA_DIR"/query_simplefunction.cpp")}};
|
{"cc", toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path()}};
|
||||||
QTemporaryFile temporaryFile{Utils::TemporaryDirectory::masterDirectoryPath() + "/clangQuery-XXXXXX.cpp"};
|
QTemporaryFile temporaryFile{Utils::TemporaryDirectory::masterDirectoryPath()
|
||||||
|
+ "/clangQuery-XXXXXX.cpp"};
|
||||||
int processingSlotCount = 2;
|
int processingSlotCount = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -266,10 +267,11 @@ TEST_F(RefactoringServer, PollTimerNotIsActiveAfterCanceling)
|
|||||||
|
|
||||||
TEST_F(RefactoringServerSlowTest, ForValidRequestSourceRangesAndDiagnosticsGetSourceRange)
|
TEST_F(RefactoringServerSlowTest, ForValidRequestSourceRangesAndDiagnosticsGetSourceRange)
|
||||||
{
|
{
|
||||||
RequestSourceRangesAndDiagnosticsForQueryMessage message("functionDecl()",
|
RequestSourceRangesAndDiagnosticsForQueryMessage message(
|
||||||
|
"functionDecl()",
|
||||||
{FilePath(temporaryFile.fileName()),
|
{FilePath(temporaryFile.fileName()),
|
||||||
"void f() {}",
|
"void f() {}",
|
||||||
{"cc", toNativePath(temporaryFile.fileName())}});
|
{"cc", toNativePath(temporaryFile.fileName()).path()}});
|
||||||
|
|
||||||
EXPECT_CALL(mockRefactoringClient,
|
EXPECT_CALL(mockRefactoringClient,
|
||||||
sourceRangesAndDiagnosticsForQueryMessage(
|
sourceRangesAndDiagnosticsForQueryMessage(
|
||||||
@@ -285,10 +287,11 @@ TEST_F(RefactoringServerSlowTest, ForValidRequestSourceRangesAndDiagnosticsGetSo
|
|||||||
|
|
||||||
TEST_F(RefactoringServerSlowTest, ForInvalidRequestSourceRangesAndDiagnosticsGetDiagnostics)
|
TEST_F(RefactoringServerSlowTest, ForInvalidRequestSourceRangesAndDiagnosticsGetDiagnostics)
|
||||||
{
|
{
|
||||||
RequestSourceRangesAndDiagnosticsForQueryMessage message("func()",
|
RequestSourceRangesAndDiagnosticsForQueryMessage message(
|
||||||
|
"func()",
|
||||||
{FilePath(temporaryFile.fileName()),
|
{FilePath(temporaryFile.fileName()),
|
||||||
"void f() {}",
|
"void f() {}",
|
||||||
{"cc", toNativePath(temporaryFile.fileName())}});
|
{"cc", toNativePath(temporaryFile.fileName()).path()}});
|
||||||
|
|
||||||
EXPECT_CALL(mockRefactoringClient,
|
EXPECT_CALL(mockRefactoringClient,
|
||||||
sourceRangesAndDiagnosticsForQueryMessage(
|
sourceRangesAndDiagnosticsForQueryMessage(
|
||||||
|
@@ -57,7 +57,9 @@ protected:
|
|||||||
void TearDown() override;
|
void TearDown() override;
|
||||||
|
|
||||||
protected:
|
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;
|
ClangBackEnd::SourceRangesContainer sourceRangesContainer;
|
||||||
const clang::SourceManager &sourceManager{clangTool.sourceManager()};
|
const clang::SourceManager &sourceManager{clangTool.sourceManager()};
|
||||||
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
|
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
|
||||||
|
@@ -31,28 +31,30 @@
|
|||||||
|
|
||||||
#include "filesystem-utilities.h"
|
#include "filesystem-utilities.h"
|
||||||
|
|
||||||
using ClangBackEnd::SymbolFinder;
|
|
||||||
using ClangBackEnd::FileContent;
|
using ClangBackEnd::FileContent;
|
||||||
|
using ClangBackEnd::FilePathView;
|
||||||
|
using ClangBackEnd::NativeFilePath;
|
||||||
|
using ClangBackEnd::NativeFilePathView;
|
||||||
|
using ClangBackEnd::SymbolFinder;
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
MATCHER_P2(IsSourceLocation, line, column,
|
inline bool operator==(const ClangBackEnd::NativeFilePath &first, const std::string &second)
|
||||||
std::string(negation ? "isn't" : "is")
|
{
|
||||||
+ "line " + PrintToString(line)
|
return first.path() == second;
|
||||||
+ ", column " + PrintToString(column)
|
}
|
||||||
)
|
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);
|
return arg.line == uint(line) && arg.column == uint(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
MATCHER_P(StrEq, text,
|
MATCHER_P(StrEq, text, std::string(negation ? "isn't" : "is") + " text " + PrintToString(text))
|
||||||
std::string(negation ? "isn't" : "is")
|
|
||||||
+ " text " + PrintToString(text)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return std::string(arg.data(), arg.size()) == std::string(text);
|
return std::string(arg.data(), arg.size()) == std::string(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
using Finder = SymbolFinder;
|
using Finder = SymbolFinder;
|
||||||
|
|
||||||
class SymbolFinder : public testing::Test
|
class SymbolFinder : public testing::Test
|
||||||
@@ -65,7 +67,7 @@ using SymbolFinderSlowTest = SymbolFinder;
|
|||||||
|
|
||||||
TEST_F(SymbolFinder, FileContentFilePath)
|
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"));
|
ASSERT_THAT(fileContent.filePath, toNativePath("/tmp/data.cpp"));
|
||||||
}
|
}
|
||||||
@@ -73,7 +75,9 @@ TEST_F(SymbolFinder, FileContentFilePath)
|
|||||||
TEST_F(SymbolFinderSlowTest, FindName)
|
TEST_F(SymbolFinderSlowTest, FindName)
|
||||||
{
|
{
|
||||||
Finder finder(1, 5, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -83,7 +87,9 @@ TEST_F(SymbolFinderSlowTest, FindName)
|
|||||||
TEST_F(SymbolFinderSlowTest, FindNameInUnsavedFile)
|
TEST_F(SymbolFinderSlowTest, FindNameInUnsavedFile)
|
||||||
{
|
{
|
||||||
Finder finder(1, 5, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -93,7 +99,9 @@ TEST_F(SymbolFinderSlowTest, FindNameInUnsavedFile)
|
|||||||
TEST_F(SymbolFinderSlowTest, FindUsrs)
|
TEST_F(SymbolFinderSlowTest, FindUsrs)
|
||||||
{
|
{
|
||||||
Finder finder(1, 5, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -103,7 +111,9 @@ TEST_F(SymbolFinderSlowTest, FindUsrs)
|
|||||||
TEST_F(SymbolFinderSlowTest, VariableDeclarationSourceLocations)
|
TEST_F(SymbolFinderSlowTest, VariableDeclarationSourceLocations)
|
||||||
{
|
{
|
||||||
Finder finder(1, 5, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -115,7 +125,9 @@ TEST_F(SymbolFinderSlowTest, VariableDeclarationSourceLocations)
|
|||||||
TEST_F(SymbolFinderSlowTest, VariableUsageSourceLocations)
|
TEST_F(SymbolFinderSlowTest, VariableUsageSourceLocations)
|
||||||
{
|
{
|
||||||
Finder finder(3, 9, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -127,7 +139,9 @@ TEST_F(SymbolFinderSlowTest, VariableUsageSourceLocations)
|
|||||||
TEST_F(SymbolFinderSlowTest, TemplateMemberVariableDeclarationSourceLocations)
|
TEST_F(SymbolFinderSlowTest, TemplateMemberVariableDeclarationSourceLocations)
|
||||||
{
|
{
|
||||||
Finder finder(8, 18, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -140,7 +154,9 @@ TEST_F(SymbolFinderSlowTest, TemplateMemberVariableDeclarationSourceLocations)
|
|||||||
TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageSourceLocations)
|
TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageSourceLocations)
|
||||||
{
|
{
|
||||||
Finder finder(15, 14, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -153,7 +169,9 @@ TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageSourceLocations)
|
|||||||
TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageInLambdaSourceLocations)
|
TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageInLambdaSourceLocations)
|
||||||
{
|
{
|
||||||
Finder finder(18, 19, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -166,7 +184,9 @@ TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageInLambdaSourceLocations)
|
|||||||
TEST_F(SymbolFinderSlowTest, CursorOverMacroDefintionSymbolName)
|
TEST_F(SymbolFinderSlowTest, CursorOverMacroDefintionSymbolName)
|
||||||
{
|
{
|
||||||
Finder finder(1, 9, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -176,7 +196,9 @@ TEST_F(SymbolFinderSlowTest, CursorOverMacroDefintionSymbolName)
|
|||||||
TEST_F(SymbolFinderSlowTest, CursorOverMacroExpansionSymbolName)
|
TEST_F(SymbolFinderSlowTest, CursorOverMacroExpansionSymbolName)
|
||||||
{
|
{
|
||||||
Finder finder(10, 10, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -186,7 +208,9 @@ TEST_F(SymbolFinderSlowTest, CursorOverMacroExpansionSymbolName)
|
|||||||
TEST_F(SymbolFinderSlowTest, FindMacroDefinition)
|
TEST_F(SymbolFinderSlowTest, FindMacroDefinition)
|
||||||
{
|
{
|
||||||
Finder finder(1, 9, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -197,7 +221,9 @@ TEST_F(SymbolFinderSlowTest, FindMacroDefinition)
|
|||||||
TEST_F(SymbolFinderSlowTest, FindMacroExpansion)
|
TEST_F(SymbolFinderSlowTest, FindMacroExpansion)
|
||||||
{
|
{
|
||||||
Finder finder(1, 9, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -208,7 +234,9 @@ TEST_F(SymbolFinderSlowTest, FindMacroExpansion)
|
|||||||
TEST_F(SymbolFinderSlowTest, DoNotFindUndedefinedMacroExpansion)
|
TEST_F(SymbolFinderSlowTest, DoNotFindUndedefinedMacroExpansion)
|
||||||
{
|
{
|
||||||
Finder finder(1, 9, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -219,7 +247,9 @@ TEST_F(SymbolFinderSlowTest, DoNotFindUndedefinedMacroExpansion)
|
|||||||
TEST_F(SymbolFinderSlowTest, FindMacroDefinitionFromMacroExpansion)
|
TEST_F(SymbolFinderSlowTest, FindMacroDefinitionFromMacroExpansion)
|
||||||
{
|
{
|
||||||
Finder finder(10, 10, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -231,7 +261,9 @@ TEST_F(SymbolFinderSlowTest, FindMacroDefinitionFromMacroExpansion)
|
|||||||
TEST_F(SymbolFinderSlowTest, FindMacroExpansionBeforeMacroExpansionWithCursor)
|
TEST_F(SymbolFinderSlowTest, FindMacroExpansionBeforeMacroExpansionWithCursor)
|
||||||
{
|
{
|
||||||
Finder finder(12, 10, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -242,7 +274,9 @@ TEST_F(SymbolFinderSlowTest, FindMacroExpansionBeforeMacroExpansionWithCursor)
|
|||||||
TEST_F(SymbolFinderSlowTest, FindMacroExpansionAfterMacroExpansionWithCursor)
|
TEST_F(SymbolFinderSlowTest, FindMacroExpansionAfterMacroExpansionWithCursor)
|
||||||
{
|
{
|
||||||
Finder finder(10, 10, filePathCaching);
|
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();
|
finder.findSymbol();
|
||||||
|
|
||||||
@@ -250,4 +284,4 @@ TEST_F(SymbolFinderSlowTest, FindMacroExpansionAfterMacroExpansionWithCursor)
|
|||||||
Contains(IsSourceLocation(12, 10)));
|
Contains(IsSourceLocation(12, 10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
#include "filesystem-utilities.h"
|
||||||
#include "mockclangpathwatcher.h"
|
#include "mockclangpathwatcher.h"
|
||||||
#include "mocksymbolscollector.h"
|
#include "mocksymbolscollector.h"
|
||||||
#include "mocksymbolstorage.h"
|
#include "mocksymbolstorage.h"
|
||||||
@@ -273,15 +274,15 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector)
|
|||||||
"-DBAR=1",
|
"-DBAR=1",
|
||||||
"-DFOO=1",
|
"-DFOO=1",
|
||||||
"-I",
|
"-I",
|
||||||
"/project/includes",
|
toNativePath("/project/includes").path(),
|
||||||
"-I",
|
"-I",
|
||||||
"/other/project/includes",
|
toNativePath("/other/project/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR,
|
toNativePath(TESTDATA_DIR).path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/other/includes",
|
toNativePath("/other/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/includes")));
|
toNativePath("/includes").path())));
|
||||||
|
|
||||||
indexer.updateProjectParts({projectPart1});
|
indexer.updateProjectParts({projectPart1});
|
||||||
}
|
}
|
||||||
@@ -303,19 +304,19 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInColl
|
|||||||
"-DBAR=1",
|
"-DBAR=1",
|
||||||
"-DFOO=1",
|
"-DFOO=1",
|
||||||
"-I",
|
"-I",
|
||||||
"/project/includes",
|
toNativePath("/project/includes").path(),
|
||||||
"-I",
|
"-I",
|
||||||
"/other/project/includes",
|
toNativePath("/other/project/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR,
|
toNativePath(TESTDATA_DIR).path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/other/includes",
|
toNativePath("/other/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/includes",
|
toNativePath("/includes").path(),
|
||||||
"-Xclang",
|
"-Xclang",
|
||||||
"-include-pch",
|
"-include-pch",
|
||||||
"-Xclang",
|
"-Xclang",
|
||||||
"/path/to/pch")));
|
toNativePath("/path/to/pch").path())));
|
||||||
|
|
||||||
indexer.updateProjectParts({projectPart1});
|
indexer.updateProjectParts({projectPart1});
|
||||||
}
|
}
|
||||||
@@ -336,15 +337,15 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInC
|
|||||||
"-DBAR=1",
|
"-DBAR=1",
|
||||||
"-DFOO=1",
|
"-DFOO=1",
|
||||||
"-I",
|
"-I",
|
||||||
"/project/includes",
|
toNativePath("/project/includes").path(),
|
||||||
"-I",
|
"-I",
|
||||||
"/other/project/includes",
|
toNativePath("/other/project/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR,
|
toNativePath(TESTDATA_DIR).path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/other/includes",
|
toNativePath("/other/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/includes")));
|
toNativePath("/includes").path())));
|
||||||
|
|
||||||
indexer.updateProjectParts({projectPart1});
|
indexer.updateProjectParts({projectPart1});
|
||||||
}
|
}
|
||||||
@@ -516,15 +517,15 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact)
|
|||||||
"-DBAR=1",
|
"-DBAR=1",
|
||||||
"-DFOO=1",
|
"-DFOO=1",
|
||||||
"-I",
|
"-I",
|
||||||
"/project/includes",
|
toNativePath("/project/includes").path(),
|
||||||
"-I",
|
"-I",
|
||||||
"/other/project/includes",
|
toNativePath("/other/project/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR,
|
toNativePath(TESTDATA_DIR).path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/other/includes",
|
toNativePath("/other/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/includes")));
|
toNativePath("/includes").path())));
|
||||||
EXPECT_CALL(mockCollector, collectSymbols());
|
EXPECT_CALL(mockCollector, collectSymbols());
|
||||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||||
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||||
@@ -568,15 +569,15 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact)
|
|||||||
"-DBAR=1",
|
"-DBAR=1",
|
||||||
"-DFOO=1",
|
"-DFOO=1",
|
||||||
"-I",
|
"-I",
|
||||||
"/project/includes",
|
toNativePath("/project/includes").path(),
|
||||||
"-I",
|
"-I",
|
||||||
"/other/project/includes",
|
toNativePath("/other/project/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR,
|
toNativePath(TESTDATA_DIR).path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/other/includes",
|
toNativePath("/other/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/includes")));
|
toNativePath("/includes").path())));
|
||||||
EXPECT_CALL(mockCollector, collectSymbols());
|
EXPECT_CALL(mockCollector, collectSymbols());
|
||||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||||
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||||
@@ -624,15 +625,15 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder)
|
|||||||
"-DBAR=1",
|
"-DBAR=1",
|
||||||
"-DFOO=1",
|
"-DFOO=1",
|
||||||
"-I",
|
"-I",
|
||||||
"/project/includes",
|
toNativePath("/project/includes").path(),
|
||||||
"-I",
|
"-I",
|
||||||
"/other/project/includes",
|
toNativePath("/other/project/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR,
|
toNativePath(TESTDATA_DIR).path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/other/includes",
|
toNativePath("/other/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/includes")));
|
toNativePath("/includes").path())));
|
||||||
EXPECT_CALL(mockCollector, collectSymbols());
|
EXPECT_CALL(mockCollector, collectSymbols());
|
||||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||||
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||||
@@ -686,19 +687,19 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader)
|
|||||||
"-DBAR=1",
|
"-DBAR=1",
|
||||||
"-DFOO=1",
|
"-DFOO=1",
|
||||||
"-I",
|
"-I",
|
||||||
"/project/includes",
|
toNativePath("/project/includes").path(),
|
||||||
"-I",
|
"-I",
|
||||||
"/other/project/includes",
|
toNativePath("/other/project/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR,
|
toNativePath(TESTDATA_DIR).path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/other/includes",
|
toNativePath("/other/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/includes",
|
toNativePath("/includes").path(),
|
||||||
"-Xclang",
|
"-Xclang",
|
||||||
"-include-pch",
|
"-include-pch",
|
||||||
"-Xclang",
|
"-Xclang",
|
||||||
"/path/to/pch")));
|
toNativePath("/path/to/pch").path())));
|
||||||
|
|
||||||
indexer.pathsChanged({sourceFileIds[0]});
|
indexer.pathsChanged({sourceFileIds[0]});
|
||||||
}
|
}
|
||||||
@@ -721,15 +722,15 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists)
|
|||||||
"-DBAR=1",
|
"-DBAR=1",
|
||||||
"-DFOO=1",
|
"-DFOO=1",
|
||||||
"-I",
|
"-I",
|
||||||
"/project/includes",
|
toNativePath("/project/includes").path(),
|
||||||
"-I",
|
"-I",
|
||||||
"/other/project/includes",
|
toNativePath("/other/project/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
TESTDATA_DIR,
|
toNativePath(TESTDATA_DIR).path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/other/includes",
|
toNativePath("/other/includes").path(),
|
||||||
"-isystem",
|
"-isystem",
|
||||||
"/includes")));
|
toNativePath("/includes").path())));
|
||||||
|
|
||||||
indexer.pathsChanged({sourceFileIds[0]});
|
indexer.pathsChanged({sourceFileIds[0]});
|
||||||
}
|
}
|
||||||
|
@@ -25,12 +25,11 @@
|
|||||||
|
|
||||||
#include "testclangtool.h"
|
#include "testclangtool.h"
|
||||||
|
|
||||||
TestClangTool::TestClangTool(std::string &&directory,
|
TestClangTool::TestClangTool(ClangBackEnd::FilePath &&filePath,
|
||||||
std::string &&fileName,
|
Utils::SmallString &&content,
|
||||||
std::string &&content,
|
Utils::SmallStringVector &&commandLine)
|
||||||
std::vector<std::string> &&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();
|
auto clangTool = createTool();
|
||||||
|
|
||||||
|
@@ -30,10 +30,9 @@
|
|||||||
class TestClangTool : public ClangBackEnd::ClangTool
|
class TestClangTool : public ClangBackEnd::ClangTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TestClangTool(std::string &&directory,
|
TestClangTool(ClangBackEnd::FilePath &&filePath,
|
||||||
std::string &&fileName,
|
Utils::SmallString &&content,
|
||||||
std::string &&content,
|
Utils::SmallStringVector &&commandLine);
|
||||||
std::vector<std::string> &&commandLine);
|
|
||||||
|
|
||||||
const clang::ASTUnit *ast() const;
|
const clang::ASTUnit *ast() const;
|
||||||
const clang::SourceManager &sourceManager() const;
|
const clang::SourceManager &sourceManager() const;
|
||||||
|
Reference in New Issue
Block a user