new(cmake/modules): provide and parse FALCO_VERSION_PRERELEASE too

Co-authored-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
This commit is contained in:
Leonardo Di Donato 2020-03-10 16:19:31 +00:00 committed by poiana
parent 123a75062e
commit 36501c5f1d

View File

@ -1,6 +1,5 @@
# Retrieve git ref and commit hash # Retrieve git ref and commit hash
include(GetGitRevisionDescription) include(GetGitRevisionDescription)
get_git_head_revision(FALCO_REF FALCO_HASH)
# Create the falco version variable according to git index # Create the falco version variable according to git index
if(NOT FALCO_VERSION) if(NOT FALCO_VERSION)
@ -9,25 +8,13 @@ if(NOT FALCO_VERSION)
git_get_exact_tag(FALCO_TAG) git_get_exact_tag(FALCO_TAG)
if(NOT FALCO_TAG) if(NOT FALCO_TAG)
# Obtain the closest tag # Obtain the closest tag
git_describe(FALCO_VERSION "--abbrev=0" "--tags") # suppress the long format git_describe(FALCO_VERSION "--always" "--tags")
# Fallback version # Fallback version
if(FALCO_VERSION MATCHES "NOTFOUND$") if(FALCO_VERSION MATCHES "NOTFOUND$")
set(FALCO_VERSION "0.0.0") set(FALCO_VERSION "0.0.0")
endif() endif()
# TODO(leodido) > Construct the prerelease part (semver 2) Construct the Build metadata part (semver 2) # Format FALCO_VERSION to be semver with prerelease and build part
if(NOT FALCO_HASH MATCHES "NOTFOUND$") string(REPLACE "-g" "+" FALCO_VERSION "${FALCO_VERSION}")
string(SUBSTRING "${FALCO_HASH}" 0 7 FALCO_VERSION_BUILD)
# Check whether there are uncommitted changes or not
git_local_changes(FALCO_CHANGES)
if(FALCO_CHANGES STREQUAL "DIRTY")
string(TOLOWER "${FALCO_CHANGES}" FALCO_CHANGES)
set(FALCO_VERSION_BUILD "${FALCO_VERSION_BUILD}.${FALCO_CHANGES}")
endif()
endif()
# Append the build metadata part (semver 2)
if(FALCO_VERSION_BUILD)
set(FALCO_VERSION "${FALCO_VERSION}+${FALCO_VERSION_BUILD}")
endif()
else() else()
# A tag has been found: use it as the Falco version # A tag has been found: use it as the Falco version
set(FALCO_VERSION "${FALCO_TAG}") set(FALCO_VERSION "${FALCO_TAG}")
@ -42,8 +29,8 @@ if(NOT FALCO_VERSION)
string( string(
REGEX REGEX
REPLACE REPLACE
"^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)\\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)*).*" "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*).*"
"\\4" "\\5"
FALCO_VERSION_PRERELEASE FALCO_VERSION_PRERELEASE
"${FALCO_VERSION}") "${FALCO_VERSION}")
if(FALCO_VERSION_PRERELEASE STREQUAL "${FALCO_VERSION}") if(FALCO_VERSION_PRERELEASE STREQUAL "${FALCO_VERSION}")