Show git hash in version string at top left corner of window
authorKahrl <kahrl@gmx.net>
Wed, 25 Sep 2013 02:29:07 +0000 (04:29 +0200)
committerKahrl <kahrl@gmx.net>
Sat, 28 Sep 2013 19:30:17 +0000 (21:30 +0200)
16 files changed:
.gitignore
CMakeLists.txt
cmake/Modules/GenerateVersion.cmake [new file with mode: 0644]
src/CMakeLists.txt
src/cmake_config.h.in
src/cmake_config_githash.h.in [new file with mode: 0644]
src/config.h
src/game.cpp
src/guiEngine.cpp
src/guiPauseMenu.cpp
src/main.cpp
src/script/lua_api/l_mainmenu.cpp
src/server.cpp
src/serverlist.cpp
src/version.cpp [new file with mode: 0644]
src/version.h [new file with mode: 0644]

index db131c29fbb3f410884470b571fad00a80eb5c87..2e1584b1df22346dc917c1a9c79b5423947e9d85 100644 (file)
@@ -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/*
index 2db4e4a76b987b75c6897028f9f3bf5318db3a61..f9fff75db24f01a339ec6866964379a14c6bba30 100644 (file)
@@ -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 (file)
index 0000000..4a7f183
--- /dev/null
@@ -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)
index 8a5212dcabb54a134221727de15bf61df8dc251e..4d99f5acd1208d734867ecf8bd06204e1a374e67 100644 (file)
@@ -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}
index c83df8e47ba53380531656f21fa72015df10c4da..7cc2fb99eefaaa8e224c072e18dddecb2ac6d362 100644 (file)
@@ -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 (file)
index 0000000..4d5fcd6
--- /dev/null
@@ -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
+
index 3cb59e619ba409fb1cfe525e77cc2ec44572057b..652c9008a52b76c40b6b7e3151ab5e56d41c250d 100644 (file)
@@ -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
index 851f5dd9ddeb1703daf3b0ece16cade901bfdbe6..71a578a65b5283b44e7357a746f5fe3359a948d6 100644 (file)
@@ -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<<std::fixed
-                               <<program_name_and_version
+                               <<"Minetest "<<minetest_version_hash
                                <<" (R: range_all="<<draw_control.range_all<<")"
                                <<std::setprecision(0)
                                <<" drawtime = "<<drawtime_avg
@@ -2995,7 +2993,9 @@ void the_game(
                }
                else if(show_hud || show_chat)
                {
-                       guitext->setText(narrow_to_wide(program_name_and_version).c_str());
+                       std::ostringstream os(std::ios_base::binary);
+                       os<<"Minetest "<<minetest_version_hash;
+                       guitext->setText(narrow_to_wide(os.str()).c_str());
                        guitext->setVisible(true);
                }
                else
index 547f393a49ef76375433ee1da8b775ce1990c96b..ac19274c3191581ed37e979082dbd6daabfbe1b3 100644 (file)
@@ -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<s32> 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 += " / ";
index f5d323a9b40d8b45a4ea4138db435e37a5002ca9..ba103b740aa32953b9c8015263ae74625afd0e3c 100644 (file)
@@ -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 <IGUICheckBox.h>
 #include <IGUIEditBox.h>
@@ -195,7 +196,7 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize)
 
                std::ostringstream os;
                os<<"Minetest\n";
-               os<<BUILD_INFO<<"\n";
+               os<<minetest_build_info<<"\n";
                os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";
        
                Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259);
index f34e24abc154296559712f0c836072c9d63126f2..10547b71123d3b86c8daf0e24ed5cbe66f163e91 100644 (file)
@@ -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<<PROJECT_NAME<<
                        " "<<_("with")<<" SER_FMT_VER_HIGHEST_READ="<<(int)SER_FMT_VER_HIGHEST_READ
-                       <<", "<<BUILD_INFO
+                       <<", "<<minetest_build_info
                        <<std::endl;
        
        /*
index 55376690eda01c68e6a0acd845cf6e5eaa1c9ddb..ff0d5277414b4b5090fc464cea3b4239369e2bfb 100644 (file)
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "guiKeyChangeMenu.h"
 #include "guiFileSelectMenu.h"
 #include "subgame.h"
+#include "version.h"
 #include "porting.h"
 #include "filesys.h"
 #include "convert_json.h"
@@ -923,7 +924,7 @@ int ModApiMainMenu::l_show_file_open_dialog(lua_State *L)
 /******************************************************************************/
 int ModApiMainMenu::l_get_version(lua_State *L)
 {
-       lua_pushstring(L,VERSION_STRING);
+       lua_pushstring(L, minetest_version_simple);
        return 1;
 }
 
index 492ad907b1dcdfe1ae0bd5a76029c3fa6b462a4a..c144be1ba13d541cc8e16d7e4b09d83241aacc8c 100644 (file)
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "constants.h"
 #include "voxel.h"
 #include "config.h"
+#include "version.h"
 #include "filesys.h"
 #include "mapblock.h"
 #include "serverobject.h"
@@ -1855,7 +1856,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                        DenyAccess(peer_id, std::wstring(
                                        L"Your client's version is not supported.\n"
                                        L"Server version is ")
-                                       + narrow_to_wide(VERSION_STRING) + L"."
+                                       + narrow_to_wide(minetest_version_simple) + L"."
                        );
                        return;
                }
@@ -1903,7 +1904,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                        DenyAccess(peer_id, std::wstring(
                                        L"Your client's version is not supported.\n"
                                        L"Server version is ")
-                                       + narrow_to_wide(VERSION_STRING) + L",\n"
+                                       + narrow_to_wide(minetest_version_simple) + L",\n"
                                        + L"server's PROTOCOL_VERSION is "
                                        + narrow_to_wide(itos(SERVER_PROTOCOL_VERSION_MIN))
                                        + L"..."
@@ -1925,7 +1926,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                DenyAccess(peer_id, std::wstring(
                                                L"Your client's version is not supported.\n"
                                                L"Server version is ")
-                                               + narrow_to_wide(VERSION_STRING) + L",\n"
+                                               + narrow_to_wide(minetest_version_simple) + L",\n"
                                                + L"server's PROTOCOL_VERSION (strict) is "
                                                + narrow_to_wide(itos(LATEST_PROTOCOL_VERSION))
                                                + L", client's PROTOCOL_VERSION is "
@@ -4823,7 +4824,7 @@ std::wstring Server::getStatusString()
        std::wostringstream os(std::ios_base::binary);
        os<<L"# Server: ";
        // Version
-       os<<L"version="<<narrow_to_wide(VERSION_STRING);
+       os<<L"version="<<narrow_to_wide(minetest_version_simple);
        // Uptime
        os<<L", uptime="<<m_uptime.get();
        // Max lag estimate
index 4db5f3ecd5239d0a35fc546228f8ee14a08fbe03..908f048cb5624d422347a030fd81a5dbe569a750 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <sstream>
 #include <algorithm>
 
+#include "version.h"
 #include "main.h" // for g_settings
 #include "settings.h"
 #include "serverlist.h"
@@ -202,7 +203,7 @@ void sendAnnounce(std::string action, u16 clients, double uptime, std::string ga
        if (action != "delete") {
                server["name"]          = g_settings->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 (file)
index 0000000..e5de8a6
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+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 (file)
index 0000000..0143d91
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+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
+