From 408e4cffc97ee80f6741d3298b08819d1e9ab683 Mon Sep 17 00:00:00 2001 From: Guilherme Amadio Date: Thu, 11 May 2023 10:57:22 +0200 Subject: [PATCH] Use CMake to detect/set XRootD version and generate XrdVersion.hh --- .gitattributes | 2 +- CMakeLists.txt | 25 +-- VERSION | 1 + VERSION_INFO | 1 - bindings/python/.gitattributes | 1 - bindings/python/.gitignore | 1 - bindings/python/MANIFEST.in | 1 - bindings/python/setup.py.in | 53 ++---- cmake/XRootDVersion.cmake | 77 +++++++++ docker/xrd-docker | 15 +- genversion.sh | 291 +++++++-------------------------- packaging/wheel/MANIFEST.in | 2 +- packaging/wheel/publish.sh | 8 +- packaging/wheel/setup.py | 44 +---- src/CMakeLists.txt | 4 +- src/XrdCeph/genversion.sh | 239 --------------------------- src/XrdCl/CMakeLists.txt | 2 +- src/XrdVersion.hh.in | 7 +- 18 files changed, 172 insertions(+), 602 deletions(-) create mode 100644 VERSION delete mode 100644 VERSION_INFO delete mode 100644 bindings/python/.gitattributes create mode 100644 cmake/XRootDVersion.cmake delete mode 100755 src/XrdCeph/genversion.sh diff --git a/.gitattributes b/.gitattributes index 0893fe6afee..5f72683f8fc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -VERSION_INFO export-subst +VERSION export-subst diff --git a/CMakeLists.txt b/CMakeLists.txt index c3129ebcf09..01f5ca9d5a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/cmake ) +include(XRootDVersion) + #------------------------------------------------------------------------------- # A 'plugins' phony target to simplify building build-tree binaries. # Plugins are responsible for adding themselves to this target, where @@ -30,29 +32,8 @@ add_definitions( -DXRDPLUGIN_SOVERSION="${PLUGIN_VERSION}" ) #------------------------------------------------------------------------------- # Generate the version header #------------------------------------------------------------------------------- -if (USER_VERSION) - set(XROOTD_VERSION "${USER_VERSION}") -else () -execute_process( - COMMAND ${CMAKE_SOURCE_DIR}/genversion.sh --print-only ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE XROOTD_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE ) -endif() - -add_custom_target( - XrdVersion.hh - ${CMAKE_SOURCE_DIR}/genversion.sh --version ${XROOTD_VERSION} ${CMAKE_SOURCE_DIR}) - -# sigh, yet another ugly hack :( -macro( add_library _target ) - _add_library( ${_target} ${ARGN} ) - add_dependencies( ${_target} XrdVersion.hh ) -endmacro() -macro( add_executable _target ) - _add_executable( ${_target} ${ARGN} ) - add_dependencies( ${_target} XrdVersion.hh ) -endmacro() +configure_file(src/XrdVersion.hh.in src/XrdVersion.hh) #------------------------------------------------------------------------------- # Build in subdirectories diff --git a/VERSION b/VERSION new file mode 100644 index 00000000000..f4034a5d279 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +$Format:%(describe)$ diff --git a/VERSION_INFO b/VERSION_INFO deleted file mode 100644 index 5ac45999939..00000000000 --- a/VERSION_INFO +++ /dev/null @@ -1 +0,0 @@ -$Format:RefNames: %d%nShortHash: %h%nDate: %ai%n$ \ No newline at end of file diff --git a/bindings/python/.gitattributes b/bindings/python/.gitattributes deleted file mode 100644 index 0893fe6afee..00000000000 --- a/bindings/python/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -VERSION_INFO export-subst diff --git a/bindings/python/.gitignore b/bindings/python/.gitignore index 22eb52622ed..a4103cedce0 100755 --- a/bindings/python/.gitignore +++ b/bindings/python/.gitignore @@ -4,4 +4,3 @@ build .cproject *.py[co] MANIFEST -VERSION_INFO diff --git a/bindings/python/MANIFEST.in b/bindings/python/MANIFEST.in index 2110b2157d3..e9c2fda97b8 100644 --- a/bindings/python/MANIFEST.in +++ b/bindings/python/MANIFEST.in @@ -1,5 +1,4 @@ include README.rst -include VERSION_INFO recursive-include tests * recursive-include examples *.py recursive-include docs * diff --git a/bindings/python/setup.py.in b/bindings/python/setup.py.in index 7fb8c53f63d..7d02d07278e 100644 --- a/bindings/python/setup.py.in +++ b/bindings/python/setup.py.in @@ -51,49 +51,16 @@ xrdcllibdir = "${XRDCL_LIBDIR}" xrdlibdir = "${XRD_LIBDIR}" xrdsrcincdir = "${XRD_SRCINCDIR}" xrdbinincdir = "${XRD_BININCDIR}" -version = "${XROOTD_VERSION}" - -if version.startswith('unknown'): - try: - import os - version_file_path = os.path.join('${CMAKE_CURRENT_SOURCE_DIR}', 'VERSION') - print('Version file path: {}'.format(version_file_path)) - with open(version_file_path, 'r') as f: - version = f.read().split('/n')[0] - print('Version from file: {}'.format(version)) - except Exception as e: - print('{} \nCannot open VERSION_INFO file. {} will be used'.format(e, version)) - -# Sanitize in keeping with PEP 440 -# c.f. https://www.python.org/dev/peps/pep-0440/ -# c.f. https://github.com/pypa/pip/issues/8368 -# version needs to pass pip._vendor.packaging.version.Version() -version = version.replace("-", ".") - -if version.startswith("v"): - version = version[1:] - -version_parts = version.split(".") - -# Ensure release candidates sanitized to ..rc -if version_parts[-1].startswith("rc"): - version = ".".join(version_parts[:-1]) + version_parts[-1] - version_parts = version.split(".") - -if len(version_parts[0]) == 8: - # CalVer - date = version_parts[0] - year = date[:4] - incremental = date[4:] - if incremental.startswith("0"): - incremental = incremental[1:] - - version = year + "." + incremental - - if len(version_parts) > 1: - # https://github.com/pypa/pip/issues/9188#issuecomment-736025963 - hash = version_parts[1] - version = version + "+" + hash + +version = "${XRootD_VERSION_STRING}" + +# Sanitize version to conform to PEP 440 +# https://www.python.org/dev/peps/pep-0440 + +version = version.replace('-rc', 'rc') +version = version.replace('-g', '+git.') +version = version.replace('-', '.post', 1) +version = version.replace('-', '.') print('XRootD library dir: ', xrdlibdir) print('XRootD src include dir:', xrdsrcincdir) diff --git a/cmake/XRootDVersion.cmake b/cmake/XRootDVersion.cmake new file mode 100644 index 00000000000..41772f91c54 --- /dev/null +++ b/cmake/XRootDVersion.cmake @@ -0,0 +1,77 @@ +#.rst: +# +# XRootDVersion +# ------------- +# +# This module sets the version of XRootD. +# +# The version is determined in the following order: +# * If a version is set with -DXRootD_VERSION_STRING=x.y.z during configuration, it is used. +# * The version is read from the 'VERSION' file at the top directory of the repository. +# * If the 'VERSION' file has not been expanded, a version is set using git describe. +# * If none of the above worked, a fallback version is set using the current date. +# + +if(NOT DEFINED XRootD_VERSION_STRING) + file(READ "${PROJECT_SOURCE_DIR}/VERSION" XRootD_VERSION_STRING) + string(STRIP ${XRootD_VERSION_STRING} XRootD_VERSION_STRING) +endif() + +if(XRootD_VERSION_STRING MATCHES "Format:" AND IS_DIRECTORY ${PROJECT_SOURCE_DIR}/.git) + find_package(Git QUIET) + if(Git_FOUND) + message(VERBOSE "Determining version with git") + execute_process(COMMAND + ${GIT_EXECUTABLE} --git-dir ${PROJECT_SOURCE_DIR}/.git describe + OUTPUT_VARIABLE XRootD_VERSION_STRING ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + set(XRootD_VERSION_STRING "${XRootD_VERSION_STRING}" CACHE INTERNAL "XRootD Version") + endif() +endif() + +if(XRootD_VERSION_STRING MATCHES "^v?([0-9]+)[.]*([0-9]*)[.]*([0-9]*)[.]*([0-9]*)") + set(XRootD_VERSION_MAJOR ${CMAKE_MATCH_1}) + if(${CMAKE_MATCH_COUNT} GREATER 1) + set(XRootD_VERSION_MINOR ${CMAKE_MATCH_2}) + else() + set(XRootD_VERSION_MINOR 0) + endif() + if(${CMAKE_MATCH_COUNT} GREATER 2) + set(XRootD_VERSION_PATCH ${CMAKE_MATCH_3}) + else() + set(XRootD_VERSION_PATCH 0) + endif() + if(${CMAKE_MATCH_COUNT} GREATER 3) + set(XRootD_VERSION_TWEAK ${CMAKE_MATCH_4}) + else() + set(XRootD_VERSION_TWEAK 0) + endif() + math(EXPR XRootD_VERSION_NUMBER + "10000 * ${XRootD_VERSION_MAJOR} + 100 * ${XRootD_VERSION_MINOR} + ${XRootD_VERSION_PATCH}" + OUTPUT_FORMAT DECIMAL) +else() + message(WARNING "Failed to determine XRootD version, using a timestamp as fallback." + "You can override this by setting -DXRootD_VERSION_STRING=x.y.z during configuration.") + set(XRootD_VERSION_MAJOR 5) + set(XRootD_VERSION_MINOR 6) + set(XRootD_VERSION_PATCH 0) + set(XRootD_VERSION_TWEAK 0) + set(XRootD_VERSION_NUMBER 1000000) + string(TIMESTAMP XRootD_VERSION_STRING + "v${XRootD_VERSION_MAJOR}.${XRootD_VERSION_MINOR}-rc%Y%m%d" UTC) +endif() + +if(XRootD_VERSION_STRING MATCHES "[_-](.*)$") + set(XRootD_VERSION_SUFFIX ${CMAKE_MATCH_1}) +endif() + +string(REGEX MATCH "[0-9]+[.]*[0-9]*[.]*[0-9]*[.]*[0-9]*(-rc)?[0-9]*" + XRootD_VERSION ${XRootD_VERSION_STRING}) + +message(DEBUG "XRootD_VERSION_STRING = '${XRootD_VERSION_STRING}'") +message(DEBUG "XRootD_VERSION_NUMBER = '${XRootD_VERSION_NUMBER}'") +message(DEBUG "XRootD_VERSION_MAJOR = '${XRootD_VERSION_MAJOR}'") +message(DEBUG "XRootD_VERSION_MINOR = '${XRootD_VERSION_MINOR}'") +message(DEBUG "XRootD_VERSION_PATCH = '${XRootD_VERSION_PATCH}'") +message(DEBUG "XRootD_VERSION_TWEAK = '${XRootD_VERSION_TWEAK}'") +message(DEBUG "XRootD_VERSION_SUFFIX = '${XRootD_VERSION_SUFFIX}'") +message(DEBUG "XRootD_VERSION = '${XRootD_VERSION}'") diff --git a/docker/xrd-docker b/docker/xrd-docker index ccbffe7b7c1..0108bcf1343 100755 --- a/docker/xrd-docker +++ b/docker/xrd-docker @@ -60,16 +60,21 @@ fetch() { package() { REPODIR=$(git rev-parse --show-toplevel) - VERSION=$(git describe ${1:-HEAD} | tr '-' '.' | cut -d. -f-4) + VERSION=$(git describe ${1:-HEAD}) + + # sanitize version name to work with RPMs + VERSION=${VERSION#v} # remove "v" prefix + VERSION=${VERSION/-rc/~rc} # release candidates use ~ in RPMs + VERSION=${VERSION/-g/^$(date +%Y%m%d)git} # snapshots use a caret + VERSION=${VERSION/-/.post} # handle git describe for post releases + VERSION=${VERSION//-/.} # replace remaining dashes with dots pushd ${REPODIR} >/dev/null echo Creating tarball for XRootD ${VERSION} - genversion.sh --version ${VERSION} sed -e "s/__VERSION__/${VERSION}/" -e 's/__RELEASE__/1/' \ packaging/rhel/xrootd.spec.in >| xrootd.spec - git archive --prefix=xrootd/src/ --add-file src/XrdVersion.hh \ - --prefix=xrootd/ --add-file xrootd.spec -o xrootd.tar.gz ${1:-HEAD} - rm ${REPODIR}/src/XrdVersion.hh xrootd.spec + git archive --prefix=xrootd/ --add-file xrootd.spec -o xrootd.tar.gz ${1:-HEAD} + rm xrootd.spec popd >/dev/null mv ${REPODIR}/xrootd.tar.gz . } diff --git a/genversion.sh b/genversion.sh index e0c6f7f7200..ce9acb80861 100755 --- a/genversion.sh +++ b/genversion.sh @@ -1,244 +1,63 @@ #!/usr/bin/env bash -#------------------------------------------------------------------------------- -# Process the git decoration expansion and try to derive version number -#------------------------------------------------------------------------------- -EXP1='^v[12][0-9][0-9][0-9][01][0-9][0-3][0-9]-[0-2][0-9][0-5][0-9]$' -EXP2='^v[0-9]+\.[0-9]+\.[0-9]+$' -EXP3='^v[0-9]+\.[0-9]+\.[0-9]+\-rc.*$' - -#------------------------------------------------------------------------------- -# Get the numeric version -#------------------------------------------------------------------------------- -function getNumericVersion() -{ - VERSION=$1 - if test x`echo $VERSION | grep -E $EXP2` == x; then - echo "1000000"; - return; - fi - VERSION=${VERSION/v/} - VERSION=${VERSION//./ } - VERSION=($VERSION) - printf "%d%02d%02d\n" ${VERSION[0]} ${VERSION[1]} ${VERSION[2]} -} - -#------------------------------------------------------------------------------- -# Extract version number from git references -#------------------------------------------------------------------------------- -function getVersionFromRefs() -{ - REFS=${1/RefNames:/} - REFS=${REFS//,/} - REFS=${REFS/(/} - REFS=${REFS/)/} - REFS=($REFS) - - VERSION="unknown" - - for i in ${REFS[@]}; do - if test x`echo $i | grep -E $EXP2` != x; then - echo "$i" - return 0 - fi - - if test x`echo $i | grep -E $EXP1` != x; then - VERSION="$i" - fi - - if test x`echo $i | grep -E $EXP3` != x; then - VERSION="$i" - fi - - done - echo $VERSION - return 0 -} - -#------------------------------------------------------------------------------- -# Generate the version string from the date and the hash -#------------------------------------------------------------------------------- -function getVersionFromLog() -{ - AWK=gawk - EX="$(command -v gawk)" - if test x"${EX}" == x -o ! -x "${EX}"; then - AWK=awk - fi - - VERSION="`echo $@ | $AWK '{ gsub("-","",$1); print $1"-"$4; }'`" - if test $? -ne 0; then - echo "unknown"; - return 1 - fi - echo v$VERSION -} - -#------------------------------------------------------------------------------- -# Print help -#------------------------------------------------------------------------------- -function printHelp() +# This script no longer generates XrdVersion.hh, but just +# prints the version using the same strategy as in the module +# XRootDVersion.cmake. The script will first try to use a custom +# version set with the option --version or via the environment +# variable XRDVERSION, then read the VERSION file and if that is +# not expanded by git, git describe is used. If a bad version is +# set for any reason, a fallback version is used based on a date. + +function usage() { - echo "Usage:" 1>&2 - echo "${0} [--help|--print-only|--version] [SOURCEPATH]" 1>&2 - echo " --help prints this message" 1>&2 - echo " --print-only prints the version to stdout and quits" 1>&2 - echo " --version VERSION sets the version manually" 1>&2 + cat 1>&2 <<-EOF + Usage: + $(basename $0) [--help|--version] + + --help prints this message + --print-only ignored, used for backward compatibility + --version VERSION sets a custom version + EOF } -#------------------------------------------------------------------------------- -# Check the parameters -#------------------------------------------------------------------------------- -while test ${#} -ne 0; do - if test x${1} = x--help; then - PRINTHELP=1 - elif test x${1} = x--print-only; then - PRINTONLY=1 - elif test x${1} = x--version; then - if test ${#} -lt 2; then - echo "--version parameter needs an argument" 1>&2 - exit 1 - fi - USER_VERSION=${2} - shift - else - SOURCEPATH=${1} - fi - shift -done +SRC=$(dirname $0) +VF=${SRC}/VERSION -if test x$PRINTHELP != x; then - printHelp ${0} - exit 0 -fi - -if test x$SOURCEPATH != x; then - SOURCEPATH=${SOURCEPATH}/ - if test ! -d $SOURCEPATH; then - echo "The given source path does not exist: ${SOURCEPATH}" 1>&2 - exit 1 - fi -fi - -VERSION="unknown" - -#------------------------------------------------------------------------------- -# We're not inside a git repo -#------------------------------------------------------------------------------- -if test ! -d ${SOURCEPATH}.git; then - #----------------------------------------------------------------------------- - # We cannot figure out what version we are - #---------------------------------------------------------------------------- - echo "[I] No git repository info found. Trying to interpret VERSION_INFO" 1>&2 - if test -f src/XrdVersion.hh; then - echo "[I] The XrdVersion.hh file already exists" 1>&2 - exit 0 - elif test ! -r ${SOURCEPATH}VERSION_INFO; then - echo "[!] VERSION_INFO file absent. Unable to determine the version. Using \"unknown\"" 1>&2 - elif test x"`grep Format ${SOURCEPATH}VERSION_INFO`" != x; then - echo "[!] VERSION_INFO file invalid. Unable to determine the version. Using \"unknown\"" 1>&2 - elif test x$USER_VERSION != x; then - echo "[I] Using the user supplied version: ${USER_VERSION}" 1>&2 - VERSION=${USER_VERSION} - #----------------------------------------------------------------------------- - # The version file exists and seems to be valid so we know the version - #---------------------------------------------------------------------------- - else - REFNAMES="`grep RefNames ${SOURCEPATH}VERSION_INFO`" - VERSION="`getVersionFromRefs "$REFNAMES"`" - if test x$VERSION == xunknown; then - SHORTHASH="`grep ShortHash ${SOURCEPATH}VERSION_INFO`" - SHORTHASH=${SHORTHASH/ShortHash:/} - SHORTHASH=${SHORTHASH// /} - DATE="`grep Date ${SOURCEPATH}VERSION_INFO`" - DATE=${DATE/Date:/} - VERSION="`getVersionFromLog $DATE $SHORTHASH`" - fi - fi - -#------------------------------------------------------------------------------- -# Check if the version has been specified by the user -#------------------------------------------------------------------------------- -elif test x$USER_VERSION != x; then - VERSION=$USER_VERSION - -#------------------------------------------------------------------------------- -# We're in a git repo so we can try to determine the version using that -#------------------------------------------------------------------------------- +if [[ -n "${XRDVERSION}" ]]; then + VERSION=${XRDVERSION}; +elif [[ -r "${VF}" ]] && grep -vq "Format:" "${VF}"; then + VERSION=$(sed -e 's/-g/+g/' "${VF}") +elif git -C ${SRC} describe >/dev/null 2>&1; then + VERSION=$(git -C ${SRC} describe | sed -e 's/-g/+g/') else - echo "[I] Determining version from git" 1>&2 - EX="$(command -v git)" - if test x"${EX}" == x -o ! -x "${EX}"; then - echo "[!] Unable to find git in the path: setting the version tag to unknown" 1>&2 - else - #--------------------------------------------------------------------------- - # Sanity check - #--------------------------------------------------------------------------- - CURRENTDIR=$PWD - if [ x${SOURCEPATH} != x ]; then - cd ${SOURCEPATH} - fi - git log -1 >/dev/null 2>&1 - if test $? -ne 0; then - echo "[!] Error while generating src/XrdVersion.hh, the git repository may be corrupted" 1>&2 - echo "[!] Setting the version tag to unknown" 1>&2 - else - #------------------------------------------------------------------------- - # Can we match the exact annotated tag? - #------------------------------------------------------------------------- - git describe --abbrev=0 --exact-match >/dev/null 2>&1 - - if test ${?} -eq 0; then - VERSION=$(git describe --abbrev=0 --exact-match) - else - VERSION=$(git describe --abbrev=0) - # Append .postN with N equal to number of commits since last tag - VERSION="${VERSION}.post$(git rev-list ${VERSION}.. | wc -l)" - fi - fi - cd $CURRENTDIR - fi -fi - -#------------------------------------------------------------------------------- -# Make sure the version string is not longer than 25 characters -#------------------------------------------------------------------------------- -if [ ${#VERSION} -gt 25 ] && [ x$USER_VERSION == x ] ; then - VERSION="${VERSION:0:19}...${VERSION: -3}" -fi - -#------------------------------------------------------------------------------- -# Print the version info and exit if necassary -#------------------------------------------------------------------------------- -if test x$PRINTONLY != x; then - echo $VERSION - exit 0 -fi - -#------------------------------------------------------------------------------- -# Create XrdVersion.hh -#------------------------------------------------------------------------------- -NUMVERSION=`getNumericVersion $VERSION` - -if test ! -r ${SOURCEPATH}src/XrdVersion.hh.in; then - echo "[!] Unable to find src/XrdVersion.hh.in" 1>&2 - exit 1 -fi - -sed -e "s/#define XrdVERSION \"unknown\"/#define XrdVERSION \"$VERSION\"/" ${SOURCEPATH}src/XrdVersion.hh.in | \ -sed -e "s/#define XrdVNUMBER 1000000/#define XrdVNUMBER $NUMVERSION/" \ -> src/XrdVersion.hh.new - -if test $? -ne 0; then - echo "[!] Error while generating src/XrdVersion.hh from the input template" 1>&2 - exit 1 -fi + VERSION="v5.6-rc$(date +%Y%m%d)" +fi + +while [[ $# -gt 0 ]]; do + case $1 in + --help) + usage + exit 0 + ;; + + --print-only) + shift + ;; + + --version) + shift + if [[ $# == 0 ]]; then + echo "error: --version parameter needs an argument" 1>&2 + fi + VERSION=$1 + shift + ;; + + *) + echo "warning: unknown option: $1" 1>&2 + shift + ;; + esac +done -if test ! -e src/XrdVersion.hh; then - mv src/XrdVersion.hh.new src/XrdVersion.hh -elif test x"`diff src/XrdVersion.hh.new src/XrdVersion.hh`" != x; then - mv src/XrdVersion.hh.new src/XrdVersion.hh -else - rm src/XrdVersion.hh.new -fi -echo "[I] src/XrdVersion.hh successfully generated" 1>&2 +printf "${VERSION}" diff --git a/packaging/wheel/MANIFEST.in b/packaging/wheel/MANIFEST.in index d89d3e218a1..c8c539facbd 100644 --- a/packaging/wheel/MANIFEST.in +++ b/packaging/wheel/MANIFEST.in @@ -1,5 +1,5 @@ include *.sh *.py *.in -include CMakeLists.txt VERSION_INFO README COPYING* LICENSE +include CMakeLists.txt VERSION README COPYING* LICENSE recursive-include bindings * recursive-include cmake * diff --git a/packaging/wheel/publish.sh b/packaging/wheel/publish.sh index ddcb335157d..72c26260bee 100755 --- a/packaging/wheel/publish.sh +++ b/packaging/wheel/publish.sh @@ -1,10 +1,8 @@ #!/bin/bash -./genversion.sh -version=$(./genversion.sh --print-only) -version=${version#v} -echo $version > bindings/python/VERSION -rm -r dist +./genversion.sh >| VERSION + +[[ -d dist ]] && rm -rf dist # Determine if wheel.bdist_wheel is available for wheel.bdist_wheel in setup.py python3 -c 'import wheel' &> /dev/null diff --git a/packaging/wheel/setup.py b/packaging/wheel/setup.py index 179b57a9aec..29be651cee2 100644 --- a/packaging/wheel/setup.py +++ b/packaging/wheel/setup.py @@ -14,45 +14,13 @@ import sys def get_version(): - version = subprocess.check_output(['./genversion.sh', '--print-only']).decode() - - # Sanitize in keeping with PEP 440 - # c.f. https://www.python.org/dev/peps/pep-0440/ - # c.f. https://github.com/pypa/pip/issues/8368 - # version needs to pass pip._vendor.packaging.version.Version() - version = version.replace("-", ".") - - if version.startswith("v"): - version = version[1:] - - version_parts = version.split(".") - - # Ensure release candidates sanitized to ..rc - if version_parts[-1].startswith("rc"): - version = ".".join(version_parts[:-1]) + version_parts[-1] - version_parts = version.split(".") - - # Assume SemVer as default case - if len(version_parts[0]) == 8: - # CalVer - date = version_parts[0] - year = date[:4] - incremental = date[4:] - if incremental.startswith("0"): - incremental = incremental[1:] - - version = year + "." + incremental - - return version - -def get_version_from_file(): try: - with open('./bindings/python/VERSION') as f: - version = f.read().split('/n')[0] - return version + version = open('VERSION').read().strip() except: - print('Failed to get version from file. Using unknown') - return 'unknown' + from datetime import date + version = 'v5.6-rc' + date.today().strftime("%Y%m%d") + + return version def binary_exists(name): """Check whether `name` is on PATH.""" @@ -199,7 +167,7 @@ class CustomWheelGen(bdist_wheel): def run(self): pass -version = get_version_from_file() +version = get_version() setup_requires=[ 'pkgconfig' ] setup( diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fd1cde70dd6..53bc84bee8c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,7 +108,7 @@ install( CODE " EXECUTE_PROCESS( COMMAND cat ${CMAKE_SOURCE_DIR}/utils/xrootd-config - COMMAND sed -e \"s/__VERSION__/${XROOTD_VERSION}/\" + COMMAND sed -e \"s/__VERSION__/${XRootD_VERSION}/\" COMMAND sed -e \"s|__INCLUDEDIR__|${CMAKE_INSTALL_INCLUDEDIR}|\" COMMAND sed -e \"s/__PLUGIN_VERSION__/${PLUGIN_VERSION}/\" COMMAND sed -e \"s|__PREFIX__|${CMAKE_INSTALL_PREFIX}|\" @@ -128,7 +128,7 @@ install( MESSAGE( \"-- Processing: \" \${MANPAGE} ) EXECUTE_PROCESS( COMMAND cat \${MANPAGE} - COMMAND sed -e \"s/__VERSION__/${XROOTD_VERSION}/\" + COMMAND sed -e \"s/__VERSION__/${XRootD_VERSION}/\" OUTPUT_FILE \${MANPAGE}.new ) EXECUTE_PROCESS( COMMAND mv -f \${MANPAGE}.new \${MANPAGE} ) diff --git a/src/XrdCeph/genversion.sh b/src/XrdCeph/genversion.sh deleted file mode 100755 index 81008e77822..00000000000 --- a/src/XrdCeph/genversion.sh +++ /dev/null @@ -1,239 +0,0 @@ -#!/bin/bash - -#------------------------------------------------------------------------------- -# Process the git decoration expansion and try to derive version number -#------------------------------------------------------------------------------- -EXP1='^v[12][0-9][0-9][0-9][01][0-9][0-3][0-9]-[0-2][0-9][0-5][0-9]$' -EXP2='^v[0-9]+\.[0-9]+\.[0-9]+$' -EXP3='^v[0-9]+\.[0-9]+\.[0-9]+\-rc.*$' - -#------------------------------------------------------------------------------- -# Get the numeric version -#------------------------------------------------------------------------------- -function getNumericVersion() -{ - VERSION=$1 - if test x`echo $VERSION | egrep $EXP2` == x; then - echo "1000000"; - return; - fi - VERSION=${VERSION/v/} - VERSION=${VERSION//./ } - VERSION=($VERSION) - printf "%d%02d%02d\n" ${VERSION[0]} ${VERSION[1]} ${VERSION[2]} -} - -#------------------------------------------------------------------------------- -# Extract version number from git references -#------------------------------------------------------------------------------- -function getVersionFromRefs() -{ - REFS=${1/RefNames:/} - REFS=${REFS//,/} - REFS=${REFS/(/} - REFS=${REFS/)/} - REFS=($REFS) - - VERSION="unknown" - - for i in ${REFS[@]}; do - if test x`echo $i | egrep $EXP2` != x; then - echo "$i" - return 0 - fi - - if test x`echo $i | egrep $EXP1` != x; then - VERSION="$i" - fi - - if test x`echo $i | egrep $EXP3` != x; then - VERSION="$i" - fi - - done - echo $VERSION - return 0 -} - -#------------------------------------------------------------------------------- -# Generate the version string from the date and the hash -#------------------------------------------------------------------------------- -function getVersionFromLog() -{ - AWK=gawk - EX="`which gawk`" - if test x"${EX}" == x -o ! -x "${EX}"; then - AWK=awk - fi - - VERSION="`echo $@ | $AWK '{ gsub("-","",$1); print $1"-"$4; }'`" - if test $? -ne 0; then - echo "unknown"; - return 1 - fi - echo v$VERSION -} - -#------------------------------------------------------------------------------- -# Print help -#------------------------------------------------------------------------------- -function printHelp() -{ - echo "Usage:" 1>&2 - echo "${0} [--help|--print-only|--version] [SOURCEPATH]" 1>&2 - echo " --help prints this message" 1>&2 - echo " --print-only prints the version to stdout and quits" 1>&2 - echo " --version VERSION sets the version manually" 1>&2 -} - -#------------------------------------------------------------------------------- -# Check the parameters -#------------------------------------------------------------------------------- -while test ${#} -ne 0; do - if test x${1} = x--help; then - PRINTHELP=1 - elif test x${1} = x--print-only; then - PRINTONLY=1 - elif test x${1} = x--version; then - if test ${#} -lt 2; then - echo "--version parameter needs an argument" 1>&2 - exit 1 - fi - USER_VERSION=${2} - shift - else - SOURCEPATH=${1} - fi - shift -done - -if test x$PRINTHELP != x; then - printHelp ${0} - exit 0 -fi - -if test x$SOURCEPATH != x; then - SOURCEPATH=${SOURCEPATH}/ - if test ! -d $SOURCEPATH; then - echo "The given source path does not exist: ${SOURCEPATH}" 1>&2 - exit 1 - fi -fi - -VERSION="unknown" - -#------------------------------------------------------------------------------- -# We're not inside a git repo -#------------------------------------------------------------------------------- -if test ! -d ${SOURCEPATH}.git; then - #----------------------------------------------------------------------------- - # We cannot figure out what version we are - #---------------------------------------------------------------------------- - echo "[I] No git repository info found. Trying to interpret VERSION_INFO" 1>&2 - if test ! -r ${SOURCEPATH}VERSION_INFO; then - echo "[!] VERSION_INFO file absent. Unable to determine the version. Using \"unknown\"" 1>&2 - elif test x"`grep Format ${SOURCEPATH}VERSION_INFO`" != x; then - echo "[!] VERSION_INFO file invalid. Unable to determine the version. Using \"unknown\"" 1>&2 - - #----------------------------------------------------------------------------- - # The version file exists and seems to be valid so we know the version - #---------------------------------------------------------------------------- - else - REFNAMES="`grep RefNames ${SOURCEPATH}VERSION_INFO`" - VERSION="`getVersionFromRefs "$REFNAMES"`" - if test x$VERSION == xunknown; then - SHORTHASH="`grep ShortHash ${SOURCEPATH}VERSION_INFO`" - SHORTHASH=${SHORTHASH/ShortHash:/} - SHORTHASH=${SHORTHASH// /} - DATE="`grep Date ${SOURCEPATH}VERSION_INFO`" - DATE=${DATE/Date:/} - VERSION="`getVersionFromLog $DATE $SHORTHASH`" - fi - fi - -#------------------------------------------------------------------------------- -# Check if the version has been specified by the user -#------------------------------------------------------------------------------- -elif test x$USER_VERSION != x; then - VERSION=$USER_VERSION - -#------------------------------------------------------------------------------- -# We're in a git repo so we can try to determine the version using that -#------------------------------------------------------------------------------- -else - echo "[I] Determining version from git" 1>&2 - EX="`which git`" - if test x"${EX}" == x -o ! -x "${EX}"; then - echo "[!] Unable to find git in the path: setting the version tag to unknown" 1>&2 - else - #--------------------------------------------------------------------------- - # Sanity check - #--------------------------------------------------------------------------- - CURRENTDIR=$PWD - if [ x${SOURCEPATH} != x ]; then - cd ${SOURCEPATH} - fi - git log -1 >/dev/null 2>&1 - if test $? -ne 0; then - echo "[!] Error while generating src/XrdVersion.hh, the git repository may be corrupted" 1>&2 - echo "[!] Setting the version tag to unknown" 1>&2 - else - #------------------------------------------------------------------------- - # Can we match the exact tag? - #------------------------------------------------------------------------- - git describe --tags --abbrev=0 --exact-match >/dev/null 2>&1 - if test ${?} -eq 0; then - VERSION="`git describe --tags --abbrev=0 --exact-match`" - else - LOGINFO="`git log -1 --format='%ai %h'`" - if test ${?} -eq 0; then - VERSION="`getVersionFromLog $LOGINFO`" - fi - fi - fi - cd $CURRENTDIR - fi -fi - -#------------------------------------------------------------------------------- -# Make sure the version string is not longer than 25 characters -#------------------------------------------------------------------------------- -if [ ${#VERSION} -gt 25 ] && [ x$USER_VERSION == x ] ; then - VERSION="${VERSION:0:19}...${VERSION: -3}" -fi - -#------------------------------------------------------------------------------- -# Print the version info and exit if necassary -#------------------------------------------------------------------------------- -if test x$PRINTONLY != x; then - echo $VERSION - exit 0 -fi - -#------------------------------------------------------------------------------- -# Create XrdVersion.hh -#------------------------------------------------------------------------------- -NUMVERSION=`getNumericVersion $VERSION` - -if test ! -r ${SOURCEPATH}src/XrdVersion.hh.in; then - echo "[!] Unable to find src/XrdVersion.hh.in" 1>&2 - exit 1 -fi - -sed -e "s/#define XrdVERSION \"unknown\"/#define XrdVERSION \"$VERSION\"/" ${SOURCEPATH}src/XrdVersion.hh.in | \ -sed -e "s/#define XrdVNUMBER 1000000/#define XrdVNUMBER $NUMVERSION/" \ -> src/XrdVersion.hh.new - -if test $? -ne 0; then - echo "[!] Error while generating src/XrdVersion.hh from the input template" 1>&2 - exit 1 -fi - -if test ! -e src/XrdVersion.hh; then - mv src/XrdVersion.hh.new src/XrdVersion.hh -elif test x"`diff src/XrdVersion.hh.new src/XrdVersion.hh`" != x; then - mv src/XrdVersion.hh.new src/XrdVersion.hh -else - rm src/XrdVersion.hh.new -fi -echo "[I] src/XrdVersion.hh successfully generated" 1>&2 diff --git a/src/XrdCl/CMakeLists.txt b/src/XrdCl/CMakeLists.txt index bac9e51bde1..2a711d19333 100644 --- a/src/XrdCl/CMakeLists.txt +++ b/src/XrdCl/CMakeLists.txt @@ -251,7 +251,7 @@ install( MESSAGE( \"-- Processing: \" \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}/man1/\${MANPAGE} ) EXECUTE_PROCESS( COMMAND cat \${MANPAGE} - COMMAND sed -e \"s/__VERSION__/${XROOTD_VERSION}/\" + COMMAND sed -e \"s/__VERSION__/${XRootD_VERSION}/\" OUTPUT_FILE \${MANPAGE}.new WORKING_DIRECTORY \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}/man1 ) EXECUTE_PROCESS( diff --git a/src/XrdVersion.hh.in b/src/XrdVersion.hh.in index b764bdbbf9d..5bd0236443f 100644 --- a/src/XrdVersion.hh.in +++ b/src/XrdVersion.hh.in @@ -25,20 +25,17 @@ /* specific prior written permission of the institution or contributor. */ /******************************************************************************/ -// this file is automatically updated by the genversion.sh script -// if you touch anything make sure that it still works - #ifndef __XRD_VERSION_H__ #define __XRD_VERSION_H__ -#define XrdVERSION "unknown" +#define XrdVERSION "@XRootD_VERSION_STRING@" // Numeric representation of the version tag // The format for the released code is: xyyzz, where: x is the major version, // y is the minor version and zz is the bugfix revision number // For the non-released code the value is 1000000 #define XrdVNUMUNK 1000000 -#define XrdVNUMBER 1000000 +#define XrdVNUMBER @XRootD_VERSION_NUMBER@ #if XrdDEBUG #define XrdVSTRING XrdVERSION "_dbg"