Skip to content

Commit

Permalink
generate version information via git describe
Browse files Browse the repository at this point in the history
  • Loading branch information
arogge committed Nov 13, 2019
1 parent c382892 commit 879350c
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Expand Up @@ -20,6 +20,7 @@
cmake_minimum_required(VERSION 3.0)

project(bareos NONE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(default_build_type "Debug")
# enable "make test"
Expand All @@ -43,6 +44,9 @@ ELSE()
set(BUILD_BAREOS_BINARIES yes)
ENDIF()

find_package(Git)
include(BareosVersionFromGit)

IF(BUILD_BAREOS_BINARIES)
add_subdirectory(core)
add_subdirectory(webui)
Expand Down
80 changes: 80 additions & 0 deletions cmake/BareosVersionFromGit.cmake
@@ -0,0 +1,80 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2019 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or modify it under
# the terms of version three of the GNU Affero General Public License as
# published by the Free Software Foundation and included in the file LICENSE.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Extract version information and commit timestamp if run in a git checkout

if(Git_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE}
log
-1
--pretty=format:%ct
RESULT_VARIABLE GIT_COMMIT_TIMESTAMP_RESULT
OUTPUT_VARIABLE GIT_COMMIT_TIMESTAMP
ERROR_QUIET)
endif()

if(GIT_COMMIT_TIMESTAMP_RESULT EQUAL 0)
execute_process(COMMAND ${GIT_EXECUTABLE}
describe
--tags
--exact-match
--match
"Release/*"
--dirty=.dirty
RESULT_VARIABLE GIT_DESCRIBE_RELEASE_RESULT
OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT GIT_DESCRIBE_RELEASE_RESULT EQUAL 0)
execute_process(COMMAND ${GIT_EXECUTABLE}
describe
--tags
--match
"WIP/*"
--dirty=.dirty
RESULT_VARIABLE GIT_DESCRIBE_WIP_RESULT
OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif()

if(NOT GIT_DESCRIBE_OUTPUT STREQUAL "")
set(GIT_DESCRIBE_REGEX_LONG
"^([^/]+)/([^-]+)-(([^-]+)?)-?([0-9]+)-g([0-9a-f]+(.dirty)?)[ \n]*")
set(GIT_DESCRIBE_REPLACE_LONG "\\2-\\3\\5.\\6")
set(GIT_DESCRIBE_REGEX_SHORT "^([^/]+)/([0-9.]+)((-[^-]+)?)((.dirty)?)[ \n]*")
set(GIT_DESCRIBE_REPLACE_SHORT "\\2\\3\\5")

string(REGEX MATCH
"${GIT_DESCRIBE_REGEX_LONG}"
GIT_DESCRIBE_REGEX_LONG_MATCH
"${GIT_DESCRIBE_OUTPUT}")
if(GIT_DESCRIBE_REGEX_LONG_MATCH STREQUAL "")
string(REGEX
REPLACE "${GIT_DESCRIBE_REGEX_SHORT}"
"${GIT_DESCRIBE_REPLACE_SHORT}"
GIT_DESCRIBE_VERSION
"${GIT_DESCRIBE_OUTPUT}")
else()
string(REGEX
REPLACE "${GIT_DESCRIBE_REGEX_LONG}"
"${GIT_DESCRIBE_REPLACE_LONG}"
GIT_DESCRIBE_VERSION
"${GIT_DESCRIBE_OUTPUT}")
endif()
endif()
15 changes: 11 additions & 4 deletions core/cmake/BareosExtractVersionInfo.cmake
Expand Up @@ -18,11 +18,18 @@
if(NOT DEFINED VERSION_STRING)
include(BareosVersion OPTIONAL RESULT_VARIABLE BareosVersionFile)
if(BareosVersionFile STREQUAL "NOTFOUND")
message(
FATAL_ERROR "VERSION_STRING not set and BareosVersion.cmake was not found"
)
# no version file, try data from git
if(GIT_DESCRIBE_VERSION)
message(STATUS "Using version information from Git")
set(VERSION_STRING "${GIT_DESCRIBE_VERSION}")
set(VERSION_TIMESTAMP "${GIT_COMMIT_TIMESTAMP}")
else()
message(
FATAL_ERROR "VERSION_STRING not set, BareosVersion.cmake not found and no version data from git available."
)
endif()
else()
message("Using version information from ${BareosVersionFile}")
message(STATUS "Using version information from ${BareosVersionFile}")
endif()
endif()

Expand Down
12 changes: 10 additions & 2 deletions get_version.cmake
Expand Up @@ -17,9 +17,17 @@

cmake_minimum_required(VERSION 3.0)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/core/cmake ${CMAKE_CURRENT_LIST_DIR}/webui/cmake)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" "${CMAKE_CURRENT_LIST_DIR}/core/cmake" "${CMAKE_CURRENT_LIST_DIR}/webui/cmake")

find_package(Git QUIET)
include(BareosVersionFromGit)

include(BareosVersion OPTIONAL RESULT_VARIABLE BareosVersionFile)
if(BareosVersionFile STREQUAL "NOTFOUND")
message(FATAL_ERROR "BareosVersion.cmake was not found")
if(GIT_DESCRIBE_VERSION)
set(VERSION_STRING "${GIT_DESCRIBE_VERSION}")
else()
message(FATAL_ERROR "BareosVersion.cmake not found and no git version available.")
endif()
endif()
message(STATUS "${VERSION_STRING}")
27 changes: 18 additions & 9 deletions webui/cmake/BareosExtractVersionInfo.cmake
Expand Up @@ -18,26 +18,35 @@
if(NOT DEFINED VERSION_STRING)
include(BareosVersion OPTIONAL RESULT_VARIABLE BareosVersionFile)
if(BareosVersionFile STREQUAL "NOTFOUND")
message(
FATAL_ERROR "VERSION_STRING not set and BareosVersion.cmake was not found"
)
# no version file, try data from git
if(GIT_DESCRIBE_VERSION)
message(STATUS "Using version information from Git")
#message(FATAL_ERROR "${GIT_DESCRIBE_VERSION}")
set(VERSION_STRING "${GIT_DESCRIBE_VERSION}")
set(VERSION_TIMESTAMP "${GIT_COMMIT_TIMESTAMP}")
else()
message(
FATAL_ERROR "VERSION_STRING not set, BareosVersion.cmake not found and no version data from git available."
)
endif()
else()
message("Using version information from ${BareosVersionFile}")
message(STATUS "Using version information from ${BareosVersionFile}")
endif()
endif()

string(REGEX MATCH
[0-9.a-zA-Z]+
[-0-9.a-zA-Z]+
BAREOS_FULL_VERSION
${VERSION_STRING})

if(BAREOS_FULL_VERSION STREQUAL "")
message(FATAL_ERROR "BAREOS_FULL_VERSION is not set")
endif()

string(REGEX MATCH
[0-9]+.[0-9]+.[0-9]+
BAREOS_NUMERIC_VERSION
${VERSION_STRING})
string(REGEX MATCH
[0-9]+
SOVERSION
${VERSION_STRING})
string(REPLACE "\""
""
BAREOS_FULL_VERSION
Expand Down

0 comments on commit 879350c

Please sign in to comment.