mirror of https://github.com/cutefishos/calamares
CMake: simplify development-version string
- merge the (not-installed) date-stamp and git-version files into ExtendedVersion, turn things into functions - drop support for CVS (wut?) - don't mention the branch, in git-versioning, because the hash is enough to find whatever - don't need external program to find date, use `string(TIMESTAMP...)`main
parent
2be9aece3f
commit
38ec357bd5
@ -1,31 +0,0 @@
|
||||
# === This file is part of Calamares - <https://calamares.io> ===
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
###
|
||||
#
|
||||
# Find today's date, for versioning purposes.
|
||||
find_program(DATE_EXECUTABLE NAMES date)
|
||||
mark_as_advanced(DATE_EXECUTABLE)
|
||||
|
||||
if(DATE_EXECUTABLE)
|
||||
execute_process(
|
||||
COMMAND ${DATE_EXECUTABLE} +%Y
|
||||
OUTPUT_VARIABLE CMAKE_DATESTAMP_YEAR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${DATE_EXECUTABLE} +%m
|
||||
OUTPUT_VARIABLE CMAKE_DATESTAMP_MONTH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${DATE_EXECUTABLE} +%d
|
||||
OUTPUT_VARIABLE CMAKE_DATESTAMP_DAY
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
@ -1,52 +0,0 @@
|
||||
# === This file is part of Calamares - <https://calamares.io> ===
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
###
|
||||
#
|
||||
# Try to identify the current development source version.
|
||||
set(CMAKE_VERSION_SOURCE "")
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD)
|
||||
find_program(GIT_EXECUTABLE NAMES git git.cmd)
|
||||
mark_as_advanced(GIT_EXECUTABLE)
|
||||
if(GIT_EXECUTABLE)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=7 HEAD
|
||||
OUTPUT_VARIABLE head
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
if(head)
|
||||
set(branch "")
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} name-rev HEAD
|
||||
OUTPUT_VARIABLE branch
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
string(REGEX REPLACE "HEAD " "" branch "${branch}")
|
||||
set(CMAKE_VERSION_SOURCE "git-${branch}-${head}")
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
|
||||
OUTPUT_VARIABLE dirty
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
if(dirty)
|
||||
set(CMAKE_VERSION_SOURCE "${CMAKE_VERSION_SOURCE}-dirty")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
elseif(EXISTS ${CMAKE_SOURCE_DIR}/CVS/Repository)
|
||||
file(READ ${CMAKE_SOURCE_DIR}/CVS/Repository repo)
|
||||
set(branch "")
|
||||
if("${repo}" MATCHES "\\.git/")
|
||||
string(REGEX REPLACE ".*\\.git/([^\r\n]*).*" "-\\1" branch "${repo}")
|
||||
endif()
|
||||
set(CMAKE_VERSION_SOURCE "cvs${branch}")
|
||||
endif()
|
@ -0,0 +1,75 @@
|
||||
# === This file is part of Calamares - <https://calamares.io> ===
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
|
||||
# SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
###
|
||||
#
|
||||
# This file defines one function for extending a VERSION-like value
|
||||
# with date and git information (if desired).
|
||||
#
|
||||
# - extend_version( version-string short_only short_var long_var )
|
||||
# Calling this function will copy *version-string* (which would typically
|
||||
# be a semver-style string, like "3.2.40") into the variable *short_var*.
|
||||
# If *short_only* is true, then:
|
||||
# - the short version is also copied into the variable *long_var*,
|
||||
# If *short_only* is false, then:
|
||||
# - the *version-string* plus date and git information, is copied
|
||||
# into the varialbe *long_var*, in the format {version}-{date}-{hash}
|
||||
#
|
||||
#
|
||||
|
||||
function( get_git_version_info out_var )
|
||||
set(CMAKE_VERSION_SOURCE "")
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD)
|
||||
find_program(GIT_EXECUTABLE NAMES git git.cmd)
|
||||
mark_as_advanced(GIT_EXECUTABLE)
|
||||
if(GIT_EXECUTABLE)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=8 HEAD
|
||||
OUTPUT_VARIABLE head
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
if(head)
|
||||
set(CMAKE_VERSION_SOURCE "${head}")
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
|
||||
OUTPUT_VARIABLE dirty
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
if(dirty)
|
||||
set(CMAKE_VERSION_SOURCE "${CMAKE_VERSION_SOURCE}-dirty")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
set( ${out_var} "${CMAKE_VERSION_SOURCE}" PARENT_SCOPE )
|
||||
endfunction()
|
||||
|
||||
function( extend_version version short_only short_var long_var )
|
||||
set( ${short_var} "${version}" PARENT_SCOPE )
|
||||
set( _v "${version}" )
|
||||
if ( NOT short_only )
|
||||
# Additional info for non-release builds which want "long" version info
|
||||
# with date and git information (commit, dirty status). That is used only
|
||||
# by CalamaresVersionX.h, which is included by consumers that need a full
|
||||
# version number with all that information; normal consumers can include
|
||||
# CalamaresVersion.h with more stable numbers.
|
||||
string( TIMESTAMP CALAMARES_VERSION_DATE "%Y%m%d" )
|
||||
if( CALAMARES_VERSION_DATE GREATER 0 )
|
||||
set( _v ${_v}.${CALAMARES_VERSION_DATE} )
|
||||
endif()
|
||||
get_git_version_info( _gitv )
|
||||
if( _gitv )
|
||||
set( _v "${_v}-${_gitv}" )
|
||||
endif()
|
||||
endif()
|
||||
set( ${long_var} "${_v}" PARENT_SCOPE )
|
||||
endfunction()
|
Loading…
Reference in New Issue