From 7f6f19778e1481470098b91d134ad07aeeab553b Mon Sep 17 00:00:00 2001 From: Jon-Michael Hartway Date: Fri, 15 Dec 2023 14:34:24 -0500 Subject: [PATCH] fixed double refresh on templates thus fixing tests, I love how this projec works --- CMakeLists.txt | 2 +- src/Command/Helpers/Interface.cpp | 34 +++++++++---------- src/Generators/ProjectGenerator.cpp | 22 +++--------- src/Lua/API.cpp | 25 ++++++++------ .../Commands/Flags/TestAddFlagMultiple.cpp | 1 - src/Test/Commands/Flags/TestAddFlagSingle.cpp | 1 - .../Commands/Flags/TestAddFlagWithMode.cpp | 3 +- 7 files changed, 38 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7e7d41..aa83522 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,7 +175,7 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_libraries(${PROJECT_NAME} PRIVATE cpptrace) elseif(CMAKE_BUILD_TYPE STREQUAL "Test") message("Test mode") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -O0 -Wextra -Wpedantic -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -O0 -Wextra -Wpedantic -Wall -fno-omit-frame-pointer") CPMAddPackage( "gh:catchorg/Catch2@3.4.0" ) diff --git a/src/Command/Helpers/Interface.cpp b/src/Command/Helpers/Interface.cpp index e0a2880..74948e6 100644 --- a/src/Command/Helpers/Interface.cpp +++ b/src/Command/Helpers/Interface.cpp @@ -216,6 +216,7 @@ namespace Frate::Command { } if(handler.requires_project){ Generators::Project::refresh(inter->pro); + inter->pro->save(); } found_alias = true; if(!handler.callback(inter)){ @@ -228,17 +229,17 @@ namespace Frate::Command { std::cout << "Error: Command not found: " << command << ENDL; return false; } - for(Handler& handler : inter->commands){ - for(std::string& alias : handler.aliases){ - if(alias == command){ - if(handler.requires_project){ - inter->pro->save(); - Generators::Project::refresh(inter->pro); - break; - } - } - } - } + // for(Handler& handler : inter->commands){ + // for(std::string& alias : handler.aliases){ + // if(alias == command){ + // if(handler.requires_project){ + // inter->pro->save(); + // Generators::Project::refresh(inter->pro); + // break; + // } + // } + // } + // } return true; @@ -274,13 +275,12 @@ namespace Frate::Command { if(!handler.callback(shared_from_this())){ getHelpString(handler); return false; - }else{ - if(handler.requires_project){ - pro->save(); - Generators::Project::refresh(pro); - } - return true; } + if(handler.requires_project){ + pro->save(); + Generators::Project::refresh(pro); + } + return true; } } } diff --git a/src/Generators/ProjectGenerator.cpp b/src/Generators/ProjectGenerator.cpp index a37a0c2..a610958 100644 --- a/src/Generators/ProjectGenerator.cpp +++ b/src/Generators/ProjectGenerator.cpp @@ -153,24 +153,12 @@ std::string index_url = static_cast(Constants::FRATE_TEMPLATES); return true; } - bool refreshTemplate(Environment &env, sol::state &lua, std::shared_ptr pro) { + bool refreshTemplate(Environment &env, std::shared_ptr pro) { info << "Refreshing template" << std::endl; std::vector paths_to_refresh{ pro->path / "template/CMakeLists.txt.inja", }; - LuaAPI::registerAPI(lua); - - if(!LuaAPI::registerProject(lua, pro)){ - error << "Error while registering project" << std::endl; - return false; - } - - if(!LuaAPI::registerProjectScripts(env, lua,pro->path / "template/scripts", pro)){ - error << "Error while registering project scripts" << std::endl; - return false; - } - for(const path& current_p: paths_to_refresh){ std::string rendered_file = env.render_file(current_p, pro->toJson()); std::string new_file = current_p.string(); @@ -247,7 +235,6 @@ std::string index_url = static_cast(Constants::FRATE_TEMPLATES); bool renderTemplate( Environment &env, - sol::state &lua, std::shared_ptr pro){ @@ -411,7 +398,7 @@ std::string index_url = static_cast(Constants::FRATE_TEMPLATES); LuaAPI::initScripts(lua, pro); - if(!renderTemplate(env, lua, pro)){ + if(!renderTemplate(env, pro)){ error << "Error while rendering template to tmp" << std::endl; return false; } @@ -427,14 +414,15 @@ std::string index_url = static_cast(Constants::FRATE_TEMPLATES); Environment env; sol::state lua; - LuaAPI::initScripts(lua, pro); if(!initializeLua(env, lua, pro)){ error << "Error while initializing lua" << std::endl; return false; } - if(!refreshTemplate(env, lua, pro)){ + LuaAPI::initScripts(lua, pro); + + if(!refreshTemplate(env,pro)){ error << "Error while rendering template to tmp" << std::endl; return false; } diff --git a/src/Lua/API.cpp b/src/Lua/API.cpp index 4562e99..cd987a6 100644 --- a/src/Lua/API.cpp +++ b/src/Lua/API.cpp @@ -61,7 +61,9 @@ bool registerProjectScripts(inja::Environment &env, sol::state &lua, } else if (arg->is_boolean()) { args_table.add(arg->get()); } else { - error << "Error while executing lua script" << std::endl; + error + << "Error while converting arguments in inja callback for script at: " + << script_path << std::endl; exit(1); } } @@ -72,14 +74,15 @@ bool registerProjectScripts(inja::Environment &env, sol::state &lua, << std::endl; exit(1); } - + + info << "Executing lua script at: " << script_path << std::endl; //lua.set("global", global_table); auto result = lua.script_file(script_path); if (result.valid()) { return result; } else { - error << "Error while executing lua script" << std::endl; + error << "Error while executing lua script at: " << script_path << std::endl; exit(1); } }); @@ -110,31 +113,31 @@ bool registerProjectScripts(inja::Environment &env, sol::state &lua, / (Constants::TEMPLATE_PATH + Constants::INIT_SCRIPTS_PATH); if(!std::filesystem::exists(script_path)){ - warning << "No init scripts found" << " at: " << script_path << std::endl; + warning << "No init scripts found at: " << script_path << std::endl; return false; } - std::vector scripts = {}; + std::vector script_paths = {}; for(const path& current_path : std::filesystem::recursive_directory_iterator(script_path)){ if(current_path.extension() == ".lua"){ - scripts.push_back(current_path); + script_paths.push_back(current_path); } } - for(const path& script : scripts){ + for(const path& current_script_path : script_paths){ lua.set("project", project); - if(!std::filesystem::exists(script)){ - error << "Script not found: " << script << " at: " << script_path << std::endl; + if(!std::filesystem::exists(current_script_path)){ + error << "Script not found: " << current_script_path << " at: " << script_path << std::endl; return false; } - auto result = lua.script_file(script); + auto result = lua.script_file(current_script_path); if(!result.valid()){ - error << "Error while executing lua script" << std::endl; + error << "Error while executing lua script at: " << current_script_path << std::endl; return false; } diff --git a/src/Test/Commands/Flags/TestAddFlagMultiple.cpp b/src/Test/Commands/Flags/TestAddFlagMultiple.cpp index f5599b1..f4d8b5b 100644 --- a/src/Test/Commands/Flags/TestAddFlagMultiple.cpp +++ b/src/Test/Commands/Flags/TestAddFlagMultiple.cpp @@ -9,7 +9,6 @@ namespace Tests::Command { if(!testNew()) return false; - std::cout << "Testing add flags command normal conditions" << std::endl; auto [failed, inter] = init("frate add flags '-g -O3'"); if(failed) return false; diff --git a/src/Test/Commands/Flags/TestAddFlagSingle.cpp b/src/Test/Commands/Flags/TestAddFlagSingle.cpp index 401b1f9..c83c77a 100644 --- a/src/Test/Commands/Flags/TestAddFlagSingle.cpp +++ b/src/Test/Commands/Flags/TestAddFlagSingle.cpp @@ -4,7 +4,6 @@ namespace Tests::Command { bool testAddFlagsSingle(){ - info << "Testing add flags command" << std::endl; if(!testNew()) return false; info << "Testing add flags command normal conditions" << std::endl; auto [failed, inter] = init("frate add flags '-O3'"); diff --git a/src/Test/Commands/Flags/TestAddFlagWithMode.cpp b/src/Test/Commands/Flags/TestAddFlagWithMode.cpp index f5673e2..5c0f382 100644 --- a/src/Test/Commands/Flags/TestAddFlagWithMode.cpp +++ b/src/Test/Commands/Flags/TestAddFlagWithMode.cpp @@ -4,12 +4,11 @@ namespace Tests::Command { bool testAddFlagsWithMode(){ - std::cout << "Testing add flags command" << std::endl; + std::cout << "Testing add flags command with a mode specified" << std::endl; if(!testNew()){ Frate::error << "Failed to create new project" << std::endl; return false; } - std::cout << "Testing add flags command normal conditions" << std::endl; auto [failed, inter] = init("frate add flags -m Release '-O3'"); if (failed) {