diff --git a/library/Core.cpp b/library/Core.cpp index d187ccd49..823c68a59 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -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) { 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" ); - 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) { @@ -1258,7 +1269,7 @@ void fIOthread(void * iodata) con.print("DFHack is ready. Have a nice day!\n" "DFHack version %s\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; while (true) diff --git a/library/DFHackVersion.cpp b/library/DFHackVersion.cpp index cc56af180..d3200a42f 100644 --- a/library/DFHackVersion.cpp +++ b/library/DFHackVersion.cpp @@ -24,5 +24,14 @@ namespace DFHack { { return DFHACK_GIT_COMMIT; } + + bool is_release() + { + #ifdef DFHACK_GIT_TAGGED + return true; + #else + return false; + #endif + } } } diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 698b4ba5a..996cae8f1 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1417,6 +1417,7 @@ static const LuaWrapper::FunctionReg dfhack_module[] = { WRAP_VERSION_FUNC(getCompiledDFVersion, df_version), WRAP_VERSION_FUNC(getGitDescription, git_description), WRAP_VERSION_FUNC(getGitCommit, git_commit), + WRAP_VERSION_FUNC(isRelease, is_release), { NULL, NULL } }; diff --git a/library/git-describe.cmake b/library/git-describe.cmake index 9c5e7a874..e1216edad 100644 --- a/library/git-describe.cmake +++ b/library/git-describe.cmake @@ -4,12 +4,20 @@ execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --long execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY "${dfhack_SOURCE_DIR}" 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) file(WRITE ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h "#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}\"") + "#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 ${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 359ed0eba..f035e616a 100644 --- a/library/include/DFHackVersion.h +++ b/library/include/DFHackVersion.h @@ -6,13 +6,15 @@ namespace DFHack { const char *dfhack_release(); const char *git_description(); const char *git_commit(); + bool is_release(); } } #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() + #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()) + #define DFHACK_IS_RELEASE (DFHack::Version::is_release()) #endif