Add more default file extensions for source and header files

This commit is contained in:
Thraix
2020-03-02 22:10:54 +01:00
parent f68861367b
commit 80c64aa499
4 changed files with 51 additions and 38 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ void HFileGen::Create(ConfigFile& conf)
if(extensionPos != std::string::npos)
{
std::string filename = it->substr(path.length());
if(it->substr(extensionPos+1) == "h" && filename != conf.GetConfigPath() + conf.GetSettingString(ConfigSetting::HFileName))
if(Utils::IsHeaderFile(filename) && filename != conf.GetConfigPath() + conf.GetSettingString(ConfigSetting::HFileName))
{
// Make files sorted in alphabetical order
hFiles.emplace(filename);
+1 -1
View File
@@ -12,7 +12,7 @@ IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, co
IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, bool projectHFile, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps)
: filepath(dir+filename), projectHFile{projectHFile}
{
if(filename[filename.length() - 1] =='h')
if(Utils::IsHeaderFile(filename))
{
allDeps.emplace(filepath, this);
}
+47 -36
View File
@@ -3,6 +3,34 @@
#include "ConfigFile.h"
#include "FileUtils.h"
bool Utils::IsSourceFile(const std::string& filepath)
{
std::string_view extension(filepath);
size_t pSlash = filepath.find_last_of('/');
size_t pDot = filepath.find_last_of('.');
if(pDot == std::string::npos || (pSlash != std::string::npos && pSlash > pDot))
{
LOG_ERROR("No file extension for file: ", filepath);
return false;
}
extension.remove_prefix(pDot + 1);
return extension == "cpp" || extension == "c" || extension == "cxx" || extension == "cc";
}
bool Utils::IsHeaderFile(const std::string& filepath)
{
std::string_view extension(filepath);
size_t pSlash = filepath.find_last_of('/');
size_t pDot = filepath.find_last_of('.');
if(pDot == std::string::npos || (pSlash != std::string::npos && pSlash > pDot))
{
LOG_ERROR("No file extension for file: ", filepath);
return false;
}
extension.remove_prefix(pDot + 1);
return extension == "hpp" || extension == "h" || extension == "hxx";
}
std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2)
{
size_t n = 0;
@@ -26,19 +54,14 @@ void Utils::GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles)
for(auto it = files.begin(); it!=files.end();++it)
{
size_t extensionPos = it->find_last_of(".");
if(extensionPos != std::string::npos)
std::string filename = it->substr(path.length());
if(IsSourceFile(filename))
{
std::string extension = it->substr(extensionPos+1);
std::string filename = it->substr(path.length());
if(extension == "cpp" || extension == "c")
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
if(it == excludeSources.end())
{
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
if(it == excludeSources.end())
{
cppFiles.emplace(filename);
}
cppFiles.emplace(filename);
}
}
}
@@ -54,27 +77,20 @@ void Utils::GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<
// For example src/graphics/Window.h -> graphics/Window.h if src is a src folder
for(auto it = files.begin(); it!=files.end();++it)
{
size_t extensionPos = it->find_last_of(".");
if(extensionPos != std::string::npos)
std::string filename = it->substr(path.length());
if(IsSourceFile(filename))
{
std::string extension = it->substr(extensionPos+1);
std::string filename = it->substr(path.length());
if(extension == "cpp" || extension == "c")
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
if(it == excludeSources.end())
{
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
if(it == excludeSources.end())
{
cppFiles.emplace(filename);
}
else
LOG_INFO("Excluding: ", sourceFile);
}
else if(extension == "hpp" || extension == "h")
{
hFiles.emplace(HFile{filename,path,false});
cppFiles.emplace(filename);
}
}
else if(IsHeaderFile(filename))
{
hFiles.emplace(HFile{filename,path,false});
}
}
std::vector<std::string>& dependencies = conf.GetSettingVectorString(ConfigSetting::Dependency);
@@ -100,15 +116,10 @@ void Utils::GetHFiles(const std::string& dependencyDir, ConfigFile& conf, std::s
FileUtils::GetAllFiles(depSrcDir, files);
for(auto it = files.begin(); it!=files.end();++it)
{
size_t extensionPos = it->find_last_of(".");
if(extensionPos != std::string::npos)
if(IsHeaderFile(*it))
{
std::string extension = it->substr(extensionPos+1);
if(extension == "hpp" || extension == "h")
{
std::string filename = it->substr(depSrcDir.length());
hFiles.emplace(HFile{filename, depSrcDir, conf.GetSettingBool(ConfigSetting::GenerateHFile) && filename == conf.GetSettingString(ConfigSetting::HFileName)});
}
std::string filename = it->substr(depSrcDir.length());
hFiles.emplace(HFile{filename, depSrcDir, conf.GetSettingBool(ConfigSetting::GenerateHFile) && filename == conf.GetSettingString(ConfigSetting::HFileName)});
}
}
}
+2
View File
@@ -26,6 +26,8 @@ class ConfigFile;
struct Utils
{
static bool IsSourceFile(const std::string& filepath);
static bool IsHeaderFile(const std::string& filepath);
static std::string CommonPrefix(const std::string& s1, const std::string& s2);
static void GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles);
static void GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles);