data: parsing file dependencies

This change adds the node NODE_FILE to the graph and the edge EDGE_INCLUDE, which determine the dependencies between
files by parsing the include preprocessor directive. File nodes can be searched and displayed in the GraphView as file
dependency graph. The filter "file" allows for selecting all files. The file depency information is used on project
refresh do determine which files need to get reparsed.
This commit is contained in:
Eberhard Graether
2015-03-03 00:33:13 +01:00
parent 5370541a0f
commit 598041f896
32 changed files with 482 additions and 168 deletions
+13 -14
View File
@@ -4,7 +4,6 @@
#include <set>
#include "utility/file/FileSystem.h"
#include "ProjectSettings.h"
FileManager::FileManager(
std::vector<std::string> sourcePaths,
@@ -37,10 +36,9 @@ void FileManager::fetchFilePaths()
m_updatedFiles.clear();
m_removedFiles.clear();
std::set<std::string> removedFileNames;
for (std::map<std::string, FileInfo>::iterator it = m_files.begin(); it != m_files.end(); it++)
{
removedFileNames.insert(it->first);
m_removedFiles.insert(it->first);
}
std::vector<std::pair<std::vector<std::string>, std::vector<std::string>>> pathsExtensionsPairs;
@@ -49,51 +47,52 @@ void FileManager::fetchFilePaths()
for (size_t i = 0; i < pathsExtensionsPairs.size(); i++)
{
std::vector<FileInfo> fileInfos = FileSystem::getFileInfosFromDirectoryPaths(pathsExtensionsPairs[i].first, pathsExtensionsPairs[i].second);
std::vector<FileInfo> fileInfos =
FileSystem::getFileInfosFromDirectoryPaths(pathsExtensionsPairs[i].first, pathsExtensionsPairs[i].second);
for (FileInfo fileInfo: fileInfos)
{
const std::string& filePath = fileInfo.path;
std::map<std::string, FileInfo>::iterator it = m_files.find(filePath);
if (it != m_files.end())
{
removedFileNames.erase(filePath);
m_removedFiles.erase(filePath);
if (fileInfo.lastWriteTime > it->second.lastWriteTime)
{
it->second.lastWriteTime = fileInfo.lastWriteTime;
m_updatedFiles.push_back(filePath);
m_updatedFiles.insert(fileInfo.path);
}
}
else
{
m_files.insert(std::pair<std::string, FileInfo>(filePath, fileInfo));
m_addedFiles.push_back(filePath);
m_addedFiles.insert(filePath);
}
}
}
for (std::set<std::string>::iterator it = removedFileNames.begin(); it != removedFileNames.end(); it++)
for (const std::string filePath : m_removedFiles)
{
m_files.erase(it->data());
m_removedFiles.push_back(it->data());
m_files.erase(filePath);
}
}
std::vector<std::string> FileManager::getAddedFilePaths() const
std::set<std::string> FileManager::getAddedFilePaths() const
{
return m_addedFiles;
}
std::vector<std::string> FileManager::getUpdatedFilePaths() const
std::set<std::string> FileManager::getUpdatedFilePaths() const
{
return m_updatedFiles;
}
std::vector<std::string> FileManager::getRemovedFilePaths() const
std::set<std::string> FileManager::getRemovedFilePaths() const
{
return m_removedFiles;
}
bool FileManager::hasFilePath(const std::string& filePath) const
{
return (m_files.find(filePath) != m_files.end());
return (m_files.find(FileSystem::absoluteFilePath(filePath)) != m_files.end());
}
+8 -7
View File
@@ -1,7 +1,7 @@
#ifndef FILE_MANAGER_H
#define FILE_MANAGER_H
#include <memory>
#include <set>
#include <vector>
#include "FileInfo.h"
@@ -19,9 +19,10 @@ public:
void reset();
void fetchFilePaths();
std::vector<std::string> getAddedFilePaths() const;
std::vector<std::string> getUpdatedFilePaths() const;
std::vector<std::string> getRemovedFilePaths() const;
std::set<std::string> getAddedFilePaths() const;
std::set<std::string> getUpdatedFilePaths() const;
std::set<std::string> getRemovedFilePaths() const;
virtual bool hasFilePath(const std::string& filePath) const;
@@ -32,9 +33,9 @@ private:
std::vector<std::string> m_includeExtensions;
std::map<std::string, FileInfo> m_files;
std::vector<std::string> m_addedFiles;
std::vector<std::string> m_updatedFiles;
std::vector<std::string> m_removedFiles;
std::set<std::string> m_addedFiles;
std::set<std::string> m_updatedFiles;
std::set<std::string> m_removedFiles;
};
#endif // FILE_MANAGER_H