Write Clio version file from template (#457)

* Set build version from git

* disallow untagged commits to master

* remove clang-format ingore around versionString
This commit is contained in:
Michael Legleux
2023-01-09 09:36:33 -08:00
committed by GitHub
parent 1a9d328f94
commit c51d696181
8 changed files with 54 additions and 56 deletions

20
.githooks/ensure_release_tag Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
# Pushing a release branch requires an annotated tag at the released commit
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $branch =~ master ]]; then
# check if HEAD commit is tagged
if ! git describe --exact-match HEAD; then
echo "Commits to master must be tagged"
exit 1
fi
elif [[ $branch =~ release/* ]]; then
IFS=/ read -r branch rel_ver <<< ${branch}
tag=$(git describe --tags --abbrev=0)
if [[ "${rel_ver}" != "${tag}" ]]; then
echo "release/${rel_ver} branches must have annotated tag ${rel_ver}"
echo "git tag -am\"${rel_ver}\" ${rel_ver}"
exit 1
fi
fi

View File

@@ -14,7 +14,7 @@ changes=$(diff <(echo "$first") <(echo "$second") | wc -l | sed -e 's/^[[:space:
if [ "$changes" != "0" ]; then
cat <<\EOF
WARNING
WARNING
-----------------------------------------------------------------------------
Automatically re-formatted code with `clang-format` - commit was aborted.
Please manually add any updated files and commit again.
@@ -23,3 +23,5 @@ if [ "$changes" != "0" ]; then
EOF
exit 1
fi
.githooks/ensure_release_tag

View File

@@ -32,17 +32,19 @@ jobs:
container:
image: ${{ matrix.type.image }}
# options: --user 1001
steps:
- uses: actions/checkout@v3
with:
path: clio
fetch-depth: 0
- name: Clone Clio packaging repo
uses: actions/checkout@v3
with:
path: clio-packages
repository: XRPLF/clio-packages
ref: main
- name: Build
shell: bash

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ build/
.vscode
.python-version
config.json
src/main/impl/Build.cpp

View File

@@ -25,33 +25,7 @@
#include <stdexcept>
namespace Build {
//--------------------------------------------------------------------------
// The build version number. You must edit this for each release
// and follow the format described at http://semver.org/
//------------------------------------------------------------------------------
// clang-format off
char const* const versionString = "1.0.3"
// clang-format on
"+"
#ifdef CLIO_BUILD
CLIO_BUILD
#endif
#ifdef DEBUG
".DEBUG"
#ifdef SANITIZER
"."
#endif
#endif
#ifdef SANITIZER
BOOST_PP_STRINGIZE(SANITIZER)
#endif
#ifdef PKG
"-release"
#endif
;
static constexpr char versionString[] = "@VERSION@";
std::string const&
getClioVersionString()

View File

@@ -1,15 +1,28 @@
#[===================================================================[
read version from source
write version to source
#]===================================================================]
file (STRINGS src/main/impl/Build.cpp BUILD_INFO)
foreach (line_ ${BUILD_INFO})
if (line_ MATCHES "versionString[ ]*=[ ]*\"(.+)\"")
set (clio_version ${CMAKE_MATCH_1})
endif ()
endforeach ()
if (clio_version)
message (STATUS "clio version: ${clio_version}")
else ()
message (FATAL_ERROR "unable to determine clio version")
endif ()
find_package(Git REQUIRED)
execute_process(COMMAND ${GIT_EXECUTABLE} branch --show-current OUTPUT_VARIABLE BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE)
set(GIT_COMMAND describe --tags)
execute_process(COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} OUTPUT_VARIABLE VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
set(VERSION "${VERSION}")
if(NOT (BRANCH MATCHES master OR BRANCH MATCHES release/*)) # for develop and any other branch name YYYYMMDDHMS-<git-ref>
set(GIT_COMMAND rev-parse --short HEAD)
execute_process(COMMAND date +%Y%m%d%H%M%S OUTPUT_VARIABLE DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
set(VERSION "${VERSION}-${DATE}")
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(VERSION "${VERSION}+DEBUG")
endif()
message(STATUS "Build version: ${VERSION}")
set(clio_version "${VERSION}")
configure_file(CMake/Build.cpp.in ${CMAKE_SOURCE_DIR}/src/main/impl/Build.cpp)

0
CMake/coverage.cmake Normal file
View File

View File

@@ -14,21 +14,7 @@ if(VERBOSE)
set(FETCHCONTENT_QUIET FALSE CACHE STRING "Verbose FetchContent()")
endif()
if(NOT GIT_COMMIT_HASH)
if(VERBOSE)
message("GIT_COMMIT_HASH not provided...looking for git")
endif()
find_package(Git)
if(Git_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE git-ref)
if(git-ref)
set(BUILD "${git-ref}")
message(STATUS "Build version: ${BUILD}")
add_definitions(-DCLIO_BUILD="${BUILD}")
endif()
endif()
endif() #git
if(PACKAGING)
add_definitions(-DPKG=1)
endif()