From 7afc8f7ad6954f056e94a0e3118dcb1877eb6f50 Mon Sep 17 00:00:00 2001 From: "lucas.sproule" Date: Mon, 6 Nov 2023 06:58:32 -0500 Subject: [PATCH] remote builds templated out --- CMakeLists.txt | 2 +- src/Command/CommandServer.cpp | 7 ++-- src/Command/CommandWatcher.cpp | 50 ++++++++++++++++----------- src/Generators/GitIgnoreGenerator.cpp | 3 ++ 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 607c540..95c5515 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ else() endif() endif() -target_link_libraries(${PROJECT_NAME} curl) +target_link_libraries(${PROJECT_NAME} libcurl) target_link_libraries(${PROJECT_NAME} cxxopts) target_link_libraries(${PROJECT_NAME} nlohmann_json) target_link_libraries(${PROJECT_NAME} termcolor::termcolor) diff --git a/src/Command/CommandServer.cpp b/src/Command/CommandServer.cpp index 515e5a7..7b49e5c 100644 --- a/src/Command/CommandServer.cpp +++ b/src/Command/CommandServer.cpp @@ -17,7 +17,7 @@ namespace Command{ return true; } - bool getServerPort(std::string& port){ + bool getServerPort(int& port){ Prompt *port_promp = new Prompt("Enter the port of the server: "); port_promp->Run(); port = port_promp->Get(); @@ -113,7 +113,8 @@ Usage server: bool serverAdd(std::vector servers){ std::string build_servers= std::string(std::getenv("HOME")) + "/.config/cmaker/" + "build_server.json"; - std::string name, address, port, username, authMethod, password, key; + std::string name, address, username, authMethod, password, key; + int port; getServerName(name); getServerAddress(address); getServerPort(port); @@ -132,7 +133,7 @@ Usage server: - BuildServer build_server = BuildServer(name, address, username, authMethod, password, key, std::stoi(port)); + BuildServer build_server = BuildServer(name, address, username, authMethod, password, key, port); servers.push_back(build_server); std::vector build_server_json; diff --git a/src/Command/CommandWatcher.cpp b/src/Command/CommandWatcher.cpp index 30a9b24..5c37f61 100644 --- a/src/Command/CommandWatcher.cpp +++ b/src/Command/CommandWatcher.cpp @@ -18,7 +18,7 @@ namespace Command { 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 | IN_MOVED_FROM | IN_MOVED_TO); + 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); @@ -49,7 +49,7 @@ namespace Command { ev.data.fd = inotify_fd; // TODO: Add recursive directory watching - size_t watch_desc = inotify_add_watch(inotify_fd, path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO); + size_t 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; @@ -88,9 +88,9 @@ namespace Command { } std::cout << buffer << std::endl; - changeCallback(); } + changeCallback(); } @@ -121,12 +121,35 @@ namespace Command { args_vec.begin(), args_vec.end(), args_vec[0], [](std::string a, std::string b) { return a + " " + b; } ); - - command = "cmake ./build/ && make && ./build/" + pro->build_dir + "/" + pro->project_name + " " + command_args; + command = "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " + std::to_string(pro->build_server.port) + "' --progress . " + + pro->build_server.username + "@" + pro->build_server.ip + + ":/tmp/cmaker && ssh -p " + std::to_string(pro->build_server.port) + " " + pro->build_server.username + "@" + pro->build_server.ip + + " 'cd /tmp/cmaker && cmake . && make && ./build/new'"; + //command = "cmake ./build/ && make && ./build/" + pro->build_dir + "/" + pro->project_name + " " + command_args; + } #else std::string command = "cmake . && make && ./" + pro->build_dir + "/" + pro->project_name; + std::string current_build_server= std::string(std::getenv("HOME")) + "/.config/cmaker/" + "current_build_server.json"; + json current_build_server_json = json::parse(std::ifstream(current_build_server)); + if (!current_build_server_json["name"].is_null()) { + pro->build_server = BuildServer( + + 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(pro->build_server.port) + "' --progress . " + + pro->build_server.username + "@" + pro->build_server.ip + + ":/tmp/cmaker && ssh -p " + std::to_string(pro->build_server.port) + " " + pro->build_server.username + "@" + pro->build_server.ip + + " 'cd /tmp/cmaker && cmake . && make && ./build/new'"; if (args->count("args") != 0) { std::cout << "estamos aqui" << std::endl; std::vector args_vec = args->operator[]("args").as>(); @@ -142,6 +165,7 @@ namespace Command { std::cout << "command_args: " << command_args << std::endl; command = "cmake . && make && ./" + pro->build_dir + "/" + pro->project_name + " " + command_args; + } #endif std::cout << "Running command: " << command << std::endl; @@ -150,22 +174,6 @@ namespace Command { std::cout << "Error running project" << std::endl; } - std::string current_build_server= std::string(std::getenv("HOME")) + "/.config/cmaker/" + "current_build_server.json"; - json current_build_server_json = json::parse(std::ifstream(current_build_server)); - if (!current_build_server_json["name"].is_null()) { - pro->build_server = BuildServer( - - 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() - - ); - } - // Call your recompilation command or any other action you want },path); return true; diff --git a/src/Generators/GitIgnoreGenerator.cpp b/src/Generators/GitIgnoreGenerator.cpp index da9abd5..3f2b1e3 100644 --- a/src/Generators/GitIgnoreGenerator.cpp +++ b/src/Generators/GitIgnoreGenerator.cpp @@ -26,6 +26,9 @@ bool write_gitignore(std::string gitignore, std::filesystem::path gitignore_path CMakeLists.txt.user CMakeFiles/ CMakeCache.txt +Makefile +_deps/ +CMakeCache.txt cmake_install.cmake install_manifest.txt compile_commands.json