Fix VERSIONTAG generation

storage-server has a bug where the git tag is only regenerated when
cmake runs, but not when the git index changes.

Import the code to do this properly from lokinet, and rename it from
SHORT_HASH -> VERSIONTAG to be consistent.
This commit is contained in:
Jason Rhinelander 2022-05-30 14:25:10 -03:00
parent e017637351
commit ad3cf01bee
No known key found for this signature in database
GPG key ID: C4992CE7A88D4262
4 changed files with 91 additions and 16 deletions

View file

@ -12,7 +12,7 @@ endif()
cmake_minimum_required(VERSION 3.10)
project(storage_server
project(oxenss
VERSION 2.3.0
LANGUAGES CXX C)

60
cmake/GenVersion.cmake Normal file
View file

@ -0,0 +1,60 @@
# Copyright (c) 2014-2019, The Monero Project
# Copyright (c) 2019-2022, The Oxen Project
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
# Check what commit we're on
execute_process(COMMAND "${GIT}" rev-parse --short HEAD RESULT_VARIABLE RET OUTPUT_VARIABLE COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
if(RET)
# Something went wrong, set the version tag to -unknown
message(WARNING "Cannot determine current commit. Make sure that you are building either from a Git working tree or from a source archive.")
set(VERSIONTAG "unknown")
else()
message(STATUS "You are currently on commit ${COMMIT}")
# Get all the tags
execute_process(COMMAND "${GIT}" rev-list --tags --max-count=1 --abbrev-commit RESULT_VARIABLE RET OUTPUT_VARIABLE TAGGEDCOMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT TAGGEDCOMMIT)
message(WARNING "Cannot determine most recent tag. Make sure that you are building either from a Git working tree or from a source archive.")
set(VERSIONTAG "${COMMIT}")
else()
# Check if we're building that tagged commit or a different one
if(COMMIT STREQUAL TAGGEDCOMMIT)
message(STATUS "${COMMIT} is a tagged release; setting version tag to 'release'")
set(VERSIONTAG "release")
else()
message(STATUS "You are not building a tagged release; setting version tag to '${COMMIT}'")
set(VERSIONTAG "${COMMIT}")
endif()
endif()
endif()
configure_file("${SRC}" "${DEST}" @ONLY)

View file

@ -24,21 +24,36 @@ add_subdirectory(utils)
# Build Info
if(OXENSS_SHORT_HASH)
set(SHORT_HASH "${OXENSS_SHORT_HASH}")
if(OXENSS_VERSIONTAG)
set(VERSIONTAG "${OXENSS_VERSIONTAG}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/version.cpp")
else()
set(GIT_INDEX_FILE "${PROJECT_SOURCE_DIR}/.git/index")
find_package(Git)
if(GIT_FOUND)
execute_process(
if(EXISTS ${GIT_INDEX_FILE} AND ( GIT_FOUND OR Git_FOUND) )
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
set(genversion_args "-DGIT=${GIT_EXECUTABLE}")
foreach(v oxenss_VERSION oxenss_VERSION_MAJOR oxenss_VERSION_MINOR oxenss_VERSION_PATCH)
list(APPEND genversion_args "-D${v}=${${v}}")
endforeach()
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/version.cpp"
COMMAND
git rev-parse --short HEAD
OUTPUT_VARIABLE
SHORT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
"${CMAKE_COMMAND}"
${genversion_args}
"-DSRC=${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in"
"-DDEST=${CMAKE_CURRENT_BINARY_DIR}/version.cpp"
"-P" "${PROJECT_SOURCE_DIR}/cmake/GenVersion.cmake"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in"
"${GIT_INDEX_FILE}")
else()
set(SHORT_HASH "unknown")
message(STATUS "Git was not found! Setting version to to nogit")
set(VERSIONTAG "nogit")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/version.cpp")
endif()
endif()
message(STATUS "using git commit hash ${SHORT_HASH}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/version.cpp")
add_library(version STATIC "${CMAKE_CURRENT_BINARY_DIR}/version.cpp")

View file

@ -4,10 +4,10 @@ namespace oxen {
using namespace std::literals;
const std::array<uint16_t, 3> STORAGE_SERVER_VERSION = {@PROJECT_VERSION_MAJOR@, @PROJECT_VERSION_MINOR@, @PROJECT_VERSION_PATCH@};
const std::array<uint16_t, 3> STORAGE_SERVER_VERSION = {@oxenss_VERSION_MAJOR@, @oxenss_VERSION_MINOR@, @oxenss_VERSION_PATCH@};
const std::string_view STORAGE_SERVER_VERSION_STRING = "@PROJECT_VERSION@"sv;
const std::string_view STORAGE_SERVER_GIT_HASH_STRING = "@SHORT_HASH@"sv;
const std::string_view STORAGE_SERVER_VERSION_INFO = "Oxen Storage Server v@PROJECT_VERSION@ (@SHORT_HASH@)"sv;
const std::string_view STORAGE_SERVER_VERSION_STRING = "@oxenss_VERSION@"sv;
const std::string_view STORAGE_SERVER_GIT_HASH_STRING = "@VERSIONTAG@"sv;
const std::string_view STORAGE_SERVER_VERSION_INFO = "Oxen Storage Server v@oxenss_VERSION@ (@VERSIONTAG@)"sv;
}