From 07fc102376402fc1beb5fa0864adbdf51cb45375 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Fri, 24 Jun 2022 23:09:35 +0100 Subject: [PATCH] Improve Revision System (mangosthree/server#52) Improve issue and bug reporting with Git Hash tracking --- .gitignore | 4 + CMakeLists.txt | 5 ++ cmake/GenRevision.cmake | 81 ++++++++++++++++++++ cmake/StatusInfo.cmake | 7 ++ src/CMakeLists.txt | 10 +++ src/game/ChatCommands/ServerCommands.cpp | 5 ++ src/genrev/CMakeLists.txt | 23 ++++++ src/mangosd/mangosd.cpp | 5 +- src/realmd | 2 +- src/shared/CMakeLists.txt | 4 + src/shared/Common/GitRevision.cpp | 97 ++++++++++++++++++++++++ src/shared/Common/GitRevision.h | 52 +++++++++++++ src/shared/SystemConfig.h.in | 36 --------- src/shared/revision_data.h.in | 40 ++++++++++ 14 files changed, 333 insertions(+), 38 deletions(-) create mode 100644 cmake/GenRevision.cmake create mode 100644 src/genrev/CMakeLists.txt create mode 100644 src/shared/Common/GitRevision.cpp create mode 100644 src/shared/Common/GitRevision.h create mode 100644 src/shared/revision_data.h.in diff --git a/.gitignore b/.gitignore index 618749bd..f8c8a596 100644 --- a/.gitignore +++ b/.gitignore @@ -120,5 +120,9 @@ msbuild.cmd /src/tools/Extractor_Binaries/*.exe +# Skip Git Revision created file +/src/shared/revision_data.h + + # File generated during compile /dep/libmpq/compile diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bbb01fd..e5de65e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,10 @@ else() endif() endif() +if(NOT WITHOUT_GIT) + find_package(Git) +endif() + find_package(Threads REQUIRED) find_package(MySQL REQUIRED) find_package(DL REQUIRED) @@ -107,6 +111,7 @@ find_package(BZip2 QUIET) find_package(OpenSSL REQUIRED) +include(${CMAKE_SOURCE_DIR}/cmake/GenRevision.cmake) include(${CMAKE_SOURCE_DIR}/cmake/EnsureVersion.cmake) include(${CMAKE_SOURCE_DIR}/cmake/MangosParams.cmake) diff --git a/cmake/GenRevision.cmake b/cmake/GenRevision.cmake new file mode 100644 index 00000000..484a1111 --- /dev/null +++ b/cmake/GenRevision.cmake @@ -0,0 +1,81 @@ + +if(NOT BUILDDIR) + # Workaround for funny MSVC behaviour - this segment is only used when using cmake gui + set(BUILDDIR ${CMAKE_BINARY_DIR}) +endif() + +if(WITHOUT_GIT) + set(rev_date "1970-01-01 00:00:00 +0000") + set(rev_hash "unknown") + set(rev_branch "Archived") + + # No valid git commit date, use compiled date + string(TIMESTAMP rev_date_fallback "%Y-%m-%d %H:%M:%S" UTC) +else() + if(GIT_EXECUTABLE) + # Create a revision-string that we can use + execute_process( + COMMAND "${GIT_EXECUTABLE}" describe --long --match init --dirty=+ --abbrev=12 --always + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE rev_info + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + + # And grab the commits timestamp + execute_process( + COMMAND "${GIT_EXECUTABLE}" show -s --format=%ci + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE rev_date + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + + # Also retrieve branch name + execute_process( + COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE rev_branch + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + endif() + + # Last minute check - ensure that we have a proper revision + # If everything above fails (means the user has erased the git revision control directory or removed the origin/HEAD tag) + if(NOT rev_info) + # No valid ways available to find/set the revision/hash, so let's force some defaults + message(STATUS " + Could not find a proper repository signature (hash) - you may need to pull tags with git fetch -t + Continuing anyway - note that the versionstring will be set to \"unknown 1970-01-01 00:00:00 (Archived)\"") + set(rev_date "1970-01-01 00:00:00 +0000") + set(rev_hash "unknown") + set(rev_branch "Archived") + + # No valid git commit date, use compiled date + string(TIMESTAMP rev_date_fallback "%Y-%m-%d %H:%M:%S" UTC) + else() + # We have valid date from git commit, use it + set(rev_date_fallback ${rev_date}) + + # Extract information required to build a proper versionstring + string(REGEX REPLACE init-|[0-9]+-g "" rev_hash ${rev_info}) + endif() +endif() + +# For package / copyright information we always need proper date +string(REGEX MATCH "([0-9]+)-([0-9]+)-([0-9]+)" rev_date_fallback_match ${rev_date_fallback}) +set(rev_year ${CMAKE_MATCH_1}) +set(rev_month ${CMAKE_MATCH_2}) +set(rev_day ${CMAKE_MATCH_3}) + +# Create the actual revision_data.h file from the above params +if(NOT "${rev_hash_cached}" MATCHES "${rev_hash}" OR NOT "${rev_branch_cached}" MATCHES "${rev_branch}" OR NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/src/shared/revision_data.h") + configure_file( + "${CMAKE_SOURCE_DIR}/src/shared/revision_data.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/src/shared/revision_data.h" + @ONLY + ) + set(rev_hash_cached "${rev_hash}" CACHE INTERNAL "Cached commit-hash") + set(rev_branch_cached "${rev_branch}" CACHE INTERNAL "Cached branch name") +endif() diff --git a/cmake/StatusInfo.cmake b/cmake/StatusInfo.cmake index d2ea47e3..1841d335 100644 --- a/cmake/StatusInfo.cmake +++ b/cmake/StatusInfo.cmake @@ -1,8 +1,15 @@ message("===================================================") +message("Mangos revision : ${rev_hash} ${rev_date} (${rev_branch} branch)") message("Build type : ${CMAKE_BUILD_TYPE}") message("Install server(s) to : ${BIN_DIR}") message("Install configs to : ${CONF_INSTALL_DIR}") +message("") +message("Detailed Information") +message("+-- opeating system : ${CMAKE_HOST_SYSTEM}") +message("+-- cmake version : ${CMAKE_VERSION}") +message("") + if(BUILD_MANGOSD) message("Build main server : Yes (default)") if(SCRIPT_LIB_ELUNA) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 01a7ddfd..d6f44b86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,21 +17,31 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# Build the mangos shared library add_subdirectory(shared) +add_subdirectory(genrev) + +# Needs to link against mangos_world.lib if(BUILD_MANGOSD OR BUILD_TOOLS) + # Build the mangos game library add_subdirectory(game) endif() if(BUILD_MANGOSD) + # Build the mangos world server add_subdirectory(mangosd) + + # Build the selected modules add_subdirectory(modules) endif() +# Build the mangos realm authentication server if(BUILD_REALMD) add_subdirectory(realmd) endif() +# If we want the tools for map/vmap/mmap extraction if(BUILD_TOOLS) add_subdirectory(tools) endif() diff --git a/src/game/ChatCommands/ServerCommands.cpp b/src/game/ChatCommands/ServerCommands.cpp index beb235af..0ec3e8b0 100644 --- a/src/game/ChatCommands/ServerCommands.cpp +++ b/src/game/ChatCommands/ServerCommands.cpp @@ -26,9 +26,11 @@ #include "Language.h" #include "World.h" #include "Config.h" +#include "GitRevision.h" #include "SystemConfig.h" #include "UpdateTime.h" #include "revision.h" +#include "revision_data.h" /********************************************************************** CommandTable : serverCommandTable @@ -65,6 +67,9 @@ bool ChatHandler::HandleServerInfoCommand(char* /*args*/) SendSysMessage(LANG_USING_SCRIPT_LIB_NONE); } + PSendSysMessage("%s", GitRevision::GetFullRevision()); + PSendSysMessage("%s", GitRevision::GetRunningSystem()); + PSendSysMessage(LANG_USING_WORLD_DB, sWorld.GetDBVersion()); PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum); PSendSysMessage(LANG_UPTIME, str.c_str()); diff --git a/src/genrev/CMakeLists.txt b/src/genrev/CMakeLists.txt new file mode 100644 index 00000000..6763762a --- /dev/null +++ b/src/genrev/CMakeLists.txt @@ -0,0 +1,23 @@ +# MaNGOS is a full featured server for World of Warcraft, supporting +# the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 +# +# Copyright (C) 2005-2022 MaNGOS +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +add_custom_target(revision_data.h ALL + COMMAND "${CMAKE_COMMAND}" -DBUILDDIR="${CMAKE_BINARY_DIR}" -P "${CMAKE_SOURCE_DIR}/cmake/GenRevision.cmake" "${CMAKE_BINARY_DIR}" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" +) diff --git a/src/mangosd/mangosd.cpp b/src/mangosd/mangosd.cpp index b9bca30b..974465de 100644 --- a/src/mangosd/mangosd.cpp +++ b/src/mangosd/mangosd.cpp @@ -34,11 +34,13 @@ #include "Common.h" #include "Database/DatabaseEnv.h" #include "Config/Config.h" +#include "GitRevision.h" #include "ProgressBar.h" #include "Log.h" #include "SystemConfig.h" #include "AuctionHouseBot.h" #include "revision.h" +#include "revision_data.h" #include "World.h" #include "Util.h" #include "DBCStores.h" @@ -385,10 +387,11 @@ int main(int argc, char** argv) #endif sLog.outString("%s [world-daemon]", REVISION_NR); + sLog.outString("%s", GitRevision::GetFullRevision()); print_banner(); sLog.outString("Using configuration file %s.", cfg_file); - DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); + DETAIL_LOG("Using SSL version: %s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); if (SSLeay() < 0x009080bfL) { DETAIL_LOG("WARNING: Outdated version of OpenSSL lib. Logins to server may not work!"); diff --git a/src/realmd b/src/realmd index 1f668a7a..7d70f55a 160000 --- a/src/realmd +++ b/src/realmd @@ -1 +1 @@ -Subproject commit 1f668a7a2cc7bb730ba51a2341ce345f19617168 +Subproject commit 7d70f55a347aec7ccd2010dcf9e715560e95fad3 diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 9e6c1fef..b9f9dd21 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -40,6 +40,8 @@ set(SRC_GRP_COMMON Common/Common.cpp Common/Common.h Common/ServerDefines.h + Common/GitRevision.cpp + Common/GitRevision.h ) source_group("Common" FILES ${SRC_GRP_COMMON}) @@ -186,6 +188,7 @@ set(TGT_INCL Policies ) +configure_file(revision_data.h.in ${CMAKE_CURRENT_BINARY_DIR}/revision_data.h) configure_file(SystemConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/SystemConfig.h) TEST_BIG_ENDIAN(ENDIAN_VALUE) @@ -206,6 +209,7 @@ add_library(shared STATIC ${SRC_GRP_SVC} ${SRC_GRP_UTILITIES} revision.h + ${CMAKE_CURRENT_BINARY_DIR/revision_data.h} ${CMAKE_CURRENT_BINARY_DIR/SystemConfig.h} ) diff --git a/src/shared/Common/GitRevision.cpp b/src/shared/Common/GitRevision.cpp new file mode 100644 index 00000000..f063fbd7 --- /dev/null +++ b/src/shared/Common/GitRevision.cpp @@ -0,0 +1,97 @@ +/** + * MaNGOS is a full featured server for World of Warcraft, supporting + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 + * + * Copyright (C) 2005-2022 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + +#include "GitRevision.h" + +char const* GitRevision::GetHash() +{ + return REVISION_HASH; +} + +char const* GitRevision::GetDate() +{ + return REVISION_DATE; +} + +char const* GitRevision::GetBranch() +{ + return REVISION_BRANCH; +} + +char const* GitRevision::GetCMakeVersion() +{ + return CMAKE_VERSION; +} + +char const* GitRevision::GetHostOSVersion() +{ + return "Compiled on: " CMAKE_HOST_SYSTEM; +} + +// Platform Define +#if PLATFORM == PLATFORM_WINDOWS + #ifdef _WIN64 + #define MANGOS_PLATFORM_STR "Win64" + #else + #define MANGOS_PLATFORM_STR "Win32" + #endif +#elif PLATFORM == PLATFORM_APPLE + #define MANGOS_PLATFORM_STR "MacOSX" +#elif PLATFORM == PLATFORM_INTEL + #define MANGOS_PLATFORM_STR "Intel" +#elif PLATFORM == PLATFORM_UNIX + #define MANGOS_PLATFORM_STR "Linux" +#else + #define MANGOS_PLATFORM_STR "Unknown System" +#endif + +char const* GitRevision::GetFullRevision() +{ + return "Mangos revision: " VER_PRODUCTVERSION_STR; +} + +char const* GitRevision::GetRunningSystem() +{ + return "Running on: " CMAKE_HOST_SYSTEM; +} + +char const* GitRevision::GetCompanyNameStr() +{ + return VER_COMPANY_NAME_STR; +} + +char const* GitRevision::GetLegalCopyrightStr() +{ + return VER_LEGALCOPYRIGHT_STR; +} + +char const* GitRevision::GetFileVersionStr() +{ + return VER_FILEVERSION_STR; +} + +char const* GitRevision::GetProductVersionStr() +{ + return VER_PRODUCTVERSION_STR; +} diff --git a/src/shared/Common/GitRevision.h b/src/shared/Common/GitRevision.h new file mode 100644 index 00000000..711aa78e --- /dev/null +++ b/src/shared/Common/GitRevision.h @@ -0,0 +1,52 @@ +/** + * MaNGOS is a full featured server for World of Warcraft, supporting + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 + * + * Copyright (C) 2005-2022 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + +#ifndef GITREVISION_H +#define GITREVISION_H + +#include "Define.h" + +#include "revision_data.h" + +namespace GitRevision +{ + // github data + char const* GetHash(); + char const* GetDate(); + char const* GetBranch(); + + // system data + char const* GetCMakeVersion(); + char const* GetHostOSVersion(); + char const* GetRunningSystem(); + + // application data + char const* GetFullRevision(); + char const* GetCompanyNameStr(); + char const* GetLegalCopyrightStr(); + char const* GetFileVersionStr(); + char const* GetProductVersionStr(); +} + +#endif diff --git a/src/shared/SystemConfig.h.in b/src/shared/SystemConfig.h.in index d79ce60a..d635f022 100644 --- a/src/shared/SystemConfig.h.in +++ b/src/shared/SystemConfig.h.in @@ -55,41 +55,6 @@ # define MANGOS_ENDIAN_STRING "little-endian" #endif -#if defined(i386) || defined(__i386) || defined(__i386__) || defined(_M_IX86) -# define ARCHITECTURE "x86" -#elif defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(_M_X64) -# define ARCHITECTURE "x64" -#elif defined(__ia64) || defined(__IA64__) || defined(_M_IA64) -# define ARCHITECTURE "IA64" -#else -# define ARCHITECTURE "x86" -#endif - -#if PLATFORM == PLATFORM_WINDOWS -# ifdef _WIN64 -# define MANGOS_ENDIAN_PLATFORM "Win64 (" MANGOS_ENDIAN_STRING ")" -# else -# define MANGOS_ENDIAN_PLATFORM "Win32 (" MANGOS_ENDIAN_STRING ")" -# endif -#else -# if defined (__FreeBSD__) -# define MANGOS_ENDIAN_PLATFORM "FreeBSD_" ARCHITECTURE " (" MANGOS_ENDIAN_STRING ")" -# elif defined(__NetBSD__) -# define MANGOS_ENDIAN_PLATFORM "NetBSD_" ARCHITECTURE " (" MANGOS_ENDIAN_STRING ")" -# elif defined(__OpenBSD__) -# define MANGOS_ENDIAN_PLATFORM "OpenBSD_" ARCHITECTURE " (" MANGOS_ENDIAN_STRING ")" -# elif defined(__DragonFly__) -# define MANGOS_ENDIAN_PLATFORM "DragonFlyBSD_" ARCHITECTURE " (" MANGOS_ENDIAN_STRING ")" -# elif defined(__APPLE__) -# define MANGOS_ENDIAN_PLATFORM "MacOSX_" ARCHITECTURE " (" MANGOS_ENDIAN_STRING ")" -# elif defined(__linux) || defined(__linux__) -# define MANGOS_ENDIAN_PLATFORM "Linux_" ARCHITECTURE " (" MANGOS_ENDIAN_STRING ")" -# else -# define MANGOS_ENDIAN_PLATFORM "Unix_" ARCHITECTURE " (" MANGOS_ENDIAN_STRING ")" -# endif -#endif - - #define SYSCONFDIR "@CONF_INSTALL_DIR@/" @@ -101,7 +66,6 @@ #define REALMD_CONFIG_LOCATION SYSCONFDIR REALMD_CONFIG_NAME #define AUCTIONHOUSEBOT_CONFIG_LOCATION SYSCONFDIR AUCTIONHOUSEBOT_CONFIG_NAME -#define MANGOS_FULLVERSION(REVD,REVT,REVN,REVH) MANGOS_PACKAGENAME "/" MANGOS_VERSION(REVD,REVT,REVN,REVH) " for " MANGOS_ENDIAN_PLATFORM #define DEFAULT_PLAYER_LIMIT 100 #define DEFAULT_WORLDSERVER_PORT 8085 //8129 diff --git a/src/shared/revision_data.h.in b/src/shared/revision_data.h.in new file mode 100644 index 00000000..027cb7b4 --- /dev/null +++ b/src/shared/revision_data.h.in @@ -0,0 +1,40 @@ +/** + * MaNGOS is a full featured server for World of Warcraft, supporting + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 + * + * Copyright (C) 2005-2022 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + +#ifndef REVISION_DATA_H +#define REVISION_DATA_H + #define REVISION_HASH "@rev_hash@" + #define REVISION_DATE "@rev_date@" + #define REVISION_BRANCH "@rev_branch@" + + #define CMAKE_VERSION R"(@CMAKE_VERSION@)" + #define CMAKE_HOST_SYSTEM R"(@CMAKE_HOST_SYSTEM_NAME@ @CMAKE_HOST_SYSTEM_VERSION@)" + + #define VER_COMPANY_NAME_STR "MaNGOS Developers" + #define VER_LEGALCOPYRIGHT_STR "(c)2005-@rev_year@ MaNGOS" + #define VER_FILEVERSION 0,0,0 + #define VER_FILEVERSION_STR "@rev_hash@ @rev_date@ (@rev_branch@ branch)" + #define VER_PRODUCTVERSION VER_FILEVERSION + #define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR +#endif