logic: Changed include files being analyzed solely by path
* removed header extensions * added source extensions to source path setup screen * added caching to hasFilePath check * don't show header list in CDB setup * removed TestSettings.xml
This commit is contained in:
+2
-4
@@ -247,18 +247,16 @@ void Project::updateFileManager()
|
||||
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
|
||||
|
||||
std::vector<FilePath> sourcePaths = projSettings->getAbsoluteSourcePaths();
|
||||
std::vector<FilePath> headerPaths;
|
||||
std::vector<FilePath> headerPaths = sourcePaths;
|
||||
|
||||
if (projSettings->getCompilationDatabasePath().exists())
|
||||
{
|
||||
headerPaths = sourcePaths;
|
||||
sourcePaths = TaskParseCxx::getSourceFilesFromCDB(projSettings->getCompilationDatabasePath());
|
||||
}
|
||||
|
||||
std::vector<std::string> sourceExtensions = projSettings->getSourceExtensions();
|
||||
std::vector<std::string> includeExtensions = projSettings->getHeaderExtensions();
|
||||
|
||||
m_fileManager.setPaths(sourcePaths, headerPaths, sourceExtensions, includeExtensions);
|
||||
m_fileManager.setPaths(sourcePaths, headerPaths, sourceExtensions);
|
||||
}
|
||||
|
||||
Parser::Arguments Project::getParserArguments() const
|
||||
|
||||
@@ -2,14 +2,6 @@
|
||||
|
||||
#include "utility/utility.h"
|
||||
|
||||
std::vector<std::string> ProjectSettings::getDefaultHeaderExtensions()
|
||||
{
|
||||
std::vector<std::string> defaultValues;
|
||||
defaultValues.push_back(".h");
|
||||
defaultValues.push_back(".hpp");
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
std::vector<std::string> ProjectSettings::getDefaultSourceExtensions()
|
||||
{
|
||||
std::vector<std::string> defaultValues;
|
||||
@@ -53,7 +45,6 @@ bool ProjectSettings::operator==(const ProjectSettings& other) const
|
||||
utility::isPermutation<FilePath>(getHeaderSearchPaths(), other.getHeaderSearchPaths()) &&
|
||||
utility::isPermutation<FilePath>(getFrameworkSearchPaths(), other.getFrameworkSearchPaths()) &&
|
||||
utility::isPermutation<std::string>(getCompilerFlags(), other.getCompilerFlags()) &&
|
||||
utility::isPermutation<std::string>(getHeaderExtensions(), other.getHeaderExtensions()) &&
|
||||
utility::isPermutation<std::string>(getSourceExtensions(), other.getSourceExtensions());
|
||||
}
|
||||
|
||||
@@ -155,21 +146,11 @@ bool ProjectSettings::setCompilerFlags(const std::vector<std::string>& compilerF
|
||||
return setValues("source/compiler_flags/compiler_flag", compilerFlags);
|
||||
}
|
||||
|
||||
std::vector<std::string> ProjectSettings::getHeaderExtensions() const
|
||||
{
|
||||
return getValues("source/extensions/header_extensions", getDefaultHeaderExtensions());
|
||||
}
|
||||
|
||||
std::vector<std::string> ProjectSettings::getSourceExtensions() const
|
||||
{
|
||||
return getValues("source/extensions/source_extensions", getDefaultSourceExtensions());
|
||||
}
|
||||
|
||||
bool ProjectSettings::setHeaderExtensions(const std::vector<std::string> &headerExtensions)
|
||||
{
|
||||
return setValues("source/extensions/header_extensions", headerExtensions);
|
||||
}
|
||||
|
||||
bool ProjectSettings::setSourceExtensions(const std::vector<std::string> &sourceExtensions)
|
||||
{
|
||||
return setValues("source/extensions/source_extensions", sourceExtensions);
|
||||
|
||||
@@ -10,7 +10,6 @@ class ProjectSettings
|
||||
: public Settings
|
||||
{
|
||||
public:
|
||||
static std::vector<std::string> getDefaultHeaderExtensions();
|
||||
static std::vector<std::string> getDefaultSourceExtensions();
|
||||
|
||||
static std::shared_ptr<ProjectSettings> getInstance();
|
||||
|
||||
@@ -23,13 +23,11 @@ const std::vector<FilePath>& FileManager::getSourcePaths() const
|
||||
void FileManager::setPaths(
|
||||
std::vector<FilePath> sourcePaths,
|
||||
std::vector<FilePath> headerPaths,
|
||||
std::vector<std::string> sourceExtensions,
|
||||
std::vector<std::string> includeExtensions
|
||||
std::vector<std::string> sourceExtensions
|
||||
){
|
||||
m_sourcePaths = sourcePaths;
|
||||
m_headerPaths = headerPaths;
|
||||
m_sourceExtensions = sourceExtensions;
|
||||
m_includeExtensions = includeExtensions;
|
||||
}
|
||||
|
||||
void FileManager::fetchFilePaths(const std::vector<FileInfo>& oldFileInfos)
|
||||
@@ -46,10 +44,24 @@ void FileManager::fetchFilePaths(const std::vector<FileInfo>& oldFileInfos)
|
||||
|
||||
for (std::map<FilePath, FileInfo>::iterator it = m_files.begin(); it != m_files.end(); it++)
|
||||
{
|
||||
m_removedFiles.insert(it->first);
|
||||
const FilePath& filePath = it->first;
|
||||
if (filePath.exists() && !hasSourceExtension(filePath))
|
||||
{
|
||||
FileInfo fileInfo = FileSystem::getFileInfoForPath(filePath);
|
||||
|
||||
if (fileInfo.lastWriteTime > it->second.lastWriteTime)
|
||||
{
|
||||
it->second.lastWriteTime = fileInfo.lastWriteTime;
|
||||
m_updatedFiles.insert(filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_removedFiles.insert(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<FileInfo> fileInfos = getFileInfosInProject();
|
||||
std::vector<FileInfo> fileInfos = FileSystem::getFileInfosFromPaths(m_sourcePaths, m_sourceExtensions);
|
||||
for (FileInfo fileInfo: fileInfos)
|
||||
{
|
||||
const FilePath& filePath = fileInfo.path;
|
||||
@@ -60,7 +72,7 @@ void FileManager::fetchFilePaths(const std::vector<FileInfo>& oldFileInfos)
|
||||
if (fileInfo.lastWriteTime > it->second.lastWriteTime)
|
||||
{
|
||||
it->second.lastWriteTime = fileInfo.lastWriteTime;
|
||||
m_updatedFiles.insert(fileInfo.path);
|
||||
m_updatedFiles.insert(filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -93,7 +105,20 @@ std::set<FilePath> FileManager::getRemovedFilePaths() const
|
||||
|
||||
bool FileManager::hasFilePath(const FilePath& filePath) const
|
||||
{
|
||||
return (m_files.find(filePath) != m_files.end());
|
||||
if (m_files.find(filePath) != m_files.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for (FilePath path : m_headerPaths)
|
||||
{
|
||||
if (path == filePath || path.contains(filePath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileManager::hasSourceExtension(const FilePath& filePath) const
|
||||
@@ -101,39 +126,14 @@ bool FileManager::hasSourceExtension(const FilePath& filePath) const
|
||||
return filePath.hasExtension(m_sourceExtensions);
|
||||
}
|
||||
|
||||
bool FileManager::hasIncludeExtension(const FilePath& filePath) const
|
||||
{
|
||||
return filePath.hasExtension(m_includeExtensions);
|
||||
}
|
||||
|
||||
const FileInfo FileManager::getFileInfo(const FilePath& filePath) const
|
||||
{
|
||||
std::map<FilePath, FileInfo>::const_iterator it = m_files.find(filePath);
|
||||
|
||||
if (it == m_files.end())
|
||||
{
|
||||
LOG_ERROR("No FileInfo found for file: " + filePath.str());
|
||||
return FileSystem::getFileInfoForPath(filePath);
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::vector<FileInfo> FileManager::getFileInfosInProject() const
|
||||
{
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
std::vector<std::pair<std::vector<FilePath>, std::vector<std::string>>> pathsExtensionsPairs;
|
||||
pathsExtensionsPairs.push_back(std::make_pair(m_sourcePaths, m_includeExtensions));
|
||||
pathsExtensionsPairs.push_back(std::make_pair(m_sourcePaths, m_sourceExtensions));
|
||||
pathsExtensionsPairs.push_back(std::make_pair(m_headerPaths, m_includeExtensions));
|
||||
|
||||
for (size_t i = 0; i < pathsExtensionsPairs.size(); i++)
|
||||
{
|
||||
utility::append(
|
||||
fileInfos,
|
||||
FileSystem::getFileInfosFromPaths(pathsExtensionsPairs[i].first, pathsExtensionsPairs[i].second)
|
||||
);
|
||||
}
|
||||
|
||||
return fileInfos;
|
||||
}
|
||||
|
||||
@@ -18,11 +18,9 @@ public:
|
||||
void setPaths(
|
||||
std::vector<FilePath> sourcePaths,
|
||||
std::vector<FilePath> headerPaths,
|
||||
std::vector<std::string> sourceExtensions,
|
||||
std::vector<std::string> includeExtensions
|
||||
std::vector<std::string> sourceExtensions
|
||||
);
|
||||
|
||||
void clear();
|
||||
void fetchFilePaths(const std::vector<FileInfo>& oldFileInfos);
|
||||
|
||||
std::set<FilePath> getAddedFilePaths() const;
|
||||
@@ -31,13 +29,10 @@ public:
|
||||
|
||||
virtual bool hasFilePath(const FilePath& filePath) const;
|
||||
virtual bool hasSourceExtension(const FilePath& filePath) const;
|
||||
virtual bool hasIncludeExtension(const FilePath& filePath) const;
|
||||
|
||||
virtual const FileInfo getFileInfo(const FilePath& filePath) const;
|
||||
|
||||
private:
|
||||
std::vector<FileInfo> getFileInfosInProject() const;
|
||||
|
||||
std::map<FilePath, FileInfo> m_files;
|
||||
|
||||
std::vector<FilePath> m_sourcePaths;
|
||||
|
||||
@@ -174,6 +174,27 @@ FilePath FilePath::concat(const FilePath& other) const
|
||||
return boost::filesystem::path(m_path) / other.m_path;
|
||||
}
|
||||
|
||||
bool FilePath::contains(const FilePath& other) const
|
||||
{
|
||||
if (!isDirectory())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::filesystem::path dir = m_path;
|
||||
boost::filesystem::path dir2 = other.m_path;
|
||||
|
||||
auto dir_len = std::distance(dir.begin(), dir.end());
|
||||
auto dir2_len = std::distance(dir2.begin(), dir2.end());
|
||||
|
||||
if (dir_len > dir2_len)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::equal(dir.begin(), dir.end(), dir2.begin());
|
||||
}
|
||||
|
||||
std::string FilePath::str() const
|
||||
{
|
||||
return m_path.generic_string();
|
||||
|
||||
@@ -28,6 +28,8 @@ public:
|
||||
FilePath concat(const FilePath& other) const;
|
||||
FilePath expandEnvironmentVariables() const;
|
||||
|
||||
bool contains(const FilePath& other) const;
|
||||
|
||||
std::string str() const;
|
||||
std::string fileName() const;
|
||||
|
||||
|
||||
@@ -10,30 +10,60 @@ FileRegister::FileRegister(const FileManager* fileManager)
|
||||
|
||||
void FileRegister::setFilePaths(const std::vector<FilePath>& filePaths)
|
||||
{
|
||||
std::lock_guard<std::mutex> sourceFileLock(m_sourceFileMutex);
|
||||
std::lock_guard<std::mutex> includeFileLock(m_includeFileMutex);
|
||||
|
||||
m_sourceFilePaths.clear();
|
||||
m_includeFilePaths.clear();
|
||||
|
||||
for (const FilePath& p : filePaths)
|
||||
{
|
||||
FilePath path = p.exists() ? p.absolute() : p;
|
||||
std::lock_guard<std::mutex> lock(m_sourceFileMutex);
|
||||
m_sourceFilePaths.clear();
|
||||
|
||||
if (m_fileManager->hasSourceExtension(path))
|
||||
for (const FilePath& p : filePaths)
|
||||
{
|
||||
m_sourceFilePaths.emplace(path, STATE_UNPARSED);
|
||||
}
|
||||
else if (m_fileManager->hasIncludeExtension(path))
|
||||
{
|
||||
m_includeFilePaths.emplace(path, STATE_UNPARSED);
|
||||
FilePath path = p.exists() ? p.absolute() : p;
|
||||
|
||||
if (m_fileManager->hasSourceExtension(path))
|
||||
{
|
||||
m_sourceFilePaths.emplace(path, STATE_UNPARSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_includeFileMutex);
|
||||
m_includeFilePaths.clear();
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadFileMutex);
|
||||
m_threadParsingFiles.clear();
|
||||
}
|
||||
}
|
||||
|
||||
const FileManager* FileRegister::getFileManager() const
|
||||
bool FileRegister::hasFilePath(const FilePath& filePath) const
|
||||
{
|
||||
return m_fileManager;
|
||||
std::lock_guard<std::mutex> lock(m_projectFilesMutex);
|
||||
std::unordered_map<std::string, bool>::iterator it = m_projectFiles.find(filePath.str());
|
||||
if (it != m_projectFiles.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool has = m_fileManager->hasFilePath(filePath);
|
||||
m_projectFiles.emplace(filePath.str(), has);
|
||||
|
||||
return has;
|
||||
}
|
||||
|
||||
const FileInfo FileRegister::getFileInfo(const FilePath& filePath) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_projectFileInfosMutex);
|
||||
std::unordered_map<std::string, FileInfo>::iterator it = m_projectFileInfos.find(filePath.str());
|
||||
if (it != m_projectFileInfos.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
FileInfo info = m_fileManager->getFileInfo(filePath);
|
||||
m_projectFileInfos.emplace(filePath.str(), info);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
std::vector<FilePath> FileRegister::getUnparsedSourceFilePaths() const
|
||||
@@ -140,30 +170,55 @@ bool FileRegister::includeFileIsParsed(const FilePath& filePath) const
|
||||
|
||||
FilePath FileRegister::consumeSourceFile()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_sourceFileMutex);
|
||||
for (std::map<FilePath, ParseState>::iterator it = m_sourceFilePaths.begin(); it != m_sourceFilePaths.end(); it++)
|
||||
FilePath path;
|
||||
{
|
||||
if (it->second == STATE_UNPARSED)
|
||||
std::lock_guard<std::mutex> lock(m_sourceFileMutex);
|
||||
for (std::map<FilePath, ParseState>::iterator it = m_sourceFilePaths.begin(); it != m_sourceFilePaths.end(); it++)
|
||||
{
|
||||
it->second = STATE_PARSING;
|
||||
m_threadParsingFiles[std::this_thread::get_id()].insert(it->first);
|
||||
return it->first;
|
||||
if (it->second == STATE_UNPARSED)
|
||||
{
|
||||
it->second = STATE_PARSING;
|
||||
path = it->first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FilePath();
|
||||
|
||||
if (!path.empty())
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadFileMutex);
|
||||
m_threadParsingFiles[std::this_thread::get_id()].insert(path);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void FileRegister::markIncludeFileParsing(const FilePath& filePath)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_includeFileMutex);
|
||||
std::map<FilePath, ParseState>::iterator it = m_includeFilePaths.find(filePath);
|
||||
if (it != m_includeFilePaths.end())
|
||||
bool unparsed = false;
|
||||
{
|
||||
if (it->second == STATE_UNPARSED)
|
||||
std::lock_guard<std::mutex> lock(m_includeFileMutex);
|
||||
std::map<FilePath, ParseState>::iterator it = m_includeFilePaths.find(filePath);
|
||||
|
||||
if (it != m_includeFilePaths.end())
|
||||
{
|
||||
it->second = STATE_PARSING;
|
||||
m_threadParsingFiles[std::this_thread::get_id()].insert(it->first);
|
||||
if (it->second == STATE_UNPARSED)
|
||||
{
|
||||
it->second = STATE_PARSING;
|
||||
unparsed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_includeFilePaths.emplace(filePath, STATE_PARSING);
|
||||
unparsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (unparsed)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadFileMutex);
|
||||
m_threadParsingFiles[std::this_thread::get_id()].insert(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +227,10 @@ void FileRegister::markThreadFilesParsed()
|
||||
std::lock_guard<std::mutex> sourceFileLock(m_sourceFileMutex);
|
||||
std::lock_guard<std::mutex> includeFileLock(m_includeFileMutex);
|
||||
std::lock_guard<std::mutex> threadFileLock(m_threadFileMutex);
|
||||
for (std::set<FilePath>::iterator it = m_threadParsingFiles[std::this_thread::get_id()].begin(); it != m_threadParsingFiles[std::this_thread::get_id()].end(); it++)
|
||||
|
||||
std::set<FilePath>& threadFiles = m_threadParsingFiles[std::this_thread::get_id()];
|
||||
|
||||
for (std::set<FilePath>::iterator it = threadFiles.begin(); it != threadFiles.end(); it++)
|
||||
{
|
||||
std::map<FilePath, ParseState>::iterator it2;
|
||||
it2 = m_sourceFilePaths.find(*it);
|
||||
@@ -188,7 +246,8 @@ void FileRegister::markThreadFilesParsed()
|
||||
it2->second = STATE_PARSED;
|
||||
}
|
||||
}
|
||||
m_threadParsingFiles[std::this_thread::get_id()].clear();
|
||||
|
||||
threadFiles.clear();
|
||||
}
|
||||
|
||||
size_t FileRegister::getSourceFilesCount() const
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define FILE_REGISTER_H
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
@@ -12,6 +13,8 @@
|
||||
|
||||
class FileManager;
|
||||
|
||||
struct FileInfo;
|
||||
|
||||
class FileRegister
|
||||
{
|
||||
public:
|
||||
@@ -19,7 +22,8 @@ public:
|
||||
|
||||
void setFilePaths(const std::vector<FilePath>& filePaths);
|
||||
|
||||
const FileManager* getFileManager() const;
|
||||
bool hasFilePath(const FilePath& filePath) const;
|
||||
const FileInfo getFileInfo(const FilePath& filePath) const;
|
||||
|
||||
std::vector<FilePath> getUnparsedSourceFilePaths() const;
|
||||
|
||||
@@ -47,6 +51,12 @@ private:
|
||||
|
||||
const FileManager* m_fileManager;
|
||||
|
||||
mutable std::unordered_map<std::string, bool> m_projectFiles;
|
||||
mutable std::mutex m_projectFilesMutex;
|
||||
|
||||
mutable std::unordered_map<std::string, FileInfo> m_projectFileInfos;
|
||||
mutable std::mutex m_projectFileInfosMutex;
|
||||
|
||||
std::map<FilePath, ParseState> m_sourceFilePaths;
|
||||
std::map<FilePath, ParseState> m_includeFilePaths;
|
||||
|
||||
@@ -55,6 +65,7 @@ private:
|
||||
mutable std::mutex m_sourceFileMutex;
|
||||
mutable std::mutex m_includeFileMutex;
|
||||
mutable std::mutex m_threadFileMutex;
|
||||
mutable std::mutex m_fileManagerMutex;
|
||||
};
|
||||
|
||||
#endif // FILE_REGISTER_H
|
||||
|
||||
Reference in New Issue
Block a user