diff --git a/CMakeLists.txt b/CMakeLists.txt index c0a800750..ab30845e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,13 +40,23 @@ # TODO:3.3: Require CMake 3.12 cmake_minimum_required( VERSION 3.3 FATAL_ERROR ) + +set( CALAMARES_VERSION 3.2.40 ) +set( CALAMARES_RELEASE_MODE OFF ) + +if ( CMAKE_SCRIPT_MODE_FILE ) + include( ${CMAKE_CURRENT_LIST_DIR}/CMakeModules/ExtendedVersion.cmake ) + set( CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} ) + extend_version( ${CALAMARES_VERSION} OFF _vshort _vlong ) + message( "${_vlong}" ) + return() +endif() + project( CALAMARES - VERSION 3.2.40 + VERSION ${CALAMARES_VERSION} LANGUAGES C CXX ) -set( CALAMARES_VERSION_RC 1 ) # Set to 0 during release cycle, 1 during development - ### OPTIONS # option( INSTALL_CONFIG "Install configuration files" OFF ) @@ -180,6 +190,7 @@ include( FeatureSummary ) # Calamares Modules include( CMakeColors ) +include( ExtendedVersion ) ### C++ SETUP # @@ -494,41 +505,21 @@ add_feature_info( ExampleDistro ${mksquashfs_FOUND} "Create example-distro targe ### CALAMARES PROPER # -set( CALAMARES_VERSION ${CALAMARES_VERSION_MAJOR}.${CALAMARES_VERSION_MINOR}.${CALAMARES_VERSION_PATCH} ) -# In rare cases we have hotfix-releases with a tweak -if( CALAMARES_VERSION_TWEAK ) - set( CALAMARES_VERSION "${CALAMARES_VERSION}.${CALAMARES_VERSION_TWEAK}" ) -endif() -set( CALAMARES_VERSION_SHORT "${CALAMARES_VERSION}" ) -if( CALAMARES_VERSION_RC ) - set( CALAMARES_VERSION ${CALAMARES_VERSION}rc${CALAMARES_VERSION_RC} ) -endif() +# +extend_version( "${CALAMARES_VERSION}" ${CALAMARES_RELEASE_MODE} CALAMARES_VERSION_SHORT CALAMARES_VERSION ) -# Additional info for non-release builds. The "extended" version information -# with date and git information (commit, dirty status) 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. -if( NOT BUILD_RELEASE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/" ) - include( CMakeDateStamp ) - set( CALAMARES_VERSION_DATE "${CMAKE_DATESTAMP_YEAR}${CMAKE_DATESTAMP_MONTH}${CMAKE_DATESTAMP_DAY}" ) - if( CALAMARES_VERSION_DATE GREATER 0 ) - set( CALAMARES_VERSION ${CALAMARES_VERSION}.${CALAMARES_VERSION_DATE} ) - endif() - - include( CMakeVersionSource ) - if( CMAKE_VERSION_SOURCE ) - set( CALAMARES_VERSION ${CALAMARES_VERSION}-${CMAKE_VERSION_SOURCE} ) - endif() -endif() - -# Special target for not-RC (e.g. might-be-release) builds. -# This is used by the release script to get the version. -if ( CALAMARES_VERSION_RC EQUAL 0 ) +# Special target for displaying the version. In RC (might-be-release) +# builds, use the short version (3.x.y), otherwise show the long version. +if ( CALAMARES_RELEASE_MODE ) add_custom_target(show-version ${CMAKE_COMMAND} -E echo CALAMARES_VERSION=${CALAMARES_VERSION_SHORT} USES_TERMINAL ) +else() + add_custom_target(show-version + ${CMAKE_COMMAND} -E echo CALAMARES_VERSION=${CALAMARES_VERSION} + USES_TERMINAL + ) endif() # enforce using constBegin, constEnd for const-iterators diff --git a/CMakeModules/CMakeDateStamp.cmake b/CMakeModules/CMakeDateStamp.cmake deleted file mode 100644 index 15482100f..000000000 --- a/CMakeModules/CMakeDateStamp.cmake +++ /dev/null @@ -1,31 +0,0 @@ -# === This file is part of Calamares - === -# -# SPDX-FileCopyrightText: 2014 Teo Mrnjavac -# 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() diff --git a/CMakeModules/CMakeVersionSource.cmake b/CMakeModules/CMakeVersionSource.cmake deleted file mode 100644 index 295fffa5d..000000000 --- a/CMakeModules/CMakeVersionSource.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# === This file is part of Calamares - === -# -# SPDX-FileCopyrightText: 2014 Teo Mrnjavac -# 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() diff --git a/CMakeModules/ExtendedVersion.cmake b/CMakeModules/ExtendedVersion.cmake new file mode 100644 index 000000000..b737dd2e2 --- /dev/null +++ b/CMakeModules/ExtendedVersion.cmake @@ -0,0 +1,75 @@ +# === This file is part of Calamares - === +# +# SPDX-FileCopyrightText: 2014 Teo Mrnjavac +# SPDX-FileCopyrightText: 2021 Adriaan de Groot +# 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() diff --git a/ci/RELEASE.md b/ci/RELEASE.md index 628f5c773..5289da5af 100644 --- a/ci/RELEASE.md +++ b/ci/RELEASE.md @@ -27,7 +27,8 @@ ## (1) Preparation -* Drop the RC variable to 0 in `CMakeLists.txt`, *CALAMARES_VERSION_RC*. +* Double-check the *CALAMARES_VERSION* value at the top of `CMakeLists.txt`. +* Set *CALAMARES_RELEASE_MODE* to `ON` in `CMakeLists.txt`. * Edit `CHANGES` and set the date of the release. * Commit both. This is usually done with commit-message *Changes: pre-release housekeeping*. @@ -78,8 +79,8 @@ Follow the instructions printed by the release script. ## (4) Post-Release -* Bump the version number in `CMakeLists.txt` in the `project()` command. -* Set *CALAMARES_VERSION_RC* back to 1. +* Bump the version number in `CMakeLists.txt` in *CALAMARES_VERSION*. +* Set *CALAMARES_RELEASE_MODE* back to `OFF`. * Add a placeholder entry for the next release in `CHANGES` with date text *not released yet*. * Commit and push that, usually with the message