From 8509f163a5d1b63dcf029c4126cdd285ef827a45 Mon Sep 17 00:00:00 2001 From: Vladimir Davydov <vdavydov@tarantool.org> Date: Tue, 14 Dec 2021 11:00:46 +0300 Subject: [PATCH] cmake: allow to set arbitrary version This commit allows to override Tarantool version detection by setting CMake TARANTOOL_VERSION variable. This is needed to build Tarantool as a part of tarantool/sdk, which sets its own, extended version. Also, this commit updates box-py/args.test.py to allow arbitrary tags appended to the version (tarantool/sdk appends -rNNN). --- CMakeLists.txt | 56 ++++++++++++++++++++-------------------- test/box-py/args.result | 8 +++--- test/box-py/args.test.py | 3 ++- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c20e5a34d7..fb80d9fa3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,37 +219,37 @@ endif() # Get version # -set (PACKAGE_VERSION "") -set (TARANTOOL_VERSION "") - -# Try to get version from VERSION file -set(VERSION_FILE_ORIG "${PROJECT_SOURCE_DIR}/VERSION") -set(VERSION_FILE "${PROJECT_BINARY_DIR}/VERSION") -if (EXISTS "${VERSION_FILE_ORIG}") - file (STRINGS "${VERSION_FILE_ORIG}" TARANTOOL_VERSION) -elseif (EXISTS "${VERSION_FILE}") - file (STRINGS "${VERSION_FILE}" TARANTOOL_VERSION) -endif() - -# Get git version only if source directory has .git repository, this -# avoids git to search .git repository in parent -# directories. -# -if (EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT) - execute_process (COMMAND ${GIT} describe --long HEAD - OUTPUT_VARIABLE TARANTOOL_GIT_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +if(NOT TARANTOOL_VERSION) + # Try to get version from VERSION file + set(VERSION_FILE_ORIG "${PROJECT_SOURCE_DIR}/VERSION") + set(VERSION_FILE "${PROJECT_BINARY_DIR}/VERSION") + if (EXISTS "${VERSION_FILE_ORIG}") + file (STRINGS "${VERSION_FILE_ORIG}" TARANTOOL_VERSION) + elseif (EXISTS "${VERSION_FILE}") + file (STRINGS "${VERSION_FILE}" TARANTOOL_VERSION) + endif() - if (NOT ("${TARANTOOL_GIT_VERSION}" STREQUAL "${TARANTOOL_VERSION}")) - set(TARANTOOL_VERSION "${TARANTOOL_GIT_VERSION}") - message(STATUS "Generating VERSION file") - file(WRITE ${VERSION_FILE} "${TARANTOOL_VERSION}\n") + # Get git version only if source directory has .git repository, this + # avoids git to search .git repository in parent + # directories. + # + if (EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT) + execute_process (COMMAND ${GIT} describe --long HEAD + OUTPUT_VARIABLE TARANTOOL_GIT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + + if (NOT ("${TARANTOOL_GIT_VERSION}" STREQUAL "${TARANTOOL_VERSION}")) + set(TARANTOOL_VERSION "${TARANTOOL_GIT_VERSION}") + message(STATUS "Generating VERSION file") + file(WRITE ${VERSION_FILE} "${TARANTOOL_VERSION}\n") + endif() endif() -endif() -if (NOT TARANTOOL_VERSION) - message (FATAL_ERROR "Unable to retrive version from git or ${VERSION_FILE} file.") + if (NOT TARANTOOL_VERSION) + message (FATAL_ERROR + "Unable to retrive version from git or ${VERSION_FILE} file.") + endif() endif() # diff --git a/test/box-py/args.result b/test/box-py/args.result index 1ae941e736..533e66eef3 100644 --- a/test/box-py/args.result +++ b/test/box-py/args.result @@ -44,7 +44,7 @@ tarantool --no-such-option --version tarantool: unrecognized option tarantool --version -Tarantool 2.minor.patch-<suffix>-<rev>-<commit> +Tarantool 2.<minor>.<patch>-<suffix> Target: platform <build> Build options: flags Compiler: cc @@ -52,7 +52,7 @@ C_FLAGS: flags CXX_FLAGS: flags tarantool -v -Tarantool 2.minor.patch-<suffix>-<rev>-<commit> +Tarantool 2.<minor>.<patch>-<suffix> Target: platform <build> Build options: flags Compiler: cc @@ -60,7 +60,7 @@ C_FLAGS: flags CXX_FLAGS: flags tarantool -V -Tarantool 2.minor.patch-<suffix>-<rev>-<commit> +Tarantool 2.<minor>.<patch>-<suffix> Target: platform <build> Build options: flags Compiler: cc @@ -111,7 +111,7 @@ arg[3] => 2 arg[4] => 3 tarantool -V ${SOURCEDIR}/test/box-py/args.lua 1 2 3 -Tarantool 2.minor.patch-<suffix>-<rev>-<commit> +Tarantool 2.<minor>.<patch>-<suffix> Target: platform <build> Build options: flags Compiler: cc diff --git a/test/box-py/args.test.py b/test/box-py/args.test.py index b412564995..152e4f236e 100644 --- a/test/box-py/args.test.py +++ b/test/box-py/args.test.py @@ -22,7 +22,8 @@ sys.stdout.push_filter("unrecognized option.*", "unrecognized option") server.test_option("-Z") server.test_option("--no-such-option") server.test_option("--no-such-option --version") -sys.stdout.push_filter(".* (\d+)\.\d+\.\d+(-\w+)?(-\d+)?(-\w+)?", "Tarantool \\1.minor.patch-<suffix>-<rev>-<commit>") +sys.stdout.push_filter(".* (\d+)\.\d+\.\d+(-\w+)*", + "Tarantool \\1.<minor>.<patch>-<suffix>") sys.stdout.push_filter("Target: .*", "Target: platform <build>") sys.stdout.push_filter(".*Disable shared arena since.*\n", "") sys.stdout.push_filter("Build options: .*", "Build options: flags") -- GitLab