Add ABI version symbol to plugins

develop
lethosor 2018-03-10 16:55:00 -05:00
parent db95796d4c
commit eb22d5c38e
5 changed files with 18 additions and 0 deletions

@ -301,6 +301,7 @@ SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS
DFHACK_VERSION="${DFHACK_VERSION}"
DF_VERSION="${DF_VERSION}"
DFHACK_RELEASE="${DFHACK_RELEASE}"
DFHACK_ABI_VERSION=${DFHACK_ABI_VERSION}
)
IF(DFHACK_PRERELEASE)
SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS

@ -3,6 +3,10 @@
#include "git-describe.h"
namespace DFHack {
namespace Version {
int dfhack_abi_version()
{
return DFHACK_ABI_VERSION;
}
const char *dfhack_version()
{
return DFHACK_VERSION;

@ -276,6 +276,7 @@ bool Plugin::load(color_ostream &con)
plugin_check_symbol("plugin_name")
plugin_check_symbol("plugin_version")
plugin_check_symbol("plugin_abi_version")
plugin_check_symbol("plugin_self")
plugin_check_symbol("plugin_init")
plugin_check_symbol("plugin_globals")
@ -287,11 +288,19 @@ bool Plugin::load(color_ostream &con)
return false;
}
const char ** plug_version =(const char ** ) LookupPlugin(plug, "plugin_version");
const int *plugin_abi_version = (int*) LookupPlugin(plug, "plugin_abi_version");
const char ** plug_git_desc_ptr = (const char**) LookupPlugin(plug, "plugin_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();
const char *plug_git_desc = plug_git_desc_ptr ? *plug_git_desc_ptr : "unknown";
if (*plugin_abi_version != Version::dfhack_abi_version())
{
con.printerr("Plugin %s: ABI version mismatch (Plugin: %i, DFHack: %i)\n",
*plug_name, *plugin_abi_version, Version::dfhack_abi_version());
plugin_abort_load;
return false;
}
if (strcmp(dfhack_version, *plug_version) != 0)
{
con.printerr("Plugin %s was not built for this version of DFHack.\n"

@ -4,6 +4,7 @@ namespace DFHack {
const char *dfhack_version();
const char *df_version();
const char *dfhack_release();
int dfhack_abi_version();
const char *git_description();
const char *git_commit();
const char *git_xml_commit();
@ -18,6 +19,7 @@ namespace DFHack {
#define DF_VERSION (DFHack::Version::df_version())
#define DFHACK_RELEASE (DFHack::Version::dfhack_release())
#define DFHACK_VERSION (DFHack::Version::dfhack_version())
#define DFHACK_ABI_VERSION (DFHack::Version::dfhack_abi_version())
#define DFHACK_GIT_DESCRIPTION (DFHack::Version::git_description())
#define DFHACK_GIT_COMMIT (DFHack::Version::git_commit())
#define DFHACK_GIT_XML_COMMIT (DFHack::Version::git_xml_commit())

@ -61,6 +61,7 @@ namespace DFHack
namespace Version {
const char *dfhack_version();
const char *git_description();
int dfhack_abi_version();
}
// anon type, pretty much
@ -296,6 +297,7 @@ namespace DFHack
DFhackDataExport const char * plugin_name = m_plugin_name;\
DFhackDataExport const char * plugin_version = DFHack::Version::dfhack_version();\
DFhackDataExport const char * plugin_git_description = DFHack::Version::git_description();\
DFhackDataExport int plugin_abi_version = DFHack::Version::dfhack_abi_version();\
DFhackDataExport DFHack::Plugin *plugin_self = NULL;\
std::vector<std::string> _plugin_globals;\
DFhackDataExport std::vector<std::string>* plugin_globals = &_plugin_globals; \