DFHackVersion: Expose whether the built commit is tagged

develop
lethosor 2015-10-17 15:35:40 -04:00
parent d3dbc6225a
commit 5387c03ea0
5 changed files with 39 additions and 8 deletions

@ -241,6 +241,17 @@ struct sortable
}; };
}; };
static string dfhack_version_desc()
{
stringstream s;
s << Version::dfhack_version() << " ";
if (Version::is_release())
s << "(release)";
else
s << "(development build " << Version::git_description() << ")";
return s.str();
}
static std::string getScriptHelp(std::string path, std::string helpprefix) static std::string getScriptHelp(std::string path, std::string helpprefix)
{ {
ifstream script(path.c_str()); ifstream script(path.c_str());
@ -611,7 +622,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v
" reload PLUGIN|-all - Reload a plugin or all loaded plugins.\n" " reload PLUGIN|-all - Reload a plugin or all loaded plugins.\n"
); );
con.print("\nDFHack version %s.\n", Version::dfhack_version()); con.print("\nDFHack version %s\n", dfhack_version_desc().c_str());
} }
else if (parts.size() == 1) else if (parts.size() == 1)
{ {
@ -1258,7 +1269,7 @@ void fIOthread(void * iodata)
con.print("DFHack is ready. Have a nice day!\n" con.print("DFHack is ready. Have a nice day!\n"
"DFHack version %s\n" "DFHack version %s\n"
"Type in '?' or 'help' for general help, 'ls' to see all commands.\n", "Type in '?' or 'help' for general help, 'ls' to see all commands.\n",
Version::dfhack_version()); dfhack_version_desc().c_str());
int clueless_counter = 0; int clueless_counter = 0;
while (true) while (true)

@ -24,5 +24,14 @@ namespace DFHack {
{ {
return DFHACK_GIT_COMMIT; return DFHACK_GIT_COMMIT;
} }
bool is_release()
{
#ifdef DFHACK_GIT_TAGGED
return true;
#else
return false;
#endif
}
} }
} }

@ -1417,6 +1417,7 @@ static const LuaWrapper::FunctionReg dfhack_module[] = {
WRAP_VERSION_FUNC(getCompiledDFVersion, df_version), WRAP_VERSION_FUNC(getCompiledDFVersion, df_version),
WRAP_VERSION_FUNC(getGitDescription, git_description), WRAP_VERSION_FUNC(getGitDescription, git_description),
WRAP_VERSION_FUNC(getGitCommit, git_commit), WRAP_VERSION_FUNC(getGitCommit, git_commit),
WRAP_VERSION_FUNC(isRelease, is_release),
{ NULL, NULL } { NULL, NULL }
}; };

@ -4,12 +4,20 @@ execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --long
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${dfhack_SOURCE_DIR}" WORKING_DIRECTORY "${dfhack_SOURCE_DIR}"
OUTPUT_VARIABLE DFHACK_GIT_COMMIT) OUTPUT_VARIABLE DFHACK_GIT_COMMIT)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match
WORKING_DIRECTORY "${dfhack_SOURCE_DIR}"
RESULT_VARIABLE DFHACK_GIT_TAGGED_RESULT
OUTPUT_QUIET ERROR_QUIET)
string(STRIP ${DFHACK_GIT_DESCRIPTION} DFHACK_GIT_DESCRIPTION) string(STRIP ${DFHACK_GIT_DESCRIPTION} DFHACK_GIT_DESCRIPTION)
file(WRITE ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h file(WRITE ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h
"#define DFHACK_GIT_DESCRIPTION \"${DFHACK_GIT_DESCRIPTION}\"\n") "#define DFHACK_GIT_DESCRIPTION \"${DFHACK_GIT_DESCRIPTION}\"\n")
string(STRIP ${DFHACK_GIT_COMMIT} DFHACK_GIT_COMMIT) string(STRIP ${DFHACK_GIT_COMMIT} DFHACK_GIT_COMMIT)
file(APPEND ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h file(APPEND ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h
"#define DFHACK_GIT_COMMIT \"${DFHACK_GIT_COMMIT}\"") "#define DFHACK_GIT_COMMIT \"${DFHACK_GIT_COMMIT}\"\n")
if(${DFHACK_GIT_TAGGED_RESULT} EQUAL 0)
file(APPEND ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h
"#define DFHACK_GIT_TAGGED\n")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different 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.tmp.h
${dfhack_SOURCE_DIR}/library/include/git-describe.h) ${dfhack_SOURCE_DIR}/library/include/git-describe.h)

@ -6,13 +6,15 @@ namespace DFHack {
const char *dfhack_release(); const char *dfhack_release();
const char *git_description(); const char *git_description();
const char *git_commit(); const char *git_commit();
bool is_release();
} }
} }
#ifndef NO_DFHACK_VERSION_MACROS #ifndef NO_DFHACK_VERSION_MACROS
#define DF_VERSION DFHack::Version::df_version() #define DF_VERSION (DFHack::Version::df_version())
#define DFHACK_RELEASE DFHack::Version::dfhack_release() #define DFHACK_RELEASE (DFHack::Version::dfhack_release())
#define DFHACK_VERSION DFHack::Version::dfhack_version() #define DFHACK_VERSION (DFHack::Version::dfhack_version())
#define DFHACK_GIT_DESCRIPTION DFHack::Version::git_description() #define DFHACK_GIT_DESCRIPTION (DFHack::Version::git_description())
#define DFHACK_GIT_COMMIT DFHack::Version::git_commit() #define DFHACK_GIT_COMMIT (DFHack::Version::git_commit())
#define DFHACK_IS_RELEASE (DFHack::Version::is_release())
#endif #endif