Skip to content

Commit

Permalink
Use CMake to detect/set XRootD version and generate XrdVersion.hh
Browse files Browse the repository at this point in the history
  • Loading branch information
amadio committed Jun 5, 2023
1 parent 66d7514 commit 2d3a8da
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 602 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION_INFO export-subst
VERSION export-subst
25 changes: 3 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$Format:%(describe)$
1 change: 0 additions & 1 deletion VERSION_INFO

This file was deleted.

1 change: 0 additions & 1 deletion bindings/python/.gitattributes

This file was deleted.

1 change: 0 additions & 1 deletion bindings/python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ build
.cproject
*.py[co]
MANIFEST
VERSION_INFO
1 change: 0 additions & 1 deletion bindings/python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include README.rst
include VERSION_INFO
recursive-include tests *
recursive-include examples *.py
recursive-include docs *
Expand Down
53 changes: 10 additions & 43 deletions bindings/python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 <major>.<minor>.<patch>rc<candidate>
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)
Expand Down
77 changes: 77 additions & 0 deletions cmake/XRootDVersion.cmake
Original file line number Diff line number Diff line change
@@ -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}'")
15 changes: 10 additions & 5 deletions docker/xrd-docker
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
}
Expand Down

0 comments on commit 2d3a8da

Please sign in to comment.