diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 759cb10b0..17bba7c87 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -257,6 +257,14 @@ SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS DFHACK_RELEASE="${DFHACK_RELEASE}" ) +ADD_CUSTOM_TARGET(git-describe + COMMAND ${CMAKE_COMMAND} + -D dfhack_SOURCE_DIR:STRING=${dfhack_SOURCE_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake + COMMENT "Obtaining git commit information" +) +ADD_DEPENDENCIES(dfhack-version git-describe) + ADD_LIBRARY(dfhack SHARED ${PROJECT_SOURCES}) ADD_DEPENDENCIES(dfhack generate_headers) diff --git a/library/Core.cpp b/library/Core.cpp index 2e59b7abe..11af466ce 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1229,6 +1229,8 @@ bool Core::Init() if(errorstate) return false; + fprintf(stderr, "DFHack build: %s\n", Version::git_description()); + // find out what we are... #ifdef LINUX_BUILD const char * path = "hack/symbols.xml"; diff --git a/library/DFHackVersion.cpp b/library/DFHackVersion.cpp index 2929201d4..df05779fb 100644 --- a/library/DFHackVersion.cpp +++ b/library/DFHackVersion.cpp @@ -1,8 +1,23 @@ #include "DFHackVersion.h" +#include "git-describe.h" +#include "Export.h" namespace DFHack { namespace Version { - const char *dfhack_version() { return DFHACK_VERSION; } - const char *df_version() { return DF_VERSION; } - const char *dfhack_release() { return DFHACK_RELEASE; } + const char *dfhack_version() + { + return DFHACK_VERSION; + } + const char *df_version() + { + return DF_VERSION; + } + const char *dfhack_release() + { + return DFHACK_RELEASE; + } + const char *git_description() + { + return DFHACK_GIT_DESCRIPTION; + } } } diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index e6510eacf..e1ef64586 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -230,10 +230,13 @@ bool Plugin::load(color_ostream &con) plugin_check_symbol("plugin_self") plugin_check_symbol("plugin_init") plugin_check_symbol("plugin_globals") + plugin_check_symbol("git_description") const char ** plug_name =(const char ** ) LookupPlugin(plug, "name"); const char ** plug_version =(const char ** ) LookupPlugin(plug, "version"); + const char ** plug_git_description = (const char**) LookupPlugin(plug, "git_description"); Plugin **plug_self = (Plugin**)LookupPlugin(plug, "plugin_self"); const char *dfhack_version = Version::dfhack_version(); + const char *dfhack_git_desc = Version::git_description(); if (strcmp(dfhack_version, *plug_version) != 0) { con.printerr("Plugin %s was not built for this version of DFHack.\n" @@ -241,6 +244,9 @@ bool Plugin::load(color_ostream &con) plugin_abort_load; return false; } + if (strcmp(dfhack_git_desc, *plug_git_description) != 0) + con.printerr("Warning: Plugin %s compiled for DFHack %s, running DFHack %s\n", + *plug_name, *plug_git_description, dfhack_git_desc); bool *plug_dev = (bool*)LookupPlugin(plug, "plugin_dev"); if (plug_dev && *plug_dev && getenv("DFHACK_NO_DEV_PLUGINS")) { diff --git a/library/git-describe.cmake b/library/git-describe.cmake new file mode 100644 index 000000000..1e4940674 --- /dev/null +++ b/library/git-describe.cmake @@ -0,0 +1,9 @@ +execute_process(COMMAND git describe --tags + WORKING_DIRECTORY "${dfhack_SOURCE_DIR}" + OUTPUT_VARIABLE DFHACK_GIT_DESCRIPTION) +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}\"") +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/.gitignore b/library/include/.gitignore new file mode 100644 index 000000000..24dcd1482 --- /dev/null +++ b/library/include/.gitignore @@ -0,0 +1 @@ +git-describe.* diff --git a/library/include/DFHackVersion.h b/library/include/DFHackVersion.h index 4bfbd85dd..aa528ccbb 100644 --- a/library/include/DFHackVersion.h +++ b/library/include/DFHackVersion.h @@ -4,5 +4,6 @@ namespace DFHack { const char *dfhack_version(); const char *df_version(); const char *dfhack_release(); + const char *git_description(); } } diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index 2bd094e9c..680262bad 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -61,6 +61,7 @@ namespace DFHack namespace Version { const char *dfhack_version(); + const char *git_description(); } // anon type, pretty much @@ -289,6 +290,7 @@ namespace DFHack #define DFHACK_PLUGIN_AUX(plugin_name, is_dev) \ DFhackDataExport const char * name = plugin_name;\ DFhackDataExport const char * version = DFHack::Version::dfhack_version();\ + DFhackDataExport const char * git_description = DFHack::Version::git_description();\ DFhackDataExport Plugin *plugin_self = NULL;\ std::vector _plugin_globals;\ DFhackDataExport std::vector* plugin_globals = &_plugin_globals; \