Browse Source

Use script to calculate the build version

pull/889/head
Hamish Coleman 3 years ago
parent
commit
aafca3813a
  1. 31
      CMakeLists.txt
  2. 4
      configure.ac
  3. 8
      doc/Scripts.md
  4. 42
      scripts/version.sh

31
CMakeLists.txt

@ -6,39 +6,18 @@ SET(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# N2n release information # N2n release information
set(N2N_OSNAME ${CMAKE_SYSTEM_NAME})
execute_process( execute_process(
COMMAND cat VERSION COMMAND scripts/version.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE PACKAGE_VERSION OUTPUT_VARIABLE PACKAGE_VERSION
) )
string(STRIP "${PACKAGE_VERSION}" PACKAGE_VERSION) string(STRIP "${PACKAGE_VERSION}" PACKAGE_VERSION)
set(N2N_OSNAME ${CMAKE_SYSTEM_NAME}) MESSAGE(STATUS "Build for version: ${PACKAGE_VERSION}")
execute_process(
COMMAND git status
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_OUTPUT
RESULT_VARIABLE GIT_ERROR_CODE
)
if (GIT_ERROR_CODE EQUAL 0)
execute_process(
COMMAND git rev-list --count HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REV
)
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_ID
)
string(REGEX REPLACE "\n$" "" GIT_REV "${GIT_REV}")
string(REGEX REPLACE "\n$" "" GIT_ID "${GIT_ID}")
set(N2N_VERSION "${N2N_VERSION}.r${GIT_REV}.${GIT_ID}")
MESSAGE(STATUS "Build from git rev: ${N2N_VERSION}")
endif (GIT_ERROR_CODE EQUAL 0)
add_definitions(-DCMAKE_BUILD) add_definitions(-DCMAKE_BUILD)
add_definitions(-DPACKAGE_OSNAME="${N2N_OSNAME}") add_definitions(-DPACKAGE_OSNAME="${N2N_OSNAME}" -DN2N_OSNAME="${N2N_OSNAME}")
add_definitions(-DPACKAGE_VERSION="${PACKAGE_VERSION}" -DN2N_OSNAME="${N2N_OSNAME}") add_definitions(-DPACKAGE_VERSION="${PACKAGE_VERSION}")
# Build information # Build information

4
configure.ac

@ -1,8 +1,8 @@
odnl> Do not add anything above odnl> Do not add anything above
AC_INIT([edge], m4_esyscmd([cat VERSION | tr -d '\n'])) AC_INIT([edge], m4_esyscmd([scripts/version.sh | tr -d '\n']))
dnl> Do not add anything above dnl> Do not add anything above
N2N_VERSION_SHORT=${PACKAGE_VERSION} N2N_VERSION_SHORT=$(scripts/version.sh short)
if test -d ".git"; then if test -d ".git"; then
# NOTE: keep in sync with the definitions for configure.in files under the packages folder # NOTE: keep in sync with the definitions for configure.in files under the packages folder

8
doc/Scripts.md

@ -59,3 +59,11 @@ This shell script is used to run automated tests during development.
A sample script to route all the host traffic towards a remote gateway, A sample script to route all the host traffic towards a remote gateway,
which is reachable via the n2n virtual interface. which is reachable via the n2n virtual interface.
### `version.sh`
This script is used to determine the current version number during the
build process.
It looks at both the VERSION file and the GIT tags and outputs the
version number to use.

42
scripts/version.sh

@ -0,0 +1,42 @@
#!/bin/sh
#
# Output the current version number
#
usage() {
echo "Usage: $0 [short]"
echo
echo "Determine the correct version number for the current build"
exit 0
}
# TODO: search for the top dir that contains the VERSION file?
VER_FILE_SHORT=$(cat VERSION)
if git status >/dev/null; then
VER_GIT_SHORT=$(git describe --abbrev=0)
VER_GIT=$(git describe --abbrev=7 --dirty)
if [ "$VER_FILE_SHORT" != "$VER_GIT_SHORT" ]; then
echo "Error: VERSION file does not match tag version ($VER_FILE_SHORT != $VER_GIT_SHORT)"
exit 1
fi
VER_SHORT="$VER_GIT_SHORT"
VER="$VER_GIT"
else
VER_SHORT="$VER_FILE_SHORT"
VER="$VER_FILE_SHORT"
fi
case "$1" in
short)
echo "$VER_SHORT"
;;
"")
echo "$VER"
;;
*)
usage
;;
esac
Loading…
Cancel
Save