diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cdf005..1d0e56f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ include (cmake/CPM.cmake) CPMAddPackage( NAME termcolor - GITHUB_REPOSITORY ikalnytskyi/termcolor + GIT_REPOSITORY https://github.com/ikalnytskyi/termcolor GIT_TAG v2.1.0 OPTIONS "BUILD_STATIC_LIBS ON" @@ -89,7 +89,7 @@ CPMAddPackage( CPMAddPackage( NAME cxxopts - GITHUB_REPOSITORY jarro2783/cxxopts + GIT_REPOSITORY https://www.github.com/jarro2783/cxxopts GIT_TAG origin/master OPTIONS "BUILD_STATIC_LIBS ON" @@ -97,7 +97,7 @@ CPMAddPackage( ) CPMAddPackage( NAME nlohmann_json - GITHUB_REPOSITORY nlohmann/json + GIT_REPOSITORY https://www.github.com/nlohmann/json GIT_TAG v3.11.3 OPTIONS "BUILD_STATIC_LIBS ON" @@ -106,18 +106,10 @@ CPMAddPackage( ) -CPMAddPackage( - name libgit2 - GITHUB_REPOSITORY libgit2/libgit2 - GIT_TAG v1.7.1 - OPTIONS - "BUILD_TESTS OFF" - "BUILD_STATIC_LIBS ON" - "BUILD_CLI OFF" -) + CPMAddPackage( NAME curl - GITHUB_REPOSITORY curl/curl + GIT_REPOSITORY https://www.github.com/curl/curl GIT_TAG curl-8_3_0 OPTIONS "ENABLE_VERSIONED_SYMBOLS ON" @@ -136,7 +128,7 @@ CPMAddPackage( CPMAddPackage( NAME uv - GITHUB_REPOSITORY libuv/libuv + GIT_REPOSITORY https://www.github.com/libuv/libuv GIT_TAG v1.47.0 OPTIONS "BUILD_STATIC_LIBS ON" @@ -145,8 +137,8 @@ CPMAddPackage( ) CPMAddPackage( - lua - GITHUB_REPOSITORY lua/lua + NAME lua + GIT_REPOSITORY https://www.github.com/lua/lua GIT_TAG v5.4.4 OPTIONS "BUILD_STATIC_LIBS ON" @@ -154,7 +146,7 @@ CPMAddPackage( CPMAddPackage( NAME sol2 - GITHUB_REPOSITORY ThePhD/sol2 + GIT_REPOSITORY https://www.github.com/ThePhD/sol2 GIT_TAG v3.3.1 ) @@ -214,7 +206,6 @@ target_link_options(${PROJECT_NAME} PRIVATE -static-libgcc -static-libstdc++) target_link_libraries(${PROJECT_NAME} PRIVATE libcurl) target_link_libraries(${PROJECT_NAME} PRIVATE cxxopts) target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json) -target_link_libraries(${PROJECT_NAME} PRIVATE libgit2package) target_link_libraries(${PROJECT_NAME} PRIVATE uv) target_link_libraries(${PROJECT_NAME} PRIVATE termcolor) target_link_libraries(${PROJECT_NAME} PRIVATE lua) diff --git a/completions/frate-completion.bash b/completions/frate-completion.bash index 7ecfdfb..6f75d1a 100644 --- a/completions/frate-completion.bash +++ b/completions/frate-completion.bash @@ -1,7 +1,6 @@ _frate() { local cur prev words cword _get_comp_words_by_ref -n : cur prev words cword - local commands="init run watch add ftp help" local add_subcommands="dep lib flags" diff --git a/include/Frate/Command/Actions/Watch.hpp b/include/Frate/Command/Actions/Watch.hpp index bfb03ec..c60d3ec 100644 --- a/include/Frate/Command/Actions/Watch.hpp +++ b/include/Frate/Command/Actions/Watch.hpp @@ -1,12 +1,7 @@ #pragma once #include -namespace Frate::Command::Watch { - bool options(std::shared_ptr inter); - bool run(std::shared_ptr inter); - std::vector handlers(std::shared_ptr inter); -} namespace Frate::Command::UvWatch { bool watch(std::shared_ptr inter); } diff --git a/include/Frate/Project.hpp b/include/Frate/Project.hpp index c33014e..a5d1f2d 100644 --- a/include/Frate/Project.hpp +++ b/include/Frate/Project.hpp @@ -30,7 +30,7 @@ namespace Frate::Command { std::string homepage{"null"}; std::string bugs{"null"}; std::string lang{"cpp"}; - std::string cmake_version{"3.28"}; + std::string cmake_version{"3.20"}; std::string lang_version{"20"}; std::string compiler{"g++"}; std::string license{""}; diff --git a/src/Command/Actions/New.cpp b/src/Command/Actions/New.cpp index b8d5c8f..59c7a64 100644 --- a/src/Command/Actions/New.cpp +++ b/src/Command/Actions/New.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "Frate/Command.hpp" diff --git a/src/Command/Actions/UvWatch.cpp b/src/Command/Actions/UvWatch.cpp index 06ff8ac..6135895 100644 --- a/src/Command/Actions/UvWatch.cpp +++ b/src/Command/Actions/UvWatch.cpp @@ -11,9 +11,8 @@ namespace Frate::Command::UvWatch{ inter->InitHeader(); inter->options->parse_positional({"command"}); inter->options->add_options() - ("command", "Command to run", cxxopts::value()->default_value("help")) - ("r,remote-build", "Build server to use", cxxopts::value()->default_value("false")) - ("c,args", "command to pass to dev", cxxopts::value>()); + ("c,command", "Command to run", cxxopts::value()->default_value("help")) + ("r,remote-build", "Build server to use", cxxopts::value()->default_value("false")); return inter->parse(); } //TODO Move to RemoteServer.hpp @@ -59,60 +58,58 @@ namespace Frate::Command::UvWatch{ return RemoteServer(); } + std::string remote_build_command(std::shared_ptr inter) { - std::string command; - std::string current_build_server = std::string(std::getenv("HOME")) + - "/.config/frate/" + - "current_build_server.json"; inter->pro->build_server = get_current_build_server(); - std::string sync_files = "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " + - std::to_string(inter->pro->build_server.port) + "' --progress . " + - inter->pro->build_server.username + "@" +inter->pro->build_server.ip + - ":/tmp/frate "; - - std::string ssh = "&& ssh -p " + std::to_string(inter->pro->build_server.port) + " " + - inter->pro->build_server.username + "@" +inter->pro->build_server.ip; - - std::string ssh_command = - " 'cd /tmp/frate && cmake . && make -j ${nproc} && " + inter->pro->build_dir + "/" + inter->pro->name + "'"; + // Get the destination path from environment variables + std::string remote_dest_path = std::getenv("REMOTE_DEST_PATH") ? std::getenv("REMOTE_DEST_PATH") : "/tmp/" + inter->pro->name; + std::cout << "Remote destination path: " << remote_dest_path << std::endl; + std::cout << "project: " << json(*inter->pro).dump(2) << std::endl; + std::cout << "pro->name: " << inter->pro->name << std::endl; + // Construct the rsync command + std::string sync_files = "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " + + std::to_string(inter->pro->build_server.port) + "' --progress . " + + inter->pro->build_server.username + "@" + inter->pro->build_server.ip + + ":" + remote_dest_path + " "; + + // SSH command to build the project + std::string ssh_build = "&& ssh -p " + std::to_string(inter->pro->build_server.port) + " " + + inter->pro->build_server.username + "@" + inter->pro->build_server.ip + " " + "'cd " + remote_dest_path + " && cmake . && make -j $(nproc)'"; + + // Add option to run a specific command after building, if set + std::string command; + if (inter->args->count("command")) { + std::string command_to_run = inter->args->operator[]("command").as(); + command = " && " + command_to_run; + } - command = sync_files + ssh + ssh_command; - return command; + return sync_files + ssh_build + command; } + bool runCommand(std::shared_ptr inter){ //TODO CLEAN UP THIS SHIT std::string command = "cmake . && make && " + inter->pro->path.string() + "/" + inter->pro->build_dir + "/" +inter->pro->name; #ifdef DEBUG command = "cd build && cmake . && make && " + inter->pro->build_dir + "/" +inter->pro->name; #endif - + if (inter->args->count("command") != 0) { + std::string command_run; + + std::string command_to_run = inter->args->operator[]("command").as(); + command = "cmake . && make && ./" + inter->pro->build_dir + "/" + + inter->pro->name + " " + command_run; + } bool build_server =inter->args->operator[]("remote-build").as(); if (build_server == true) { command = remote_build_command(inter); } - if (inter->args->count("args") != 0) { - // historical reasons - std::cout << "estamos aqui" << std::endl; - std::vector args_vec = - inter->args->operator[]("args").as>(); - std::string command_args = args_vec[0]; - if (args_vec.size() > 1) { - command_args = std::accumulate( - args_vec.begin(), args_vec.end(), args_vec[0], - [](std::string a, std::string b) { return a + " " + b; }); - std::cout << "args size is 0" << std::endl; - return false; - } - std::cout << "command_args: " << command_args << std::endl; - command = "cmake . && make && ./" + inter->pro->build_dir + "/" + - inter->pro->name + " " + command_args; - } if (Utils::hSystem(command) != 0){ std::cout << "Error running command: " << command << std::endl; exit(1); diff --git a/src/Command/Actions/Watch.cpp b/src/Command/Actions/Watch.cpp deleted file mode 100644 index 52f8544..0000000 --- a/src/Command/Actions/Watch.cpp +++ /dev/null @@ -1,240 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef __linux__ -#include -#include - -namespace Frate::Command::Watch { - bool options(std::shared_ptr inter) { - inter->InitHeader(); - inter->options->parse_positional({"command"}); - inter->options->add_options() - ("command", "Command to run", cxxopts::value()->default_value("help")) - ("r,remote-build", "Build server to use", cxxopts::value()->default_value("false")) - ("c,args", "command to pass to dev", cxxopts::value>()); - return inter->parse(); - } - using std::filesystem::directory_entry; - using std::filesystem::recursive_directory_iterator; - using std::views::filter; - - size_t walk(int epoll_fd, std::string path) { - std::vector filedescriptors; - - for (directory_entry filetoken : recursive_directory_iterator(path) | - filter([](const directory_entry &entry){return entry.is_directory();})) - { - std::cout << filetoken.path() << std::endl; - int temp_fd = inotify_init(); - if (temp_fd < 0) { - std::cout << "Error creating inotify instance" << std::endl; - exit(1); - } - int err = inotify_add_watch(temp_fd, filetoken.path().c_str(), - IN_MODIFY | IN_CREATE | IN_DELETE); - if (err < 0) { - std::cout << "Error adding watch" << std::endl; - exit(1); - } - filedescriptors.push_back(temp_fd); - }; - - for (int fd : filedescriptors) { - struct epoll_event temp_ev; - temp_ev.data.fd = fd; - temp_ev.events = EPOLLIN; - epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &temp_ev); - } - return filedescriptors.size(); - } - - void watcher(const std::function &changeCallback, std::string path) { - int inotify_fd = inotify_init(); - int epoll_fd = epoll_create(1); - - // Add inotify file descriptor to the epoll instance - struct epoll_event ev; - ev.events = EPOLLIN; - ev.data.fd = inotify_fd; - // TODO: Add recursive directory watching - - int watch_desc = inotify_add_watch(inotify_fd, path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE); - if (watch_desc < 0) { - std::cout << "Error adding watch" << std::endl; - return; - } - epoll_ctl(epoll_fd, EPOLL_CTL_ADD, inotify_fd, &ev); - size_t filedescriptors = walk(epoll_fd, path); - - // Add the directory you want to watch - - // Now, you can use epoll to wait for events - struct epoll_event events[1]; - while (true) { - std::cout << "\nWaiting for changes...\n" << std::endl; - int num_events = epoll_wait(epoll_fd, events, 1, -1); - std::cout << "\nChange detected!\n" << std::endl; - std::vector dirs; -#ifdef DEBUG - for (auto filetoken : std::filesystem::recursive_directory_iterator(path)) { -#else - for (auto filetoken : std::filesystem::recursive_directory_iterator(path)) { -#endif - if (std::filesystem::is_directory(filetoken.path())) { - dirs.push_back(filetoken.path()); - } - } - if (dirs.size() != filedescriptors) { - std::cout << "\nDirectory change detected\n" << std::endl; - filedescriptors = walk(epoll_fd, path.c_str()); - } - if (num_events > 0) { - char buffer[1024]; - while (read(events[0].data.fd, &buffer, sizeof(buffer)) < 0) { - } - std::cout << buffer << std::endl; - } - changeCallback(); - } - - // Don't forget to clean up your file descriptors when you're done - close(watch_desc); - close(inotify_fd); - close(epoll_fd); - } - - bool run(std::shared_ptr inter) { - options(inter); - // This is where you call the watcher function and provide a lambda for the - // callback - -#ifdef DEBUG - const std::string path = "./build/src"; -#else - const std::string path = "./src"; - -#endif - - watcher( - [inter]() { -#ifdef DEBUG - // TODO: please use project path - std::string command = "cmake ./build/ && ./build/make && ./build/" + - inter->pro->build_dir + "/" + inter->pro->name; - if (inter->args->count("args") != 0) { - std::vector args_vec = - inter->args->operator[]("args").as>(); - std::string command_args = std::accumulate( - args_vec.begin(), args_vec.end(), args_vec[0], - [](std::string a, std::string b) { return a + " " + b; }); - command = - "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " + - std::to_string(inter->pro->build_server.port) + "' --progress . " + - inter->pro->build_server.username + "@" +inter->pro->build_server.ip + - ":/tmp/frate && ssh -p " + - std::to_string(inter->pro->build_server.port) + " " + - inter->pro->build_server.username + "@" +inter->pro->build_server.ip + - " 'cd /tmp/frate && cmake . && make && ./build/new'"; - // command = "cmake ./build/ && make && ./build/" + inter->pro->build_dir + - // "/" + inter->pro->project_name + " " + command_args; - } - bool build_server =inter->args->operator[]("remote-build").as(); - if (build_server == true) { - std::string current_build_server = std::string(std::getenv("HOME")) + - "/.config/frate/" + - "current_build_server.json"; - json current_build_server_json = - json::parse(std::ifstream(current_build_server)); - if (!current_build_server_json["name"].is_null()) { - inter->pro->build_server = RemoteServer( - current_build_server_json["name"].get(), - current_build_server_json["address"].get(), - current_build_server_json["username"].get(), - current_build_server_json["authMethod"].get(), - current_build_server_json["password"].get(), - current_build_server_json["key"].get(), - current_build_server_json["port"].get()); - } - command = - "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " + - std::to_string(inter->pro->build_server.port) + "' --progress . " + - inter->pro->build_server.username + "@" +inter->pro->build_server.ip + - ":/tmp/frate && ssh -p " + - std::to_string(inter->pro->build_server.port) + " " + - inter->pro->build_server.username + "@" +inter->pro->build_server.ip + - " 'cd /tmp/frate && cmake . && make && ./build/" + - inter->pro->name + "'"; - } - -#else - std::string command = - "cmake . && make && ./" + inter->pro->build_dir + "/" +inter->pro->name; - - bool build_server =inter->args->operator[]("remote-build").as(); - if (build_server == true) { - std::string current_build_server = std::string(std::getenv("HOME")) + - "/.config/frate/" + - "current_build_server.json"; - json current_build_server_json = - json::parse(std::ifstream(current_build_server)); - if (!current_build_server_json["name"].is_null()) { - inter->pro->build_server = RemoteServer( - current_build_server_json["name"].get(), - current_build_server_json["address"].get(), - current_build_server_json["username"].get(), - current_build_server_json["authMethod"].get(), - current_build_server_json["password"].get(), - current_build_server_json["key"].get(), - current_build_server_json["port"].get()); - } - command = - "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " + - std::to_string(inter->pro->build_server.port) + "' --progress . " + - inter->pro->build_server.username + "@" +inter->pro->build_server.ip + - ":/tmp/frate && ssh -p " + - std::to_string(inter->pro->build_server.port) + " " + - inter->pro->build_server.username + "@" +inter->pro->build_server.ip + - " 'cd /tmp/frate && cmake . && make -j ${nproc} && ./build/" + - inter->pro->name + "'"; - } - if (inter->args->count("args") != 0) { - std::cout << "estamos aqui" << std::endl; - std::vector args_vec = - inter->args->operator[]("args").as>(); - std::string command_args = args_vec[0]; - if (args_vec.size() > 1) { - command_args = std::accumulate( - args_vec.begin(), args_vec.end(), args_vec[0], - [](std::string a, std::string b) { return a + " " + b; }); - std::cout << "args size is 0" << std::endl; - return; - } - - std::cout << "command_args: " << command_args << std::endl; - command = "cmake . && make && ./" + inter->pro->build_dir + "/" + - inter->pro->name + " " + command_args; - } -#endif - std::cout << "Running command: " << command << std::endl; - int success = Utils::hSystem(command.c_str()); - if (success != 0) { - std::cout << "Error running project" << std::endl; - } - - // Call your recompilation command or any other action you want - }, - path); - return true; - } -} // namespace Command -#endif - -#ifdef __APPLE__ -#include -#endif diff --git a/src/Command/Helpers/Interface.cpp b/src/Command/Helpers/Interface.cpp index b3063e7..a62a008 100644 --- a/src/Command/Helpers/Interface.cpp +++ b/src/Command/Helpers/Interface.cpp @@ -20,7 +20,6 @@ #include #include #include -#include namespace Frate::Command { @@ -60,7 +59,6 @@ namespace Frate::Command { Interface::Interface(int argc, char** argv){ this->argc = argc; this->argv = argv; - git_libgit2_init(); this->pro = std::make_shared(); #ifdef DEBUG #ifndef TEST @@ -204,8 +202,9 @@ namespace Frate::Command { .aliases = {"watch"}, .flags = {}, //TODO: Add flags .docs = "watches the project for changes", - .callback = &Watch::run - }); + .callback = &UvWatch::watch, + .requires_project = true + }); for(Handler& handler : inter->commands){ @@ -349,7 +348,6 @@ namespace Frate::Command { } } Interface::~Interface(){ - git_libgit2_shutdown(); } } // namespace Command diff --git a/src/Generators/CMakeTemplates.cpp b/src/Generators/CMakeTemplates.cpp index 5f70740..ab50acf 100644 --- a/src/Generators/CMakeTemplates.cpp +++ b/src/Generators/CMakeTemplates.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include diff --git a/src/Generators/ProjectGenerator/DownloadTemplates.cpp b/src/Generators/ProjectGenerator/DownloadTemplates.cpp index 30bd3ad..a747613 100644 --- a/src/Generators/ProjectGenerator/DownloadTemplates.cpp +++ b/src/Generators/ProjectGenerator/DownloadTemplates.cpp @@ -1,8 +1,6 @@ #include #include #include "Frate/Utils/General.hpp" -#include -#include namespace Frate::Generators::Project { diff --git a/src/Generators/ProjectGenerator/ProjectGenerator.cpp b/src/Generators/ProjectGenerator/ProjectGenerator.cpp index 27f9770..82219b0 100644 --- a/src/Generators/ProjectGenerator/ProjectGenerator.cpp +++ b/src/Generators/ProjectGenerator/ProjectGenerator.cpp @@ -6,8 +6,6 @@ #include #include #include -#include -#include #include namespace Frate::Generators::Project {