Skip to content

Commit

Permalink
remote builds templated out
Browse files Browse the repository at this point in the history
  • Loading branch information
lsproule committed Nov 6, 2023
1 parent be6d33b commit 7afc8f7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/Command/CommandServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Command{
return true;
}

bool getServerPort(std::string& port){
bool getServerPort(int& port){
Prompt<int> *port_promp = new Prompt<int>("Enter the port of the server: ");
port_promp->Run();
port = port_promp->Get();
Expand Down Expand Up @@ -113,7 +113,8 @@ Usage server:
bool serverAdd(std::vector<BuildServer> 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);
Expand All @@ -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<json> build_server_json;
Expand Down
50 changes: 29 additions & 21 deletions src/Command/CommandWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -88,9 +88,9 @@ namespace Command {

}
std::cout << buffer << std::endl;
changeCallback();

}
changeCallback();
}


Expand Down Expand Up @@ -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<std::string>(),
current_build_server_json["address"].get<std::string>(),
current_build_server_json["username"].get<std::string>(),
current_build_server_json["authMethod"].get<std::string>(),
current_build_server_json["password"].get<std::string>(),
current_build_server_json["key"].get<std::string>(),
current_build_server_json["port"].get<int>()

);
}
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<std::string> args_vec = args->operator[]("args").as<std::vector<std::string>>();
Expand All @@ -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;
Expand All @@ -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<std::string>(),
current_build_server_json["address"].get<std::string>(),
current_build_server_json["username"].get<std::string>(),
current_build_server_json["authMethod"].get<std::string>(),
current_build_server_json["password"].get<std::string>(),
current_build_server_json["key"].get<std::string>(),
current_build_server_json["port"].get<int>()

);
}

// Call your recompilation command or any other action you want
},path);
return true;
Expand Down
3 changes: 3 additions & 0 deletions src/Generators/GitIgnoreGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7afc8f7

Please sign in to comment.