Fix cyclic project dependencies causing stack overflow

This commit is contained in:
Thraix
2019-10-08 22:00:43 +02:00
parent e786de5118
commit fb7a369f83
5 changed files with 55 additions and 25 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
# This Makefile was generated using MakeGen v1.1.6 made by Tim Håkansson
# This Makefile was generated using MakeGen v1.1.7 made by Tim Håkansson
# and is licensed under MIT. Full source of the project can be found at
# https://github.com/Thraix/MakeGen
CC=@g++
+1 -1
View File
@@ -13,7 +13,7 @@
// Release , should be backwards compatible with any minor version
#define MAKEGEN_VERSION_RELEASE 1
// Minor changes, should be compatible with any other minor version with same major and release.
#define MAKEGEN_VERSION_MINOR 6
#define MAKEGEN_VERSION_MINOR 7
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
const static unsigned int FLAG_HELP = BIT(0);
+46 -8
View File
@@ -15,10 +15,55 @@ ConfigFile::ConfigFile()
{
}
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath)
{
std::map<std::string, ConfigFile> loadedConfigs;
return GetConfigFile(filepath, loadedConfigs);
}
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath, std::map<std::string, ConfigFile>& loadedConfigs)
{
std::string realPath = FileUtils::GetRealPath(filepath);
auto it = loadedConfigs.find(realPath);
if(it != loadedConfigs.end())
{
return {};
}
std::ifstream f(filepath + CONFIG_FILENAME);
// Check if the file exists
if(f.good())
{
f.close();
ConfigFile conf = ConfigFile::Load(realPath);
loadedConfigs.emplace(realPath, conf);
// Create dependency config files.
for(size_t i = 0; i < conf.dependencies.size();++i)
{
std::optional<ConfigFile> dep = GetConfigFile(conf.configPath + conf.dependencies[i], loadedConfigs);
if(dep)
{
conf.dependencyConfigs.push_back(*dep);
conf.dependencies[i] = dep->configPath;
}
else
{
// Remove the dependency since it is already accounted for
conf.dependencies.erase(conf.dependencies.begin() + i);
--i;
}
}
return conf;
}
return {};
}
ConfigFile ConfigFile::Load(const std::string& filepath)
{
ConfigFile conf;
conf.configPath = FileUtils::GetRealPath(filepath);
conf.configPath = filepath;
unsigned int loadFlag = 0;
std::vector<std::string>* vec;
@@ -129,13 +174,6 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
if(conf.hFile == "")
conf.hFile = conf.projectname+".h";
// Create dependency config files.
for(size_t i = 0; i < conf.dependencies.size();++i)
{
conf.dependencyConfigs.push_back(ConfigFile::Load(conf.configPath + conf.dependencies[i]));
conf.dependencies[i] = FileUtils::GetRealPath(conf.dependencies[i]);
}
return conf;
}
+5 -1
View File
@@ -2,6 +2,8 @@
#include <vector>
#include <string>
#include <optional>
#include <map>
static const std::string CONFIG_FILENAME = "makegen.conf";
@@ -29,8 +31,10 @@ class ConfigFile
ConfigFile();
void Save() const;
static ConfigFile Gen();
static ConfigFile Load(const std::string& filename);
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath = "./");
private:
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath, std::map<std::string, ConfigFile>& loadedConfigs);
static ConfigFile Load(const std::string& filename);
static void InputBoolean(const std::string& inputText, bool& b);
static void InputMultiple(const std::string& inputText, std::vector<std::string>& vec, bool needEnding);
static void InputString(const std::string& inputText, std::string& vec, bool needEnding, bool allowEmpty);
+2 -14
View File
@@ -54,18 +54,6 @@ void PrintHelp()
LOG_INFO(" clean all install run, rebuild will be translated to \"clean make\"");
}
std::optional<ConfigFile> GetConfigFile(const std::string& filepath)
{
std::ifstream f(filepath + CONFIG_FILENAME);
if(f.good())
{
ConfigFile conf = ConfigFile::Load(filepath);
return conf;
}
f.close();
return {};
}
void GenMakefile(const ConfigFile& conf, unsigned int flags)
{
if(conf.generateHFile)
@@ -202,8 +190,8 @@ int main(int argc, char** argv)
ConfigFile::Gen().Save();
return 0;
}
auto conf = GetConfigFile("./");
std::map<std::string, ConfigFile> files{};
auto conf = ConfigFile::GetConfigFile();
if(conf)
{
bool success = MakeGen("./", flags, *conf);