Skip to content

Commit b30d0d3

Browse files
committed
Teach (build) scripts about git versioning
- Insert various info into .VERSION file when `git archive` is performed. - Latest tag - Commit that archive/tag is based on - Author, date, signature info for that commit - Teach top level CMakeLists.txt how to: - Deal with the `git archive` modified version of .VERSION - Check if src dir is a git repo - Extract version info from `git describe` - Fall back on manually entered version string in .VERSION when it can't be extracted from git - Embed detailed version info in caf and cafrun that was extracted by git - Ensure install.sh and other build scripts will fetch the `git archive` created version info, or fall back onto manually entered version in .VERSION
1 parent 5915924 commit b30d0d3

File tree

7 files changed

+70
-14
lines changed

7 files changed

+70
-14
lines changed

.VERSION

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
# OpenCoarrays version file. Odd patch levels indicate inter-release
2-
# version, i.e., code is from SCM/git. This project uses semantic
3-
# versioning. For details see http://semver.org
4-
1+
$Format:%d%n%n$
2+
# Fall back version, probably last release:
53
1.8.11
4+
5+
# OpenCoarrays version file. This project uses semantic
6+
# versioning. For details see http://semver.org
7+
#
8+
# Release archive created from commit:
9+
# $Format:%H %d$
10+
# $Format:Created on %ci by %cN, and$
11+
# $Format:signed by %GS using %GK.$
12+
# $Format:Signature status: %G?$
13+
$Format:%GG$

.gitattributes

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ prerequisites/build text
3131
developer-scripts export-ignore
3232
codecov.yml export-ignore
3333
*.enc export-ignore
34-
.github
34+
.github export-ignore
35+
36+
# Perform substitutions when `git export`ing these files
37+
.VERSION export-subst

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ after_script:
204204
- |
205205
set -o errexit
206206
if [[ "${TRAVIS_TAG}" ]]; then
207-
if [[ "v${TRAVIS_TAG}" != "v$(sed -n 's/\([0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}\)/\1/p' .VERSION)" ]]; then
207+
if [[ "v${TRAVIS_TAG}" != "v$(sed -n '/[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}/{s/^\([^.]*\)\([0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}\)\(.*\)/\2/p;q;}' .VERSION)" ]]; then
208208
echo "ERROR: You are trying to tag a new release but have a version missmatch in \`.VERSION\`"
209209
false # throw an error
210210
fi

CMakeLists.txt

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set_property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYP
99
# Add option and check environment to determine if developer tests should be run
1010
if($ENV{OPENCOARRAYS_DEVELOPER})
1111
option(CAF_RUN_DEVELOPER_TESTS "Run tests intended only for developers" ON)
12+
message( STATUS "OpenCoarrays developer tests turned on")
1213
else()
1314
option(CAF_RUN_DEVELOPER_TESTS "Run tests intended only for developers" OFF)
1415
endif()
@@ -20,9 +21,47 @@ endif()
2021

2122
# Name project and specify source languages
2223
# Parse version from .VERSION file so that more info can be added and easier to get from scripts
23-
file( STRINGS ".VERSION" OpenCoarraysVersion
24+
file(STRINGS ".VERSION" first_line
25+
LIMIT_COUNT 1
26+
)
27+
28+
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
29+
OpenCoarraysVersion "${first_line}")
30+
31+
if((NOT (OpenCoarraysVersion MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")) AND (EXISTS "${CMAKE_SOURCE_DIR}/.git"))
32+
message( STATUS "Build from git repository detected")
33+
find_package(Git)
34+
if(GIT_FOUND)
35+
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --abbrev=0
36+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
37+
RESULT_VARIABLE git_status
38+
OUTPUT_VARIABLE git_output
39+
OUTPUT_STRIP_TRAILING_WHITESPACE)
40+
if((git_status STREQUAL "0") AND (git_output MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+"))
41+
set(OpenCoarraysVersion "${git_output}")
42+
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --always --dirty
43+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
44+
RESULT_VARIABLE git_status
45+
OUTPUT_VARIABLE full_git_describe
46+
OUTPUT_STRIP_TRAILING_WHITESPACE)
47+
endif()
48+
else()
49+
message( WARNING "Could not find git executable!")
50+
endif()
51+
endif()
52+
53+
if(NOT (OpenCoarraysVersion MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+"))
54+
message( WARNING "Could not extract version from git, falling back on .VERSION, line 3.")
55+
file(STRINGS ".VERSION" OpenCoarraysVersion
2456
REGEX "[0-9]+\\.[0-9]+\\.[0-9]+"
25-
)
57+
)
58+
endif()
59+
60+
if(NOT full_git_describe)
61+
set(full_git_describe ${OpenCoarraysVersion})
62+
message( STATUS "Full `git describe`: ${full_git_describe}")
63+
endif()
64+
2665
project(opencoarrays VERSION "${OpenCoarraysVersion}" LANGUAGES C Fortran)
2766
message( STATUS "Building OpenCoarrays version: ${OpenCoarraysVersion}" )
2867

install.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,11 @@ source $opencoarrays_src_dir/prerequisites/install-functions/report_results.sh
240240

241241
if [[ "${arg_v}" == "${__flag_present}" || "${arg_V}" == "opencoarrays" ]]; then
242242

243-
# Print script copyright if invoked with -v, -V, or --version argument
244-
opencoarrays_version=$(sed -n 's/\([0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}\)/\1/p' "${opencoarrays_src_dir%/}/.VERSION")
243+
# Print script copyright & version if invoked with -v, -V, or
244+
# --version argument git attributes handle .VERSION, making it more
245+
# robust, but fallback version is still manually included. Search
246+
# for the first version string we encounter and extract it using sed:
247+
opencoarrays_version=$(sed -n '/[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}/{s/^\([^.]*\)\([0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}\)\(.*\)/\2/p;q;}' "${opencoarrays_src_dir%/}/.VERSION")
245248
if [[ "${arg_v}" == "${__flag_present}" ]]; then
246249
echo "OpenCoarrays ${opencoarrays_version}"
247250
echo ""

prerequisites/check_version.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ elif [[ $1 == '--list' || $1 == '-l' ]]; then
8181
exit 40
8282

8383
elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then
84-
# Print script copyright if invoked with -v, -V, or --version argument
85-
opencoarrays_version=$(sed -n 's/\([0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}\)/\1/p' ../.VERSION)
84+
# Print script copyright if invoked with -v, -V, or --version
85+
# argument Extract version from .VERSION file. Git automatically
86+
# inserts various things when performing git archive, so ensure we
87+
# extract just the first version string
88+
opencoarrays_version=$(sed -n '/[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}/{s/^\([^.]*\)\([0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}\)\(.*\)/\2/p;q;}' ../.VERSION)
8689
echo "opencoarrays $opencoarrays_version"
8790
echo ""
8891
echo "OpenCoarrays prerequisite version verifier"

src/mpi/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../extensions/caf-head CAF_HEADER)
144144
file(WRITE "${compiler_wrapper}" "${CAF_HEADER}\n")
145145
file(APPEND "${compiler_wrapper}" "caf_mod_dir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}/mod\"\n")
146146
file(APPEND "${compiler_wrapper}" "caf_lib_dir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n")
147-
file(APPEND "${compiler_wrapper}" "caf_version=${PROJECT_VERSION}\n")
147+
file(APPEND "${compiler_wrapper}" "caf_version=${full_git_describe}\n")
148148
if(gfortran_compiler)
149149
file(APPEND "${compiler_wrapper}" "link_args='-fcoarray=lib -lcaf_mpi'\n")
150150
elseif(portland_group_compiler)
@@ -175,7 +175,7 @@ install(
175175
)
176176
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../extensions/cafrun-head CAFRUN_HEADER)
177177
file(WRITE "${caf_launcher}" "${CAFRUN_HEADER}\n")
178-
file(APPEND "${caf_launcher}" "caf_version=${PROJECT_VERSION}\n")
178+
file(APPEND "${caf_launcher}" "caf_version=${full_git_describe}\n")
179179
file(APPEND "${caf_launcher}" "CAFRUN=${MPIEXEC}\n")
180180

181181
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../extensions/cafrun-foot FOOTER)

0 commit comments

Comments
 (0)