Add git commit information to libdfhack-version

git is run every time 'make' is run, but the generated include file
is only updated when necessary. Plugins will be loaded successfully
if their DFHack version matches core's (assuming OpenLibrary()
succeeds), but will produce a warning if their git commit doesn't
match core's.
develop
lethosor 2015-06-24 19:32:45 -04:00
parent 0fa5570349
commit ee7a2c7db7
8 changed files with 47 additions and 3 deletions

@ -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)

@ -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";

@ -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;
}
}
}

@ -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"))
{

@ -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)

@ -0,0 +1 @@
git-describe.*

@ -4,5 +4,6 @@ namespace DFHack {
const char *dfhack_version();
const char *df_version();
const char *dfhack_release();
const char *git_description();
}
}

@ -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<std::string> _plugin_globals;\
DFhackDataExport std::vector<std::string>* plugin_globals = &_plugin_globals; \