Skip to content

Commit df82297

Browse files
committed
Merge PR #195 into development
* upstream/pr/195/head: cmake: make set_version more robust against insufficient python versions tools: Decode command output properly. build: Don't write site_config.hpp if it hasn't changed. Signed-off-by: Torbjörn Klatt <[email protected]>
2 parents 81ecf14 + bc065c6 commit df82297

File tree

5 files changed

+40
-20
lines changed

5 files changed

+40
-20
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ message(STATUS "****************************************************************
155155
message(STATUS "Configuring sources")
156156
update_site_config()
157157

158+
find_package(PythonInterp REQUIRED)
158159
add_custom_target(set_version ALL
159-
COMMAND ${pfasst_SOURCE_DIR}/tools/get_pfasst_version.sh
160+
COMMAND ${PYTHON_EXECUTABLE} ${pfasst_SOURCE_DIR}/tools/get_pfasst_version.py
160161
WORKING_DIRECTORY ${pfasst_SOURCE_DIR}
161162
COMMENT "Updating PFASST++ version number"
162163
USES_TERMINAL

cmake/site_config.hpp.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using namespace std;
1212

1313
namespace pfasst
1414
{
15-
static constexpr const char* VERSION = "pfasst_VERSION";
15+
static constexpr const char* VERSION = "@pfasst_VERSION@";
1616
} // ::pfasst
1717

1818
#endif // _PFASST__SITE_CONFIG_HPP

cmake/utility_functions.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ macro(update_site_config)
3333
if(pfasst_RANDOM_SEED)
3434
add_definitions(-DPFASST_DEFAULT_RANDOM_SEED)
3535
endif()
36+
execute_process(COMMAND git describe --dirty
37+
OUTPUT_VARIABLE pfasst_VERSION
38+
OUTPUT_STRIP_TRAILING_WHITESPACE)
3639
configure_file(
3740
"${pfasst_SOURCE_DIR}/cmake/site_config.hpp.in"
3841
"${CMAKE_CURRENT_SOURCE_DIR}/include/pfasst/site_config.hpp"

tools/get_pfasst_version.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# encoding: utf-8
2+
3+
from __future__ import print_function
4+
5+
from sys import version_info
6+
7+
if version_info[0] == 2 and version_info[1] < 7:
8+
raise SystemExit("Insufficient Python Interpreter Version (%s < 2.7)" % (version_info,))
9+
10+
import re
11+
import subprocess
12+
13+
from os.path import dirname, abspath, join
14+
15+
# get git version
16+
version = subprocess.check_output(['git', 'describe', '--dirty']).decode().strip()
17+
18+
# read in site_config.hpp
19+
base = dirname(dirname(abspath(__file__)))
20+
site_config = abspath(join(base, 'include', 'pfasst', 'site_config.hpp'))
21+
22+
with open(site_config, 'r') as f:
23+
config = f.read()
24+
25+
# reset version
26+
new_config = re.sub('VERSION = "[^"]*"', 'VERSION = "{version}"'.format(version=version), config)
27+
28+
# write site_config if it has changed
29+
if config != new_config:
30+
with open(site_config, 'w') as f:
31+
f.write(new_config)
32+
print("PFASST++ version set to: %s" % (version,))
33+
else:
34+
print("PFASST++ version did not change (still %s)" % (version,))

tools/get_pfasst_version.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)