Fix cyclic project dependencies causing stack overflow
This commit is contained in:
@@ -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
|
# and is licensed under MIT. Full source of the project can be found at
|
||||||
# https://github.com/Thraix/MakeGen
|
# https://github.com/Thraix/MakeGen
|
||||||
CC=@g++
|
CC=@g++
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
// Release , should be backwards compatible with any minor version
|
// Release , should be backwards compatible with any minor version
|
||||||
#define MAKEGEN_VERSION_RELEASE 1
|
#define MAKEGEN_VERSION_RELEASE 1
|
||||||
// Minor changes, should be compatible with any other minor version with same major and release.
|
// 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))
|
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
|
||||||
|
|
||||||
const static unsigned int FLAG_HELP = BIT(0);
|
const static unsigned int FLAG_HELP = BIT(0);
|
||||||
|
|||||||
+46
-8
@@ -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 ConfigFile::Load(const std::string& filepath)
|
||||||
{
|
{
|
||||||
ConfigFile conf;
|
ConfigFile conf;
|
||||||
conf.configPath = FileUtils::GetRealPath(filepath);
|
conf.configPath = filepath;
|
||||||
unsigned int loadFlag = 0;
|
unsigned int loadFlag = 0;
|
||||||
|
|
||||||
std::vector<std::string>* vec;
|
std::vector<std::string>* vec;
|
||||||
@@ -129,13 +174,6 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
|
|||||||
if(conf.hFile == "")
|
if(conf.hFile == "")
|
||||||
conf.hFile = conf.projectname+".h";
|
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;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
static const std::string CONFIG_FILENAME = "makegen.conf";
|
static const std::string CONFIG_FILENAME = "makegen.conf";
|
||||||
|
|
||||||
@@ -29,8 +31,10 @@ class ConfigFile
|
|||||||
ConfigFile();
|
ConfigFile();
|
||||||
void Save() const;
|
void Save() const;
|
||||||
static ConfigFile Gen();
|
static ConfigFile Gen();
|
||||||
static ConfigFile Load(const std::string& filename);
|
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath = "./");
|
||||||
private:
|
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 InputBoolean(const std::string& inputText, bool& b);
|
||||||
static void InputMultiple(const std::string& inputText, std::vector<std::string>& vec, bool needEnding);
|
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);
|
static void InputString(const std::string& inputText, std::string& vec, bool needEnding, bool allowEmpty);
|
||||||
|
|||||||
+2
-14
@@ -54,18 +54,6 @@ void PrintHelp()
|
|||||||
LOG_INFO(" clean all install run, rebuild will be translated to \"clean make\"");
|
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)
|
void GenMakefile(const ConfigFile& conf, unsigned int flags)
|
||||||
{
|
{
|
||||||
if(conf.generateHFile)
|
if(conf.generateHFile)
|
||||||
@@ -202,8 +190,8 @@ int main(int argc, char** argv)
|
|||||||
ConfigFile::Gen().Save();
|
ConfigFile::Gen().Save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
std::map<std::string, ConfigFile> files{};
|
||||||
auto conf = GetConfigFile("./");
|
auto conf = ConfigFile::GetConfigFile();
|
||||||
if(conf)
|
if(conf)
|
||||||
{
|
{
|
||||||
bool success = MakeGen("./", flags, *conf);
|
bool success = MakeGen("./", flags, *conf);
|
||||||
|
|||||||
Reference in New Issue
Block a user