From f3660d78403f8c21faaa0faeec4eee0b127ada43 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Sun, 28 Jul 2013 21:37:37 +0100 Subject: [PATCH] Updated build system to incorporate libgit2. Also, VCS picking is done by looking to see if ".git" is in the remote URL or not. --- CMakeLists.txt | 4 +- README.md | 16 ++++-- src/backend/network.cpp | 110 ++++++++++++++++++++++------------------ 3 files changed, 73 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79d0ed21..ce1ff81c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set (BOSS_SRC "${CMAKE_SOURCE_DIR}/src/backend/metadata.cpp" "${CMAKE_SOURCE_DIR set (BOSS_SRC ${BOSS_SRC} "${PROJECT_LIBS_DIR}/boost/libs/iostreams/src/file_descriptor.cpp") # Include source and library directories. -include_directories ("${PROJECT_LIBS_DIR}/alphanum" "${PROJECT_LIBS_DIR}/boost" "${PROJECT_LIBS_DIR}/yaml-cpp/include" "${CMAKE_SOURCE_DIR}/src" "${PROJECT_LIBS_DIR}/libloadorder/src" "${PROJECT_LIBS_DIR}/libespm" "${PROJECT_LIBS_DIR}/zlib" "${PROJECT_LIBS_DIR}/pugixml/src" "${PROJECT_LIBS_DIR}/wxWidgets/include") +include_directories ("${PROJECT_LIBS_DIR}/alphanum" "${PROJECT_LIBS_DIR}/boost" "${PROJECT_LIBS_DIR}/yaml-cpp/include" "${CMAKE_SOURCE_DIR}/src" "${PROJECT_LIBS_DIR}/libloadorder/src" "${PROJECT_LIBS_DIR}/libespm" "${PROJECT_LIBS_DIR}/zlib" "${PROJECT_LIBS_DIR}/pugixml/src" "${PROJECT_LIBS_DIR}/wxWidgets/include" "${PROJECT_LIBS_DIR}/libgit2/include") ############################## @@ -61,7 +61,7 @@ IF (CMAKE_HOST_SYSTEM_NAME MATCHES "Linux") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,windows") ENDIF () - set (BOSS_LIBS ${BOSS_LIBS} zlibstatic loadorder${PROJECT_ARCH} yaml-cpp boost_log_setup boost_log boost_locale boost_thread_win32 boost_chrono boost_date_time boost_filesystem boost_system boost_regex) + set (BOSS_LIBS ${BOSS_LIBS} git2 zlibstatic loadorder${PROJECT_ARCH} yaml-cpp boost_log_setup boost_log boost_locale boost_thread_win32 boost_chrono boost_date_time boost_filesystem boost_system boost_regex) ENDIF () # Settings when compiling on Windows. diff --git a/README.md b/README.md index 82530556..32c56836 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,7 @@ echo "using gcc : 4.6.3 : i686-w64-mingw32-g++ : i686-w64-mingw32-windres +#include + #if _WIN32 || _WIN64 # ifndef UNICODE # define UNICODE @@ -143,69 +145,77 @@ namespace boss { std::string UpdateMasterlist(const Game& game, std::vector& parsingErrors) { - string command, output, revision; - //First check if the working copy is set up or not. - command = g_path_svn.string() + " info \"" + game.MasterlistPath().string() + "\""; + //First need to decide how the masterlist is updated: using Git or Subversion? + //Look at the update URL to decide. - BOOST_LOG_TRIVIAL(trace) << "Checking to see if the working copy is set up or not for the masterlist at \"" + game.MasterlistPath().string() + "\""; - bool success = RunCommand(command, output); + if (game.URL().find(".git") == string::npos) { //Subversion - revision = GetRevision(output); + string command, output, revision; + //First check if the working copy is set up or not. + command = g_path_svn.string() + " info \"" + game.MasterlistPath().string() + "\""; - if (game.URL().empty()) { - if (!revision.empty()) - return revision; - else - return "N/A"; - } + BOOST_LOG_TRIVIAL(trace) << "Checking to see if the working copy is set up or not for the masterlist at \"" + game.MasterlistPath().string() + "\""; + bool success = RunCommand(command, output); - if (!success) { - BOOST_LOG_TRIVIAL(trace) << "Working copy is not set up, checking out repository."; - //Working copy not set up, perform a checkout. - command = g_path_svn.string() + " co --depth empty " + game.URL().substr(0, game.URL().rfind('/')) + " \"" + game.MasterlistPath().parent_path().string() + "\\.\""; + revision = GetRevision(output); + + if (game.URL().empty()) { + if (!revision.empty()) + return revision; + else + return "N/A"; + } + + if (!success) { + BOOST_LOG_TRIVIAL(trace) << "Working copy is not set up, checking out repository."; + //Working copy not set up, perform a checkout. + command = g_path_svn.string() + " co --depth empty " + game.URL().substr(0, game.URL().rfind('/')) + " \"" + game.MasterlistPath().parent_path().string() + "\\.\""; + if (!RunCommand(command, output)) { + BOOST_LOG_TRIVIAL(error) << "Subversion could not perform a checkout. Details: " << output; + throw error(error::subversion_error, "Subversion could not perform a checkout. Details: " + output); + } + } + + //Now update masterlist. + BOOST_LOG_TRIVIAL(trace) << "Performing Subversion update of masterlist."; + command = g_path_svn.string() + " update \"" + game.MasterlistPath().string() + "\""; if (!RunCommand(command, output)) { - BOOST_LOG_TRIVIAL(error) << "Subversion could not perform a checkout. Details: " << output; - throw error(error::subversion_error, "Subversion could not perform a checkout. Details: " + output); + BOOST_LOG_TRIVIAL(error) << "Subversion could not update the masterlist. Details: " << output; + throw error(error::subversion_error, "Subversion could not update the masterlist. Details: " + output); } - } - //Now update masterlist. - BOOST_LOG_TRIVIAL(trace) << "Performing Subversion update of masterlist."; - command = g_path_svn.string() + " update \"" + game.MasterlistPath().string() + "\""; - if (!RunCommand(command, output)) { - BOOST_LOG_TRIVIAL(error) << "Subversion could not update the masterlist. Details: " << output; - throw error(error::subversion_error, "Subversion could not update the masterlist. Details: " + output); - } + while (true) { + try { - while (true) { - try { + //Now get the masterlist revision. + BOOST_LOG_TRIVIAL(trace) << "Getting the new masterlist version."; + command = g_path_svn.string() + " info \"" + game.MasterlistPath().string() + "\""; + if (!RunCommand(command, output)) { + BOOST_LOG_TRIVIAL(error) << "Subversion could not read the masterlist revision number. Details: " << output; + throw error(error::subversion_error, "Subversion could not read the masterlist revision number. Details: " + output); + } - //Now get the masterlist revision. - BOOST_LOG_TRIVIAL(trace) << "Getting the new masterlist version."; - command = g_path_svn.string() + " info \"" + game.MasterlistPath().string() + "\""; - if (!RunCommand(command, output)) { - BOOST_LOG_TRIVIAL(error) << "Subversion could not read the masterlist revision number. Details: " << output; - throw error(error::subversion_error, "Subversion could not read the masterlist revision number. Details: " + output); - } + BOOST_LOG_TRIVIAL(trace) << "Reading the masterlist version from the svn info output."; + revision = GetRevision(output); - BOOST_LOG_TRIVIAL(trace) << "Reading the masterlist version from the svn info output."; - revision = GetRevision(output); + //Now test masterlist to see if it parses OK. + BOOST_LOG_TRIVIAL(trace) << "Testing the new masterlist to see if it parses OK."; + YAML::Node mlist = YAML::LoadFile(game.MasterlistPath().string()); - //Now test masterlist to see if it parses OK. - BOOST_LOG_TRIVIAL(trace) << "Testing the new masterlist to see if it parses OK."; - YAML::Node mlist = YAML::LoadFile(game.MasterlistPath().string()); - - return revision; - } catch (YAML::Exception& e) { - //Roll back one revision if there's an error. - BOOST_LOG_TRIVIAL(error) << "Masterlist parsing failed. Masterlist revision " + revision + ": " + e.what(); - parsingErrors.push_back("Masterlist revision " + revision + ": " + e.what()); - command = g_path_svn.string() + " update --revision PREV \"" + game.MasterlistPath().string() + "\""; - if (!RunCommand(command, output)) { - BOOST_LOG_TRIVIAL(error) << "Subversion could not update the masterlist. Details: " << output; - throw error(error::subversion_error, "Subversion could not update the masterlist. Details: " + output); + return revision; + } catch (YAML::Exception& e) { + //Roll back one revision if there's an error. + BOOST_LOG_TRIVIAL(error) << "Masterlist parsing failed. Masterlist revision " + revision + ": " + e.what(); + parsingErrors.push_back("Masterlist revision " + revision + ": " + e.what()); + command = g_path_svn.string() + " update --revision PREV \"" + game.MasterlistPath().string() + "\""; + if (!RunCommand(command, output)) { + BOOST_LOG_TRIVIAL(error) << "Subversion could not update the masterlist. Details: " << output; + throw error(error::subversion_error, "Subversion could not update the masterlist. Details: " + output); + } } } + } else { //Git. + } } }