From 237d390e403d89f332d3f03a87ad15c68bc454d5 Mon Sep 17 00:00:00 2001 From: dehnert Date: Thu, 5 Apr 2018 14:30:09 +0200 Subject: [PATCH] reworked version retrieval slightly --- CMakeLists.txt | 33 ++++++++++++------------------- src/storm/utility/storm-version.h | 14 +++++++++++-- storm-version.cpp.in | 7 ++++--- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 801a824c6..d5c8aa732 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -402,42 +402,26 @@ endif(DOXYGEN_FOUND) # try to obtain the current version from git. include(GetGitRevisionDescription) -message (STATUS "Storm - git hash ${STORM_VERSION_GIT_HASH}") -message (STATUS "Storm - git version refspec ${STORM_VERSION_REFSPEC}") -message (STATUS "Storm - git version string ${STORM_GIT_VERSION_STRING}") get_git_head_revision(STORM_VERSION_REFSPEC STORM_VERSION_GIT_HASH) -git_describe_checkout(STORM_GIT_VERSION_STRING) -message (STATUS "Storm - git hash ${STORM_VERSION_GIT_HASH}") -message (STATUS "Storm - git version refspec ${STORM_VERSION_REFSPEC}") -message (STATUS "Storm - git version string ${STORM_GIT_VERSION_STRING}") +git_describe(STORM_GIT_VERSION_STRING) # parse the git tag into variables # start with major.minor.patch string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)$" STORM_VERSION_MATCH "${STORM_GIT_VERSION_STRING}") -message (STATUS "Storm - version match ${STORM_VERSION_MATCH}") set(STORM_VERSION_MAJOR "${CMAKE_MATCH_1}") set(STORM_VERSION_MINOR "${CMAKE_MATCH_2}") set(STORM_VERSION_PATCH "${CMAKE_MATCH_3}") set(STORM_GIT_VERSION_REST "${CMAKE_MATCH_4}") -message (STATUS "Storm - version ${STORM_VERSION_MAJOR}.${STORM_VERSION_MINOR}.${STORM_VERSION_PATCH}") # parse rest of the form (-label)-commitsahead-hash-appendix string(REGEX MATCH "^(\\-([a-z][a-z0-9\\.]+))?\\-([0-9]+)\\-([a-z0-9]+)(\\-.*)?$" STORM_VERSION_REST_MATCH "${STORM_GIT_VERSION_REST}") -message (STATUS "Storm - version rest match ${STORM_VERSION_REST_MATCH}") set(STORM_VERSION_LABEL "${CMAKE_MATCH_2}") # might be empty set(STORM_VERSION_COMMITS_AHEAD "${CMAKE_MATCH_3}") set(STORM_VERSION_TAG_HASH "${CMAKE_MATCH_4}") set(STORM_VERSION_APPENDIX "${CMAKE_MATCH_5}") # might be empty -message (STATUS "Storm - version rest ${STORM_VERSION_LABEL} / ${STORM_VERSION_COMMITS_AHEAD} / ${STORM_VERSION_TAG_HASH} / STORM_VERSION_APPENDIX") -# now check whether the git version lookup failed -if (STORM_VERSION_MAJOR MATCHES "NOTFOUND") - include(version.cmake) - set(STORM_VERSION_LABEL "") - set(STORM_VERSION_COMMITS_AHEAD 0) - set(STORM_VERSION_GIT_HASH "") - set(STORM_VERSION_DIRTY boost::none) - message(WARNING "Storm - git version information not available, statically assuming version ${STORM_VERSION_MAJOR}.${STORM_VERSION_MINOR}.${STORM_VERSION_PATCH}.") -else() + +set(STORM_VERSION_DIRTY boost::none) +if (NOT "${STORM_GIT_VERSION_STRING}" STREQUAL "") if ("${STORM_VERSION_APPENDIX}" MATCHES "^.*dirty.*$") set(STORM_VERSION_DIRTY "true") else() @@ -445,6 +429,15 @@ else() endif() endif() +# now check whether the git version lookup failed +set(STORM_VERSION_SOURCE "VersionSource::Git") +if (STORM_GIT_VERSION_STRING MATCHES "NOTFOUND") + set(STORM_VERSION_SOURCE "VersionSource::Static") + set(STORM_VERSION_COMMITS_AHEAD "boost::none") + include(version.cmake) + message(WARNING "Storm - git version information not available, statically assuming version ${STORM_VERSION_MAJOR}.${STORM_VERSION_MINOR}.${STORM_VERSION_PATCH}.") +endif() + # check whether there is a label ('alpha', 'pre', etc.) if ("${STORM_VERSION_LABEL}" STREQUAL "") set(STORM_VERSION_LABEL_STRING "") diff --git a/src/storm/utility/storm-version.h b/src/storm/utility/storm-version.h index 72f047906..b6b1d3d2e 100644 --- a/src/storm/utility/storm-version.h +++ b/src/storm/utility/storm-version.h @@ -24,11 +24,18 @@ namespace storm { /// Flag indicating if the version of Storm is a development version. const static bool versionDev; + enum class VersionSource { + Git, Static + }; + + /// The source of the versioning information. + const static VersionSource versionSource; + /// The short hash of the git commit this build is based on const static std::string gitRevisionHash; /// How many commits passed since the tag was last set. - const static unsigned commitsAhead; + const static boost::optional commitsAhead; /// 0 iff there no files were modified in the checkout, 1 otherwise. If none, no information about dirtyness is given. const static boost::optional dirty; @@ -60,8 +67,11 @@ namespace storm { static std::string longVersionString() { std::stringstream sstream; sstream << "Version " << shortVersionString(); + if (versionSource == VersionSource::Static) { + sstream << " (derived statically)"; + } if (commitsAhead) { - sstream << " (+ " << commitsAhead << " commits)"; + sstream << " (+ " << commitsAhead.get() << " commits)"; } if (!gitRevisionHash.empty()) { sstream << " build from revision " << gitRevisionHash; diff --git a/storm-version.cpp.in b/storm-version.cpp.in index 9ff273d4b..6e3706bae 100644 --- a/storm-version.cpp.in +++ b/storm-version.cpp.in @@ -1,5 +1,4 @@ -//AUTO GENERATED -- DO NOT CHANGE -// TODO resolve issues when placing this in the build order directly. +// AUTO GENERATED -- DO NOT CHANGE #include "storm/utility/storm-version.h" namespace storm { @@ -10,8 +9,9 @@ namespace storm { const unsigned StormVersion::versionPatch = @STORM_VERSION_DEV_PATCH@; const std::string StormVersion::versionLabel = "@STORM_VERSION_LABEL@"; const bool StormVersion::versionDev = @STORM_VERSION_DEV@; + const StormVersion::VersionSource StormVersion::versionSource = @STORM_VERSION_SOURCE@; const std::string StormVersion::gitRevisionHash = "@STORM_VERSION_GIT_HASH@"; - const unsigned StormVersion::commitsAhead = @STORM_VERSION_COMMITS_AHEAD@; + const boost::optional StormVersion::commitsAhead = @STORM_VERSION_COMMITS_AHEAD@; const boost::optional StormVersion::dirty = @STORM_VERSION_DIRTY@; const std::string StormVersion::systemName = "@CMAKE_SYSTEM_NAME@"; const std::string StormVersion::systemVersion = "@CMAKE_SYSTEM_VERSION@"; @@ -21,5 +21,6 @@ namespace storm { #else const std::string StormVersion::cxxFlags = "@CMAKE_CXX_FLAGS@" " " "@CMAKE_CXX_FLAGS_DEBUG@"; #endif + } }