From 8bc7ea61b901516d3e1cbde77df1830d14129259 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Wed, 25 Sep 2013 04:29:07 +0200 Subject: [PATCH] Show git hash in version string at top left corner of window --- .gitignore | 1 + CMakeLists.txt | 3 +++ cmake/Modules/GenerateVersion.cmake | 20 +++++++++++++++ src/CMakeLists.txt | 12 +++++++++ src/cmake_config.h.in | 2 +- src/cmake_config_githash.h.in | 10 ++++++++ src/config.h | 6 ----- src/game.cpp | 10 ++++---- src/guiEngine.cpp | 5 ++-- src/guiPauseMenu.cpp | 3 ++- src/main.cpp | 3 ++- src/script/lua_api/l_mainmenu.cpp | 3 ++- src/server.cpp | 9 ++++--- src/serverlist.cpp | 3 ++- src/version.cpp | 39 +++++++++++++++++++++++++++++ src/version.h | 30 ++++++++++++++++++++++ 16 files changed, 137 insertions(+), 22 deletions(-) create mode 100644 cmake/Modules/GenerateVersion.cmake create mode 100644 src/cmake_config_githash.h.in create mode 100644 src/version.cpp create mode 100644 src/version.h diff --git a/.gitignore b/.gitignore index db131c29f..2e1584b1d 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ CMakeFiles/* src/CMakeFiles/* src/Makefile src/cmake_config.h +src/cmake_config_githash.h src/cmake_install.cmake src/script/CMakeFiles/* src/script/common/CMakeFiles/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 2db4e4a76..f9fff75db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,9 @@ set(VERSION_MINOR 4) set(VERSION_PATCH 7) if(VERSION_EXTRA) set(VERSION_PATCH ${VERSION_PATCH}-${VERSION_EXTRA}) +else() + # Comment the following line during release + set(VERSION_PATCH ${VERSION_PATCH}-dev) endif() set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") diff --git a/cmake/Modules/GenerateVersion.cmake b/cmake/Modules/GenerateVersion.cmake new file mode 100644 index 000000000..4a7f183da --- /dev/null +++ b/cmake/Modules/GenerateVersion.cmake @@ -0,0 +1,20 @@ +# Always run during 'make' + +if(VERSION_EXTRA) + set(VERSION_GITHASH "${VERSION_STRING}") +else(VERSION_EXTRA) + execute_process(COMMAND git describe --always --tag --dirty + WORKING_DIRECTORY "${GENERATE_VERSION_SOURCE_DIR}" + OUTPUT_VARIABLE VERSION_GITHASH OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + + if(VERSION_GITHASH) + message(STATUS "*** Detected git version ${VERSION_GITHASH} ***") + else() + set(VERSION_GITHASH "${VERSION_STRING}") + endif() +endif() + +configure_file( + ${GENERATE_VERSION_SOURCE_DIR}/cmake_config_githash.h.in + ${GENERATE_VERSION_BINARY_DIR}/cmake_config_githash.h) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a5212dca..4d99f5acd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -225,11 +225,21 @@ configure_file( "${PROJECT_BINARY_DIR}/cmake_config.h" ) +# Add a target that always rebuilds cmake_config_githash.h +add_custom_target(GenerateVersion + COMMAND ${CMAKE_COMMAND} + -D "GENERATE_VERSION_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}" + -D "GENERATE_VERSION_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}" + -D "VERSION_STRING=${VERSION_STRING}" + -P "${CMAKE_SOURCE_DIR}/cmake/Modules/GenerateVersion.cmake" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_subdirectory(jthread) add_subdirectory(script) add_subdirectory(util) set(common_SRCS + version.cpp rollback_interface.cpp rollback.cpp genericobject.cpp @@ -406,6 +416,7 @@ set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin") if(BUILD_CLIENT) add_executable(${PROJECT_NAME} ${minetest_SRCS}) + add_dependencies(${PROJECT_NAME} GenerateVersion) target_link_libraries( ${PROJECT_NAME} ${ZLIB_LIBRARIES} @@ -444,6 +455,7 @@ endif(BUILD_CLIENT) if(BUILD_SERVER) add_executable(${PROJECT_NAME}server ${minetestserver_SRCS}) + add_dependencies(${PROJECT_NAME}server GenerateVersion) target_link_libraries( ${PROJECT_NAME}server ${ZLIB_LIBRARIES} diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index c83df8e47..7cc2fb99e 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -18,7 +18,7 @@ #else #define CMAKE_BUILD_TYPE "Debug" #endif -#define CMAKE_BUILD_INFO "VER=@VERSION_STRING@ BUILD_TYPE="CMAKE_BUILD_TYPE" RUN_IN_PLACE=@RUN_IN_PLACE@ USE_GETTEXT=@USE_GETTEXT@ USE_SOUND=@USE_SOUND@ USE_CURL=@USE_CURL@ USE_FREETYPE=@USE_FREETYPE@ USE_LUAJIT=@USE_LUAJIT@ STATIC_SHAREDIR=@SHAREDIR@" +#define CMAKE_BUILD_INFO "BUILD_TYPE="CMAKE_BUILD_TYPE" RUN_IN_PLACE=@RUN_IN_PLACE@ USE_GETTEXT=@USE_GETTEXT@ USE_SOUND=@USE_SOUND@ USE_CURL=@USE_CURL@ USE_FREETYPE=@USE_FREETYPE@ USE_LUAJIT=@USE_LUAJIT@ STATIC_SHAREDIR=@SHAREDIR@" #endif diff --git a/src/cmake_config_githash.h.in b/src/cmake_config_githash.h.in new file mode 100644 index 000000000..4d5fcd60f --- /dev/null +++ b/src/cmake_config_githash.h.in @@ -0,0 +1,10 @@ +// Filled in by the build system +// Separated from cmake_config.h to avoid excessive rebuilds on every commit + +#ifndef CMAKE_CONFIG_GITHASH_H +#define CMAKE_CONFIG_GITHASH_H + +#define CMAKE_VERSION_GITHASH "@VERSION_GITHASH@" + +#endif + diff --git a/src/config.h b/src/config.h index 3cb59e619..652c9008a 100644 --- a/src/config.h +++ b/src/config.h @@ -7,22 +7,18 @@ #define CONFIG_H #define PROJECT_NAME "Minetest" -#define VERSION_STRING "unknown" #define RUN_IN_PLACE 0 #define USE_GETTEXT 0 #define USE_SOUND 0 #define USE_CURL 0 #define USE_FREETYPE 0 #define STATIC_SHAREDIR "" -#define BUILD_INFO "non-cmake" #define USE_LEVELDB 0 #ifdef USE_CMAKE_CONFIG_H #include "cmake_config.h" #undef PROJECT_NAME #define PROJECT_NAME CMAKE_PROJECT_NAME - #undef VERSION_STRING - #define VERSION_STRING CMAKE_VERSION_STRING #undef RUN_IN_PLACE #define RUN_IN_PLACE CMAKE_RUN_IN_PLACE #undef USE_GETTEXT @@ -35,8 +31,6 @@ #define USE_FREETYPE CMAKE_USE_FREETYPE #undef STATIC_SHAREDIR #define STATIC_SHAREDIR CMAKE_STATIC_SHAREDIR - #undef BUILD_INFO - #define BUILD_INFO CMAKE_BUILD_INFO #undef USE_LEVELDB #define USE_LEVELDB CMAKE_USE_LEVELDB #endif diff --git a/src/game.cpp b/src/game.cpp index 851f5dd9d..71a578a65 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -37,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "tool.h" #include "guiChatConsole.h" #include "config.h" +#include "version.h" #include "clouds.h" #include "particles.h" #include "camera.h" @@ -2963,9 +2964,6 @@ void the_game( //TimeTaker guiupdatetimer("Gui updating"); - const char program_name_and_version[] = - "Minetest " VERSION_STRING; - if(show_debug) { static float drawtime_avg = 0; @@ -2979,7 +2977,7 @@ void the_game( std::ostringstream os(std::ios_base::binary); os<setText(narrow_to_wide(os.str()).c_str()); guitext->setVisible(true); } else diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index 547f393a4..ac19274c3 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "scripting_mainmenu.h" #include "config.h" +#include "version.h" #include "porting.h" #include "filesys.h" #include "main.h" @@ -157,7 +158,7 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, //create topleft header core::rect rect(0, 0, 500, 40); rect += v2s32(4, 0); - std::string t = "Minetest " VERSION_STRING; + std::string t = std::string("Minetest ") + minetest_version_hash; m_irr_toplefttext = m_device->getGUIEnvironment()->addStaticText(narrow_to_wide(t).c_str(), @@ -553,7 +554,7 @@ bool GUIEngine::downloadFile(std::string url,std::string target) { /******************************************************************************/ void GUIEngine::setTopleftText(std::string append) { - std::string toset = "Minetest " VERSION_STRING; + std::string toset = std::string("Minetest ") + minetest_version_hash; if (append != "") { toset += " / "; diff --git a/src/guiPauseMenu.cpp b/src/guiPauseMenu.cpp index f5d323a9b..ba103b740 100644 --- a/src/guiPauseMenu.cpp +++ b/src/guiPauseMenu.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serialization.h" #include "porting.h" #include "config.h" +#include "version.h" #include "main.h" #include #include @@ -195,7 +196,7 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize) std::ostringstream os; os<<"Minetest\n"; - os<addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259); diff --git a/src/main.cpp b/src/main.cpp index f34e24abc..10547b711 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiMessageMenu.h" #include "filesys.h" #include "config.h" +#include "version.h" #include "guiMainMenu.h" #include "game.h" #include "keycode.h" @@ -903,7 +904,7 @@ int main(int argc, char *argv[]) // Print startup message infostream<get("server_name"); server["description"] = g_settings->get("server_description"); - server["version"] = VERSION_STRING; + server["version"] = minetest_version_simple; server["url"] = g_settings->get("server_url"); server["creative"] = g_settings->get("creative_mode"); server["damage"] = g_settings->get("enable_damage"); diff --git a/src/version.cpp b/src/version.cpp new file mode 100644 index 000000000..e5de8a61e --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,39 @@ +/* +Minetest +Copyright (C) 2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "version.h" +#include "config.h" + +#ifdef USE_CMAKE_CONFIG_H + +#include "cmake_config_githash.h" + +const char *minetest_version_simple = CMAKE_VERSION_STRING; +const char *minetest_version_hash = CMAKE_VERSION_GITHASH; +const char *minetest_build_info = + "VER=" CMAKE_VERSION_GITHASH " " CMAKE_BUILD_INFO; + +#else + +const char *minetest_version_simple = "unknown"; +const char *minetest_version_hash = "unknown"; +const char *minetest_build_info = "non-cmake"; + +#endif + diff --git a/src/version.h b/src/version.h new file mode 100644 index 000000000..0143d91a4 --- /dev/null +++ b/src/version.h @@ -0,0 +1,30 @@ +/* +Minetest +Copyright (C) 2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef VERSION_HEADER +#define VERSION_HEADER + +#include "config.h" + +extern const char *minetest_version_simple; +extern const char *minetest_version_hash; +extern const char *minetest_build_info; + +#endif +