Skip to content

Commit

Permalink
fixed double refresh on templates thus fixing tests, I love how this …
Browse files Browse the repository at this point in the history
…projec works
  • Loading branch information
DeaSTL committed Dec 15, 2023
1 parent 63982ec commit 7f6f197
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 50 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
34 changes: 17 additions & 17 deletions src/Command/Helpers/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
22 changes: 5 additions & 17 deletions src/Generators/ProjectGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,12 @@ std::string index_url = static_cast<std::string>(Constants::FRATE_TEMPLATES);
return true;
}

bool refreshTemplate(Environment &env, sol::state &lua, std::shared_ptr<Command::Project> pro) {
bool refreshTemplate(Environment &env, std::shared_ptr<Command::Project> pro) {
info << "Refreshing template" << std::endl;
std::vector<path> 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();
Expand Down Expand Up @@ -247,7 +235,6 @@ std::string index_url = static_cast<std::string>(Constants::FRATE_TEMPLATES);

bool renderTemplate(
Environment &env,
sol::state &lua,
std::shared_ptr<Command::Project> pro){


Expand Down Expand Up @@ -411,7 +398,7 @@ std::string index_url = static_cast<std::string>(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;
}
Expand All @@ -427,14 +414,15 @@ std::string index_url = static_cast<std::string>(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;
}
Expand Down
25 changes: 14 additions & 11 deletions src/Lua/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ bool registerProjectScripts(inja::Environment &env, sol::state &lua,
} else if (arg->is_boolean()) {
args_table.add(arg->get<bool>());
} 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);
}
}
Expand All @@ -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);
}
});
Expand Down Expand Up @@ -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<path> scripts = {};
std::vector<path> 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;
}

Expand Down
1 change: 0 additions & 1 deletion src/Test/Commands/Flags/TestAddFlagMultiple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Test/Commands/Flags/TestAddFlagSingle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand Down
3 changes: 1 addition & 2 deletions src/Test/Commands/Flags/TestAddFlagWithMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7f6f197

Please sign in to comment.