From da9d3965759f2fd3046180904089dced4e76a070 Mon Sep 17 00:00:00 2001 From: Riccardo De Benedictis Date: Wed, 15 Jan 2025 12:02:50 +0100 Subject: [PATCH] Update build configuration and server implementation - Add npm install and build targets for the oRatio GUI in CMakeLists.txt - Update .gitignore to include additional files - Modify server constructor to use a relative path for assets directory - Implement assets route in the server to serve static files - Enhance main function to handle multiple input files and output solution - Update submodule references for rationet and riddle --- .gitignore | 4 +++- CMakeLists.txt | 3 +++ extern/rationet | 2 +- extern/riddle | 2 +- include/server/solver_server.hpp | 3 ++- src/server/main.cpp | 37 ++++++++++++++++++++++++++++++++ src/server/solver_server.cpp | 17 ++++++++++++--- 7 files changed, 61 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 6a8bc10..07eb1d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .vscode -build \ No newline at end of file +.z3-trace +build +solution.json \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index aa2f7d1..9c1f225 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,9 @@ if(BUILD_ORATIO_SERVER) target_link_libraries(oRatioServer PUBLIC oRatioLib ratioNet) setup_sanitizers(oRatioServer) + + add_custom_target(npm_install ALL COMMAND npm install WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/gui COMMENT "Installing the oRatio GUI" VERBATIM) + add_custom_target(npm_build ALL COMMAND npm run build WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/gui COMMENT "Building the oRatio GUI" VERBATIM DEPENDS npm_install) endif() if(BUILD_TESTING) diff --git a/extern/rationet b/extern/rationet index 0b8b59d..6c03365 160000 --- a/extern/rationet +++ b/extern/rationet @@ -1 +1 @@ -Subproject commit 0b8b59d8d4417f694da34f96450f84b40aa7b738 +Subproject commit 6c03365a8d722a064910402b5adb8a002a12fa1d diff --git a/extern/riddle b/extern/riddle index 49e74a4..e4c23fc 160000 --- a/extern/riddle +++ b/extern/riddle @@ -1 +1 @@ -Subproject commit 49e74a4f63612031eef172890b08d5cf1c709c06 +Subproject commit e4c23fca38c55a9a6e197a22005f82d2837bc843 diff --git a/include/server/solver_server.hpp b/include/server/solver_server.hpp index 9716804..6912959 100644 --- a/include/server/solver_server.hpp +++ b/include/server/solver_server.hpp @@ -16,10 +16,11 @@ namespace ratio::server #endif { public: - server(std::string_view assets_dir = "/gui/dist"); + server(std::string_view assets_dir = "./gui/dist"); private: std::unique_ptr index(const network::request &req); + std::unique_ptr assets(const network::request &req); private: void state_changed() override; diff --git a/src/server/main.cpp b/src/server/main.cpp index a6160cb..aea070a 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -1,6 +1,43 @@ #include "solver_server.hpp" +#include "logging.hpp" +#include int main(int argc, char const *argv[]) { + if (argc < 3) + { + LOG_FATAL("usage: oRatio [ ...] "); + return -1; + } + + // the problem files.. + std::vector prob_names; + for (int i = 1; i < argc - 1; i++) + prob_names.push_back(argv[i]); + + // the solution file.. + std::string sol_name = argv[argc - 1]; + + LOG_INFO("starting oRatio server"); + + ratio::server::server server; + + auto srv_ft = std::async(std::launch::async, [&server] + { server.start(); }); + std::this_thread::sleep_for(std::chrono::seconds(1)); + server.read(prob_names); + + if (server.solve()) + { + LOG_INFO("hurray!! we have found a solution.."); + + std::ofstream sol_file; + sol_file.open(sol_name); + sol_file << server.to_json().dump(); + sol_file.close(); + } + else + LOG_INFO("the problem is unsolvable.."); + return 0; } diff --git a/src/server/solver_server.cpp b/src/server/solver_server.cpp index 8de8c6b..dc397c2 100644 --- a/src/server/solver_server.cpp +++ b/src/server/solver_server.cpp @@ -3,15 +3,26 @@ namespace ratio::server { #if defined(SEMITONE) - server::server() : network::server(), ratio::semitonesolver() + server::server() : network::server(SERVER_HOST, SERVER_PORT, 1), ratio::semitonesolver() #elif defined(Z3) - server::server(std::string_view assets_dir) : network::server(), ratio::z3solver(), assets_dir(assets_dir) + server::server(std::string_view assets_dir) : network::server(SERVER_HOST, SERVER_PORT, 1), ratio::z3solver(), assets_dir(assets_dir) #endif { add_route(network::Get, "^/$", std::bind(&server::index, this, network::placeholders::request)); + add_route(network::Get, "^(/assets/.+)|/.+\\.ico|/.+\\.png", std::bind(&server::assets, this, network::placeholders::request)); } - std::unique_ptr server::index(const network::request &) { return std::make_unique(assets_dir + "/index.html"); } + std::unique_ptr server::index(const network::request &) + { + return std::make_unique(assets_dir + "/index.html"); + } + std::unique_ptr server::assets(const network::request &req) + { + std::string target = req.get_target(); + if (target.find('?') != std::string::npos) + target = target.substr(0, target.find('?')); + return std::make_unique(assets_dir + target); + } void server::state_changed() {} void server::flaw_created(const ratio::flaw &f) {}