From de49befdbbf4f015a0d12f3767031fce9218be9c Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 6 Aug 2015 17:30:51 -0400 Subject: [PATCH] Improve version information * Add reimplementations of old DFHACK_VERSION-style macros * Expose full git commit ID * Expose all DFHack::Version functions to Lua --- Lua API.rst | 14 ++++++++++++++ NEWS | 2 +- library/DFHackVersion.cpp | 5 +++++ library/LuaApi.cpp | 8 ++++++++ library/git-describe.cmake | 8 +++++++- library/include/DFHackVersion.h | 9 +++++++++ 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Lua API.rst b/Lua API.rst index 86233470a..3f92ad4db 100644 --- a/Lua API.rst +++ b/Lua API.rst @@ -785,6 +785,20 @@ can be omitted. Returns the DF version string from ``symbols.xml``. +* ``getDFHackVersion()`` +* ``getDFHackRelease()`` +* ``getCompiledDFVersion()`` +* ``getGitDescription()`` +* ``getGitCommit()`` + + Return information about the DFHack build in use. + + **Note:** ``getCompiledDFVersion()`` returns the DF version specified at compile time, + while ``getDFVersion()`` returns the version and typically the OS as well. + These do not necessarily match - for example, DFHack 0.34.11-r5 worked with + DF 0.34.10 and 0.34.11, so the former function would always return ``0.34.11`` + while the latter would return ``v0.34.10 `` or ``v0.34.11 ``. + * ``dfhack.getDFPath()`` Returns the DF directory path. diff --git a/NEWS b/NEWS index 9094dec76..10178f501 100644 --- a/NEWS +++ b/NEWS @@ -4,7 +4,7 @@ DFHack Future Developer plugins can be ignored on startup by setting the DFHACK_NO_DEV_PLUGINS environment variable The console on Linux and OS X now recognizes keyboard input between prompts JSON libraries available (C++ and Lua) - More build information available in plugins + More DFHack build information used in plugin version checks and available to plugins and lua scripts Fixed a rare overflow issue that could cause crashes on Linux and OS X Stopped DF window from receiving input when unfocused on OS X Fixed issues with keybindings involving Ctrl-A and Ctrl-Z, as well as Alt-E/U/N on OS X diff --git a/library/DFHackVersion.cpp b/library/DFHackVersion.cpp index df05779fb..cc56af180 100644 --- a/library/DFHackVersion.cpp +++ b/library/DFHackVersion.cpp @@ -1,3 +1,4 @@ +#define NO_DFHACK_VERSION_MACROS #include "DFHackVersion.h" #include "git-describe.h" #include "Export.h" @@ -19,5 +20,9 @@ namespace DFHack { { return DFHACK_GIT_DESCRIPTION; } + const char *git_commit() + { + return DFHACK_GIT_COMMIT; + } } } diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index ee2ca3702..0e507dafe 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -38,6 +38,7 @@ distribution. #include "DataDefs.h" #include "DataIdentity.h" #include "DataFuncs.h" +#include "DFHackVersion.h" #include "modules/World.h" #include "modules/Gui.h" @@ -1396,6 +1397,8 @@ static std::string df2utf(std::string s) { return DF2UTF(s); } static std::string utf2df(std::string s) { return UTF2DF(s); } static std::string df2console(std::string s) { return DF2CONSOLE(s); } +#define WRAP_VERSION_FUNC(name, function) WRAPN(name, DFHack::Version::function) + static const LuaWrapper::FunctionReg dfhack_module[] = { WRAP(getOSType), WRAP(getDFVersion), @@ -1408,6 +1411,11 @@ static const LuaWrapper::FunctionReg dfhack_module[] = { WRAP(df2utf), WRAP(utf2df), WRAP(df2console), + WRAP_VERSION_FUNC(getDFHackVersion, dfhack_version), + WRAP_VERSION_FUNC(getDFHackRelease, dfhack_release), + WRAP_VERSION_FUNC(getCompiledDFVersion, df_version), + WRAP_VERSION_FUNC(getGitDescription, git_description), + WRAP_VERSION_FUNC(getGitCommit, git_commit), { NULL, NULL } }; diff --git a/library/git-describe.cmake b/library/git-describe.cmake index 7ccd2d91d..9c5e7a874 100644 --- a/library/git-describe.cmake +++ b/library/git-describe.cmake @@ -1,9 +1,15 @@ execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --long WORKING_DIRECTORY "${dfhack_SOURCE_DIR}" OUTPUT_VARIABLE DFHACK_GIT_DESCRIPTION) +execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY "${dfhack_SOURCE_DIR}" + OUTPUT_VARIABLE DFHACK_GIT_COMMIT) string(STRIP ${DFHACK_GIT_DESCRIPTION} DFHACK_GIT_DESCRIPTION) file(WRITE ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h - "#define DFHACK_GIT_DESCRIPTION \"${DFHACK_GIT_DESCRIPTION}\"") + "#define DFHACK_GIT_DESCRIPTION \"${DFHACK_GIT_DESCRIPTION}\"\n") +string(STRIP ${DFHACK_GIT_COMMIT} DFHACK_GIT_COMMIT) +file(APPEND ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h + "#define DFHACK_GIT_COMMIT \"${DFHACK_GIT_COMMIT}\"") execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h ${dfhack_SOURCE_DIR}/library/include/git-describe.h) diff --git a/library/include/DFHackVersion.h b/library/include/DFHackVersion.h index aa528ccbb..359ed0eba 100644 --- a/library/include/DFHackVersion.h +++ b/library/include/DFHackVersion.h @@ -5,5 +5,14 @@ namespace DFHack { const char *df_version(); const char *dfhack_release(); const char *git_description(); + const char *git_commit(); } } + +#ifndef NO_DFHACK_VERSION_MACROS +#define DF_VERSION DFHack::Version::df_version() +#define DFHACK_RELEASE DFHack::Version::dfhack_release() +#define DFHACK_VERSION DFHack::Version::dfhack_version() +#define DFHACK_GIT_DESCRIPTION DFHack::Version::git_description() +#define DFHACK_GIT_COMMIT DFHack::Version::git_commit() +#endif