From f55bf48baddeb99aff395e9fd94b7ac82ba8388d Mon Sep 17 00:00:00 2001 From: xiphon Date: Wed, 1 Jul 2020 01:29:09 +0000 Subject: cmake: fix git tag + commit detection and version.js generation --- cmake/GenVersionGui.cmake | 64 ------------------------------------------ cmake/GitGetVersionTag.cmake | 67 ++++++++++++++++++++++++++++++++++++++++++++ cmake/VersionGui.cmake | 23 +++++++-------- 3 files changed, 77 insertions(+), 77 deletions(-) delete mode 100644 cmake/GenVersionGui.cmake create mode 100644 cmake/GitGetVersionTag.cmake (limited to 'cmake') diff --git a/cmake/GenVersionGui.cmake b/cmake/GenVersionGui.cmake deleted file mode 100644 index 0ec2e8ba..00000000 --- a/cmake/GenVersionGui.cmake +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (c) 2014-2019, The Monero 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=9 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") - configure_file("src/version.js.in" "${TO}") -else() - string(SUBSTRING ${COMMIT} 0 9 COMMIT) - 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() - message(STATUS "The most recent tag was at ${TAGGEDCOMMIT}") - - # Check if we're building that tagged commit or a different one - if(COMMIT STREQUAL TAGGEDCOMMIT) - message(STATUS "You are building a tagged release") - set(VERSIONTAG "release") - else() - message(STATUS "You are ahead of or behind a tagged release") - set(VERSIONTAG "${COMMIT}") - endif() - endif() - - configure_file("src/version.js.in" "${TO}") -endif() diff --git a/cmake/GitGetVersionTag.cmake b/cmake/GitGetVersionTag.cmake new file mode 100644 index 00000000..b66b1886 --- /dev/null +++ b/cmake/GitGetVersionTag.cmake @@ -0,0 +1,67 @@ +# Copyright (c) 2014-2019, The Monero 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 + +function (git_get_version_tag git directory result_var) + execute_process(COMMAND "${git}" rev-parse --short HEAD + WORKING_DIRECTORY ${directory} + OUTPUT_VARIABLE COMMIT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT COMMIT) + message(WARNING "${directory}: cannot determine current commit. Make sure that you are building from a Git working tree") + set(${result_var} "unknown" PARENT_SCOPE) + return() + endif() + + execute_process(COMMAND "${git}" describe --tags --exact-match + WORKING_DIRECTORY ${directory} + OUTPUT_VARIABLE TAG + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(TAG) + message(STATUS "${directory}: building tagged release ${TAG}-${COMMIT}") + set(${result_var} "${TAG}-${COMMIT}" PARENT_SCOPE) + return() + endif() + + execute_process(COMMAND "${git}" describe --tags --long + WORKING_DIRECTORY ${directory} + OUTPUT_VARIABLE MOST_RECENT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(MOST_RECENT_TAG) + message(STATUS "${directory}: ahead of or behind a tagged release, building ${MOST_RECENT_TAG}") + set(${result_var} "${MOST_RECENT_TAG}" PARENT_SCOPE) + return() + endif() + + message(STATUS "${directory}: building ${COMMIT} commit") + set(${result_var} "${COMMIT}" PARENT_SCOPE) +endfunction() diff --git a/cmake/VersionGui.cmake b/cmake/VersionGui.cmake index b248cba0..fd0eddae 100644 --- a/cmake/VersionGui.cmake +++ b/cmake/VersionGui.cmake @@ -26,27 +26,24 @@ # 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. -function (write_static_version_header hash) - set(VERSIONTAG "${hash}") - configure_file("${CMAKE_SOURCE_DIR}/version.js.in" "${CMAKE_SOURCE_DIR}/version.js") +function (write_static_version_header VERSION_TAG_GUI VERSION_TAG_CORE) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/version.js.in" "${CMAKE_CURRENT_SOURCE_DIR}/version.js") endfunction () find_package(Git QUIET) if ("$Format:$" STREQUAL "") # We're in a tarball; use hard-coded variables. - write_static_version_header("release") + write_static_version_header("release" "release") elseif (GIT_FOUND OR Git_FOUND) message(STATUS "Found Git: ${GIT_EXECUTABLE}") - add_custom_command( - OUTPUT "${CMAKE_SOURCE_DIR}/version.js" - COMMAND "${CMAKE_COMMAND}" - "-D" "GIT=${GIT_EXECUTABLE}" - "-D" "TO=${CMAKE_SOURCE_DIR}/version.js" - "-P" "cmake/GenVersionGui.cmake" - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") + + include(GitGetVersionTag) + git_get_version_tag(${GIT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} VERSION_TAG_GUI) + git_get_version_tag(${GIT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/monero VERSION_TAG_CORE) + write_static_version_header(${VERSION_TAG_GUI} ${VERSION_TAG_CORE}) else() message(STATUS "WARNING: Git was not found!") - write_static_version_header("unknown") + write_static_version_header("unknown" "unknown") endif () add_custom_target(genversiongui ALL - DEPENDS "${CMAKE_SOURCE_DIR}/version.js") + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/version.js") -- cgit v1.2.3