Skip to content

Commit 7be88e9

Browse files
authored
Merge pull request #453 from lukaszstolarczuk/set-versions
Set versions in CMake
2 parents 05456ea + 30f54e1 commit 7be88e9

File tree

7 files changed

+144
-13
lines changed

7 files changed

+144
-13
lines changed

.github/workflows/basic.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on: workflow_call
66
permissions:
77
contents: read
88

9+
env:
10+
# for installation testing - it should match with version set in CMake
11+
UMF_VERSION: 0.1.0
12+
913
jobs:
1014
icx-build:
1115
# TODO: we could merge ICX build with gcc/clang (using our dockers) Issue: #259
@@ -34,7 +38,10 @@ jobs:
3438
- name: Install apt packages
3539
run: |
3640
apt-get update
37-
apt-get install -y libnuma-dev libjemalloc-dev libtbb-dev libhwloc-dev sudo
41+
apt-get install -y libnuma-dev libjemalloc-dev libtbb-dev libhwloc-dev python3-pip sudo
42+
43+
- name: Install Python requirements
44+
run: python3 -m pip install -r third_party/requirements.txt
3845

3946
- name: Configure build
4047
run: >
@@ -71,6 +78,7 @@ jobs:
7178
--disjoint-pool
7279
--jemalloc-pool
7380
--scalable-pool
81+
--umf-version ${{env.UMF_VERSION}}
7482
${{ matrix.shared_library == 'ON' && '--shared-library' || ''}}
7583
7684
ubuntu-build:
@@ -170,6 +178,7 @@ jobs:
170178
--disjoint-pool
171179
--jemalloc-pool
172180
--scalable-pool
181+
--umf-version ${{env.UMF_VERSION}}
173182
${{ matrix.shared_library == 'ON' && '--shared-library' || '' }}
174183
175184
windows-build:
@@ -258,6 +267,7 @@ jobs:
258267
--disjoint-pool
259268
--jemalloc-pool
260269
--scalable-pool
270+
--umf-version ${{env.UMF_VERSION}}
261271
${{ matrix.shared_library == 'ON' && '--shared-library' || ''}}
262272
263273
macos-build:
@@ -304,7 +314,8 @@ jobs:
304314
--build-dir ${{env.BUILD_DIR}}
305315
--install-dir ${{env.INSTL_DIR}}
306316
--build-type ${{env.BUILD_TYPE}}
307-
--shared-library
308317
--disjoint-pool
309318
--jemalloc-pool
310319
--scalable-pool
320+
--umf-version ${{env.UMF_VERSION}}
321+
--shared-library

CMakeLists.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ project(
88
VERSION 0.1.0
99
LANGUAGES C)
1010

11+
# needed when UMF is used as an external project
12+
set(UMF_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
13+
14+
list(APPEND CMAKE_MODULE_PATH "${UMF_CMAKE_SOURCE_DIR}/cmake")
15+
include(helpers)
16+
17+
# CMAKE_PROJECT_VERSION[_MAJOR|_MINOR|_PATCH] variables are set via 'project'
18+
# command. They cannot contain any "pre-release" part, though. We use custom
19+
# "UMF_SRC_VERSION" to store more accurate (source) version - this var should be
20+
# used, e.g., for creating packages.
21+
set_source_version()
22+
message(
23+
STATUS
24+
"UMF version: ${CMAKE_PROJECT_VERSION} (source version: ${UMF_SRC_VERSION})"
25+
)
26+
1127
# Build Options
1228
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
1329
option(UMF_BUILD_LEVEL_ZERO_PROVIDER "Build Level Zero memory provider" ON)
@@ -109,12 +125,6 @@ include(CMakePackageConfigHelpers)
109125
include(GNUInstallDirs)
110126
find_package(PkgConfig)
111127

112-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
113-
include(helpers)
114-
115-
# needed when UMF is used as an external project
116-
set(UMF_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
117-
118128
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
119129
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
120130
set(CMAKE_UMF_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

cmake/helpers.cmake

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,70 @@
1010
include(CheckCCompilerFlag)
1111
include(CheckCXXCompilerFlag)
1212

13+
# src version shows the current version, as reported by 'git describe', unless
14+
# 'git' is not available, then fall back to the top-level defined version
15+
function(set_source_version)
16+
execute_process(
17+
COMMAND git describe --always
18+
OUTPUT_VARIABLE GIT_VERSION
19+
WORKING_DIRECTORY ${UMF_CMAKE_SOURCE_DIR}
20+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
21+
22+
if(GIT_VERSION)
23+
# 1.5.0 - we're on a tag
24+
string(REGEX MATCHALL "\^([0-9]+\.[0-9]+\.[0-9]+)\$" MATCHES
25+
${GIT_VERSION})
26+
if(MATCHES)
27+
set(UMF_SRC_VERSION
28+
"${CMAKE_MATCH_1}"
29+
PARENT_SCOPE)
30+
return()
31+
endif()
32+
33+
# 1.5.0-rc1 - we're on a RC tag
34+
string(REGEX MATCHALL "\^([0-9]+\.[0-9]+\.[0-9]+\-rc[0-9]+)\$" MATCHES
35+
${GIT_VERSION})
36+
if(MATCHES)
37+
set(UMF_SRC_VERSION
38+
"${CMAKE_MATCH_1}"
39+
PARENT_SCOPE)
40+
return()
41+
endif()
42+
43+
# 1.5.0-rc1-19-gb8f78a329 -> 1.5.0-rc1.git19.gb8f78a329
44+
string(REGEX MATCHALL "([0-9.]*)-rc([0-9]*)-([0-9]*)-([0-9a-g]*)"
45+
MATCHES ${GIT_VERSION})
46+
if(MATCHES)
47+
set(UMF_SRC_VERSION
48+
"${CMAKE_MATCH_1}-rc${CMAKE_MATCH_2}.git${CMAKE_MATCH_3}.${CMAKE_MATCH_4}"
49+
PARENT_SCOPE)
50+
return()
51+
endif()
52+
53+
# 1.5.0-19-gb8f78a329 -> 1.5.0-git19.gb8f78a329
54+
string(REGEX MATCHALL "([0-9.]*)-([0-9]*)-([0-9a-g]*)" MATCHES
55+
${GIT_VERSION})
56+
if(MATCHES)
57+
set(UMF_SRC_VERSION
58+
"${CMAKE_MATCH_1}-git${CMAKE_MATCH_2}.${CMAKE_MATCH_3}"
59+
PARENT_SCOPE)
60+
return()
61+
endif()
62+
63+
# no full version is available (e.g. only a hash commit) or a pattern
64+
# was not recognized
65+
set(UMF_SRC_VERSION
66+
"${CMAKE_PROJECT_VERSION}.git.${GIT_VERSION}"
67+
PARENT_SCOPE)
68+
else()
69+
# git reported no version. Use version set up in the top-level CMake
70+
# with a "devel" suffix
71+
set(UMF_SRC_VERSION
72+
"${CMAKE_PROJECT_VERSION}-devel"
73+
PARENT_SCOPE)
74+
endif()
75+
endfunction()
76+
1377
# Sets ${ret} to version of program specified by ${name} in major.minor format
1478
function(get_program_version_major_minor name ret)
1579
execute_process(

src/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ if(UMF_BUILD_SHARED_LIBRARY)
114114
WINDOWS_DEF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libumf.def)
115115
set(UMF_PRIVATE_COMPILE_DEFINITIONS ${UMF_PRIVATE_COMPILE_DEFINITIONS}
116116
"UMF_SHARED_LIBRARY")
117-
set_target_properties(umf PROPERTIES RUNTIME_OUTPUT_DIRECTORY
118-
${CMAKE_UMF_OUTPUT_DIRECTORY})
117+
set_target_properties(
118+
umf
119+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_UMF_OUTPUT_DIRECTORY}
120+
VERSION ${CMAKE_PROJECT_VERSION}
121+
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})
119122
else()
120123
add_umf_library(
121124
NAME umf

src/proxy_lib/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ add_umf_library(
2727
LIBS ${PROXY_LIBS}
2828
LINUX_MAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/proxy_lib.map
2929
WINDOWS_DEF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/proxy_lib.def)
30+
set_target_properties(umf_proxy PROPERTIES SOVERSION
31+
${CMAKE_PROJECT_VERSION_MAJOR})
3032

3133
add_library(${PROJECT_NAME}::proxy ALIAS umf_proxy)
3234

test/test_installation.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import argparse
99
import difflib
10+
from packaging.version import Version
1011
from pathlib import Path
1112
import platform
1213
import subprocess # nosec B404
@@ -25,6 +26,7 @@ class UmfInstaller:
2526
build_type (str): Debug or Release build type passed to the script
2627
shared_library (bool): Determines if the UMF was built as a shared library
2728
pools (List[str]): A list of enabled pools during the UMF compilation
29+
umf_version (Version): UMF version currently being built and installed
2830
match_list (List[str]): A list of relative paths of files that should be installed
2931
"""
3032

@@ -36,13 +38,15 @@ def __init__(
3638
build_type: str,
3739
shared_library: bool,
3840
pools: List[str],
41+
umf_version: Version,
3942
):
4043
self.workspace_dir = workspace_dir
4144
self.build_dir = build_dir
4245
self.install_dir = install_dir
4346
self.build_type = build_type
4447
self.shared_library = shared_library
4548
self.pools = pools
49+
self.umf_version = umf_version
4650
self.match_list = self._create_match_list()
4751

4852
def _create_match_list(self) -> List[str]:
@@ -95,11 +99,34 @@ def _create_match_list(self) -> List[str]:
9599
]
96100
for pool in self.pools:
97101
lib.append(f"lib/{lib_prefix}{pool}.{lib_ext_static}")
98-
lib_ext = lib_ext_shared if self.shared_library else lib_ext_static
99-
lib.append(f"lib/{lib_prefix}umf.{lib_ext}")
102+
if self.shared_library:
103+
lib.append(f"lib/{lib_prefix}umf.{lib_ext_shared}")
104+
105+
if platform.system() == "Linux":
106+
lib.append(
107+
f"lib/{lib_prefix}umf.{lib_ext_shared}.{self.umf_version.major}"
108+
)
109+
lib.append(f"lib/{lib_prefix}umf.{lib_ext_shared}.{self.umf_version}")
110+
elif platform.system() == "Darwin": # MacOS
111+
lib.append(
112+
f"lib/{lib_prefix}umf.{self.umf_version.major}.{lib_ext_shared}"
113+
)
114+
lib.append(f"lib/{lib_prefix}umf.{self.umf_version}.{lib_ext_shared}")
115+
else:
116+
lib.append(f"lib/{lib_prefix}umf.{lib_ext_static}")
117+
100118
if is_umf_proxy:
101119
lib.append(f"lib/{lib_prefix}umf_proxy.{lib_ext_shared}")
102120

121+
if platform.system() == "Linux":
122+
lib.append(
123+
f"lib/{lib_prefix}umf_proxy.{lib_ext_shared}.{self.umf_version.major}"
124+
)
125+
elif platform.system() == "Darwin": # MacOS
126+
lib.append(
127+
f"lib/{lib_prefix}umf_proxy.{self.umf_version.major}.{lib_ext_shared}"
128+
)
129+
103130
share = []
104131
share = [
105132
"share",
@@ -155,9 +182,14 @@ def validate_installed_files(self) -> None:
155182
)
156183
]
157184

185+
expected_files = [
186+
str(entry)
187+
for entry in sorted(self.match_list, key=lambda x: str(x).casefold())
188+
]
189+
158190
diff = list(
159191
difflib.unified_diff(
160-
self.match_list,
192+
expected_files,
161193
installed_files,
162194
fromfile="Expected files",
163195
tofile="Installed files",
@@ -252,6 +284,11 @@ def parse_arguments(self) -> argparse.Namespace:
252284
action="store_true",
253285
help="Add this argument if the UMF was built with Scalable Pool enabled",
254286
)
287+
self.parser.add_argument(
288+
"--umf-version",
289+
action="store",
290+
help="Current version of the UMF, e.g. 1.0.0",
291+
)
255292
return self.parser.parse_args()
256293

257294
def run(self) -> None:
@@ -269,6 +306,7 @@ def run(self) -> None:
269306
pools.append("jemalloc_pool")
270307
if self.args.scalable_pool:
271308
pools.append("scalable_pool")
309+
umf_version = Version(self.args.umf_version)
272310

273311
umf_installer = UmfInstaller(
274312
workspace_dir,
@@ -277,6 +315,7 @@ def run(self) -> None:
277315
self.args.build_type,
278316
self.args.shared_library,
279317
pools,
318+
umf_version,
280319
)
281320

282321
print("Installation test - BEGIN", flush=True)

third_party/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
clang-format==15.0.7
44
cmake-format==0.6.13
55
black==24.3.0
6+
# Tests
7+
packaging==24.0
68
# Generating HTML documentation
79
pygments==2.15.1
810
sphinxcontrib_applehelp==1.0.4

0 commit comments

Comments
 (0)