mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-11-16 15:58:11 +00:00
cmake: fix git tag + commit detection and version.js generation
This commit is contained in:
parent
e0faddf964
commit
f55bf48bad
3 changed files with 47 additions and 48 deletions
|
@ -28,37 +28,40 @@
|
|||
#
|
||||
# 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)
|
||||
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()
|
||||
|
||||
if(RET)
|
||||
# Something went wrong, set the version tag to -unknown
|
||||
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()
|
||||
|
||||
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}")
|
||||
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()
|
||||
|
||||
# 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()
|
||||
message(STATUS "${directory}: building ${COMMIT} commit")
|
||||
set(${result_var} "${COMMIT}" PARENT_SCOPE)
|
||||
endfunction()
|
|
@ -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")
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
var GUI_VERSION = "@VERSIONTAG@"
|
||||
var GUI_MONERO_VERSION = "@VERSIONTAG@"
|
||||
|
||||
var GUI_VERSION = "@VERSION_TAG_GUI@";
|
||||
var GUI_MONERO_VERSION = "@VERSION_TAG_CORE@";
|
||||
|
|
Loading…
Reference in a new issue