Add more default file extensions for source and header files
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ void HFileGen::Create(ConfigFile& conf)
|
|||||||
if(extensionPos != std::string::npos)
|
if(extensionPos != std::string::npos)
|
||||||
{
|
{
|
||||||
std::string filename = it->substr(path.length());
|
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
|
// Make files sorted in alphabetical order
|
||||||
hFiles.emplace(filename);
|
hFiles.emplace(filename);
|
||||||
|
|||||||
+1
-1
@@ -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)
|
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}
|
: filepath(dir+filename), projectHFile{projectHFile}
|
||||||
{
|
{
|
||||||
if(filename[filename.length() - 1] =='h')
|
if(Utils::IsHeaderFile(filename))
|
||||||
{
|
{
|
||||||
allDeps.emplace(filepath, this);
|
allDeps.emplace(filepath, this);
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-21
@@ -3,6 +3,34 @@
|
|||||||
#include "ConfigFile.h"
|
#include "ConfigFile.h"
|
||||||
#include "FileUtils.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)
|
std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
@@ -26,12 +54,8 @@ void Utils::GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles)
|
|||||||
|
|
||||||
for(auto it = files.begin(); it!=files.end();++it)
|
for(auto it = files.begin(); it!=files.end();++it)
|
||||||
{
|
{
|
||||||
size_t extensionPos = it->find_last_of(".");
|
|
||||||
if(extensionPos != std::string::npos)
|
|
||||||
{
|
|
||||||
std::string extension = it->substr(extensionPos+1);
|
|
||||||
std::string filename = it->substr(path.length());
|
std::string filename = it->substr(path.length());
|
||||||
if(extension == "cpp" || extension == "c")
|
if(IsSourceFile(filename))
|
||||||
{
|
{
|
||||||
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
|
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
|
||||||
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
|
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
|
||||||
@@ -41,7 +65,6 @@ void Utils::GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Utils::GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles)
|
void Utils::GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles)
|
||||||
@@ -54,12 +77,8 @@ 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 example src/graphics/Window.h -> graphics/Window.h if src is a src folder
|
||||||
for(auto it = files.begin(); it!=files.end();++it)
|
for(auto it = files.begin(); it!=files.end();++it)
|
||||||
{
|
{
|
||||||
size_t extensionPos = it->find_last_of(".");
|
|
||||||
if(extensionPos != std::string::npos)
|
|
||||||
{
|
|
||||||
std::string extension = it->substr(extensionPos+1);
|
|
||||||
std::string filename = it->substr(path.length());
|
std::string filename = it->substr(path.length());
|
||||||
if(extension == "cpp" || extension == "c")
|
if(IsSourceFile(filename))
|
||||||
{
|
{
|
||||||
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
|
std::string sourceFile =conf.GetSettingString(ConfigSetting::SourceDir) + filename;
|
||||||
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
|
auto it = std::find(excludeSources.begin(), excludeSources.end(), sourceFile);
|
||||||
@@ -67,15 +86,12 @@ void Utils::GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<
|
|||||||
{
|
{
|
||||||
cppFiles.emplace(filename);
|
cppFiles.emplace(filename);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
LOG_INFO("Excluding: ", sourceFile);
|
|
||||||
}
|
}
|
||||||
else if(extension == "hpp" || extension == "h")
|
else if(IsHeaderFile(filename))
|
||||||
{
|
{
|
||||||
hFiles.emplace(HFile{filename,path,false});
|
hFiles.emplace(HFile{filename,path,false});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string>& dependencies = conf.GetSettingVectorString(ConfigSetting::Dependency);
|
std::vector<std::string>& dependencies = conf.GetSettingVectorString(ConfigSetting::Dependency);
|
||||||
for(size_t i = 0; i < dependencies.size(); ++i)
|
for(size_t i = 0; i < dependencies.size(); ++i)
|
||||||
@@ -100,17 +116,12 @@ void Utils::GetHFiles(const std::string& dependencyDir, ConfigFile& conf, std::s
|
|||||||
FileUtils::GetAllFiles(depSrcDir, files);
|
FileUtils::GetAllFiles(depSrcDir, files);
|
||||||
for(auto it = files.begin(); it!=files.end();++it)
|
for(auto it = files.begin(); it!=files.end();++it)
|
||||||
{
|
{
|
||||||
size_t extensionPos = it->find_last_of(".");
|
if(IsHeaderFile(*it))
|
||||||
if(extensionPos != std::string::npos)
|
|
||||||
{
|
|
||||||
std::string extension = it->substr(extensionPos+1);
|
|
||||||
if(extension == "hpp" || extension == "h")
|
|
||||||
{
|
{
|
||||||
std::string filename = it->substr(depSrcDir.length());
|
std::string filename = it->substr(depSrcDir.length());
|
||||||
hFiles.emplace(HFile{filename, depSrcDir, conf.GetSettingBool(ConfigSetting::GenerateHFile) && filename == conf.GetSettingString(ConfigSetting::HFileName)});
|
hFiles.emplace(HFile{filename, depSrcDir, conf.GetSettingBool(ConfigSetting::GenerateHFile) && filename == conf.GetSettingString(ConfigSetting::HFileName)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bool Utils::IsWhiteSpace(char c)
|
bool Utils::IsWhiteSpace(char c)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ class ConfigFile;
|
|||||||
|
|
||||||
struct Utils
|
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 std::string CommonPrefix(const std::string& s1, const std::string& s2);
|
||||||
static void GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles);
|
static void GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles);
|
||||||
static void GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles);
|
static void GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles);
|
||||||
|
|||||||
Reference in New Issue
Block a user