From 603e25074533ce28d76a9a8ec181fb51a29715cf Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 19 Oct 2020 16:19:48 +0300 Subject: [PATCH] mdbx-cmake: fix/refine `git-fetch_version` macro for old branches. Change-Id: Ied5b7c839da75de065fd86ec46da7b391022c948 --- cmake/utils.cmake | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index dc6a240e..8f4babd4 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -113,23 +113,34 @@ macro(fetch_version name source_root_directory parent_scope) message(FATAL_ERROR "Please install latest version of git ('show --no-patch --format=%H HEAD' failed)") endif() - execute_process(COMMAND ${GIT} tag --sort=-version:refname - OUTPUT_VARIABLE tag_list + execute_process(COMMAND ${GIT} describe --tags --abbrev=0 "--match=v[0-9]*" + OUTPUT_VARIABLE last_release_tag OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE rc) if(rc) - message(FATAL_ERROR "Please install latest version of git ('tag --sort=-version:refname' failed)") + message(FATAL_ERROR "Please install latest version of git ('describe --tags --abbrev=0 --match=v[0-9]*' failed)") endif() - string(REGEX REPLACE "\n" ";" tag_list "${tag_list}") - set(last_release_tag "") - set(git_revlist_arg "HEAD") - foreach(tag IN LISTS tag_list) - if(NOT last_release_tag) - string(REGEX MATCH "^v[0-9]+(\.[0-9]+)+" last_release_tag "${tag}") - set(git_revlist_arg "${tag}..HEAD") + if (last_release_tag) + set(git_revlist_arg "${last_release_tag}..HEAD") + else() + execute_process(COMMAND ${GIT} tag --sort=-version:refname + OUTPUT_VARIABLE tag_list + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${source_root_directory} + RESULT_VARIABLE rc) + if(rc) + message(FATAL_ERROR "Please install latest version of git ('tag --sort=-version:refname' failed)") endif() - endforeach(tag) + string(REGEX REPLACE "\n" ";" tag_list "${tag_list}") + set(git_revlist_arg "HEAD") + foreach(tag IN LISTS tag_list) + if(NOT last_release_tag) + string(REGEX MATCH "^v[0-9]+(\.[0-9]+)+" last_release_tag "${tag}") + set(git_revlist_arg "${tag}..HEAD") + endif() + endforeach(tag) + endif() execute_process(COMMAND ${GIT} rev-list --count "${git_revlist_arg}" OUTPUT_VARIABLE ${name}_GIT_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE