5 Commits

Author SHA1 Message Date
Michael Fabian 'Xaymar' Dirks 2494a2b6c8 Version: 1.3.0 2022-07-22 13:50:59 +02:00
Michael Fabian 'Xaymar' Dirks e240967c27 code: Add support for requiring PATCH and TWEAK components
These will be set to 0 if required instead of leaving them blank.
2022-07-22 13:50:54 +02:00
Michael Fabian 'Xaymar' Dirks db601c04d3 Version 1.2.2 2022-07-05 22:23:47 +02:00
Michael Fabian 'Xaymar' Dirks e5b1376772 code: Fix MODIFY and GENERATE command behavior
These problems were discovered by users.
2022-07-05 22:22:58 +02:00
Michael Fabian 'Xaymar' Dirks 2f60608e3c tests: Modify tests to include hidden problems
The previous test cases didn't actually cover the majority of use cases at all.
2022-07-05 21:18:29 +02:00
4 changed files with 100 additions and 79 deletions
+2 -2
View File
@@ -20,8 +20,8 @@
project = 'version'
copyright = "2022, Michael Fabian Dirks"
author = "Michael Fabian 'Xaymar' Dirks"
version = "1.2.1"
release = "1.2.1"
version = "1.3.0"
release = "1.3.0"
# -- General configuration ---------------------------------------------------
+6 -6
View File
@@ -8,9 +8,9 @@ Synopsis
.. parsed-literal::
version(`PARSE`_ <out-var> <string>)
version(`PARSE`_ <out-var> [REQUIRE [PATCH|TWEAK][;...]] <string>)
version(`GENERATE`_ <out-var> [COMPRESS] [MAJOR <major>] [MINOR <minor>] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>])
version(`MODIFY`_ <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>])
version(`MODIFY`_ <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>] [REQUIRE [PATCH|TWEAK][;...]])
version(`COMPARE`_ <out-var> <a> <b>)
@@ -27,9 +27,9 @@ Parsing
.. code-block:: cmake
version(PARSE <out-var> <string>)
version(PARSE <out-var> [REQUIRE [PATCH|TWEAK][;...]] <string>)
Attempts to parse the version in ``<string>`` and stores the individual compoents into ``<out-var>_<component>``. If a component is not present in the given version, it will be set to a false constant. If an error occurred, ``<out-var>_ERROR`` will contain the error message otherwise it will be a false constant. The ``PRERELEASE`` and ``BUILD`` components support the dot-separation specifier and will be turned into a list if they are encountered.
Attempts to parse the version in ``<string>`` and stores the individual compoents into ``<out-var>_<component>``. If a component is not present in the given version, it will be set to a false constant. If an error occurred, ``<out-var>_ERROR`` will contain the error message otherwise it will be a false constant. The ``PRERELEASE`` and ``BUILD`` components support the dot-separation specifier and will be turned into a list if they are encountered. The optional ``REQUIRE`` allows forcing the components ``PATCH`` and ``TWEAK`` to always be defined.
Generating
^^^^^^^^^^
@@ -49,9 +49,9 @@ Modifying
.. code-block:: cmake
version(MODIFY <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>])
version(MODIFY <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>] [REQUIRE [PATCH|TWEAK][;...]])
Modifies the version provided in ``<string>`` with the components provided. The components ``<major>``, ``<minor>``, ``<patch>`` and ``<tweak>`` may have a prefix of ``+`` or ``-`` to add and subtract the value, or no prefix to replace. The result of this operation will be stored as a string in ``<out-var>``. If a component did not exist in the original, it will be added to the version as a replace operation. If an error occurred, ``<out-var>_ERROR`` will contain the error message otherwise it will be a false constant.
Modifies the version provided in ``<string>`` with the components provided. The components ``<major>``, ``<minor>``, ``<patch>`` and ``<tweak>`` may have a prefix of ``+`` or ``-`` to add and subtract the value, or no prefix to replace. The result of this operation will be stored as a string in ``<out-var>``. If a component did not exist in the original, it will be added to the version as a replace operation. If an error occurred, ``<out-var>_ERROR`` will contain the error message otherwise it will be a false constant. The optional ``REQUIRE`` allows forcing the components ``PATCH`` and ``TWEAK`` to always be defined.
Comparing
^^^^^^^^^
+22 -17
View File
@@ -63,23 +63,23 @@ test_parse("0.0.0+.0" FAIL)
# Modifying
message(STATUS "\n\n===== Modifying =====")
# - Valid Cases
test_modify("1.0" "0.0" MAJOR 1)
test_modify("1.0" "0.0" MAJOR "+1")
test_modify("1.0" "2.0" MAJOR "-1")
test_modify("0.2" "0.0" MINOR 2)
test_modify("0.2" "0.0" MINOR "+2")
test_modify("0.2" "0.3" MINOR "-1")
test_modify("0.0.3" "0.0" PATCH 3)
test_modify("0.0.3" "0.0.2" PATCH "+1")
test_modify("0.0.3" "0.0.4" PATCH "-1")
test_modify("0.0.0.4" "0.0" TWEAK 4)
test_modify("0.0.0.4" "0.0.0.3" TWEAK "+1")
test_modify("0.0.0.4" "0.0.0.5" TWEAK "-1")
test_modify("0.0-5" "0.0" COMPRESS PRERELEASE 5)
test_modify("0.0a5" "0.0" COMPRESS PRERELEASE a5)
test_modify("0.0+6" "0.0" COMPRESS BUILD 6)
test_modify("0.0-5+6" "0.0" COMPRESS PRERELEASE 5 BUILD 6)
test_modify("0.0a5+6" "0.0" COMPRESS PRERELEASE a5 BUILD 6)
test_modify("1.2" "0.2" MAJOR 1)
test_modify("1.2" "0.2" MAJOR "+1")
test_modify("1.2" "2.2" MAJOR "-1")
test_modify("1.2" "1.0" MINOR 2)
test_modify("1.2" "1.0" MINOR "+2")
test_modify("1.2" "1.3" MINOR "-1")
test_modify("1.2.3" "1.2" PATCH 3)
test_modify("1.2.3" "1.2.2" PATCH "+1")
test_modify("1.2.3" "1.2.4" PATCH "-1")
test_modify("1.2.0.4" "1.2" TWEAK 4)
test_modify("1.2.3.4" "1.2.3.3" TWEAK "+1")
test_modify("1.2.3.4" "1.2.3.5" TWEAK "-1")
test_modify("1.2-5" "1.2" COMPRESS PRERELEASE 5)
test_modify("1.2a5" "1.2" COMPRESS PRERELEASE a5)
test_modify("1.2+6" "1.2" COMPRESS BUILD 6)
test_modify("1.2-5+6" "1.2" COMPRESS PRERELEASE 5 BUILD 6)
test_modify("1.2a5+6" "1.2" COMPRESS PRERELEASE a5 BUILD 6)
# - Invalid Cases
test_modify("0.0" "0.0" FAIL MAJOR -1)
test_modify("0.0" "0.0" FAIL MINOR -1)
@@ -111,3 +111,8 @@ test_compare("0.0-5" "+PRERELEASE" "0.0")
test_compare("0.0" "-PRERELEASE" "0.0-5")
test_compare("0.0+6" "+BUILD" "0.0")
test_compare("0.0" "-BUILD" "0.0+6")
# Discovered failure cases
message(STATUS "\n\n===== User-generated Cases =====")
test_generate("1.2.3.4+gABCDEF01" MAJOR 1 MINOR 2 PATCH 3 TWEAK 4 BUILD "gABCDEF01")
test_modify("0.2.0.4+gABCDEF01" "0.2.0" TWEAK "4" BUILD "gABCDEF01")
+67 -51
View File
@@ -98,12 +98,19 @@ function(version)
string(TOUPPER "${ARGV0}" ARGV0)
if(ARGV0 STREQUAL "PARSE")
cmake_parse_arguments(
PARSE_ARGV 2
_992ae727
""
""
"REQUIRE"
)
# <major> "." <minor> ["." <patch> ["." <tweak>]]
# <major> "." <minor> ["." <patch> ["." <tweak>]] [["-"] <pre-release>] ["+" <build>]
# One regex to rule them all...
if(NOT (ARGV2 MATCHES [[^([0-9]+)\.([0-9]+)(\.[0-9]+|)(\.[0-9]+|)(-?[a-zA-Z0-9]+[a-zA-Z0-9\.\-]*|)(\+[a-zA-Z0-9]+[a-zA-Z0-9\.\-]*|)$]]))
set(${OUT_VAR}_ERROR "Version format not supported: '${ARGV2}'" PARENT_SCOPE)
if(NOT (_992ae727_UNPARSED_ARGUMENTS MATCHES [[^([0-9]+)\.([0-9]+)(\.[0-9]+|)(\.[0-9]+|)(-?[a-zA-Z0-9]+[a-zA-Z0-9\.\-]*|)(\+[a-zA-Z0-9]+[a-zA-Z0-9\.\-]*|)$]]))
set(${OUT_VAR}_ERROR "Version format not supported: '${_992ae727_UNPARSED_ARGUMENTS}'" PARENT_SCOPE)
return()
endif()
@@ -112,21 +119,29 @@ function(version)
# {2} = Minor
set(${OUT_VAR}_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
# {3} = Patch
if(CMAKE_MATCH_3)
if((DEFINED CMAKE_MATCH_3) AND (NOT "${CMAKE_MATCH_3}" STREQUAL ""))
string(SUBSTRING "${CMAKE_MATCH_3}" 1 -1 _TMP)
set(${OUT_VAR}_PATCH "${_TMP}" PARENT_SCOPE)
else()
if("PATCH" IN_LIST _992ae727_REQUIRE)
set(${OUT_VAR}_PATCH "0" PARENT_SCOPE)
else()
set(${OUT_VAR}_PATCH "" PARENT_SCOPE)
endif()
endif()
# {4} = Tweak
if(CMAKE_MATCH_4)
if((DEFINED CMAKE_MATCH_4) AND (NOT "${CMAKE_MATCH_4}" STREQUAL ""))
string(SUBSTRING "${CMAKE_MATCH_4}" 1 -1 _TMP)
set(${OUT_VAR}_TWEAK "${_TMP}" PARENT_SCOPE)
else()
if("TWEAK" IN_LIST _992ae727_REQUIRE)
set(${OUT_VAR}_TWEAK "0" PARENT_SCOPE)
else()
set(${OUT_VAR}_TWEAK "" PARENT_SCOPE)
endif()
endif()
# {5} = PreRelease
if(CMAKE_MATCH_5)
if((DEFINED CMAKE_MATCH_5) AND (NOT "${CMAKE_MATCH_5}" STREQUAL ""))
string(REPLACE "." ";" CMAKE_MATCH_5 "${CMAKE_MATCH_5}") # Handle dot separation as list.
string(SUBSTRING "${CMAKE_MATCH_5}" 0 1 _TMP)
if(_TMP STREQUAL "-")
@@ -139,7 +154,7 @@ function(version)
set(${OUT_VAR}_PRERELEASE "" PARENT_SCOPE)
endif()
# {6} = Build
if(CMAKE_MATCH_6)
if((DEFINED CMAKE_MATCH_6) AND (NOT "${CMAKE_MATCH_6}" STREQUAL ""))
string(REPLACE "." ";" CMAKE_MATCH_6 "${CMAKE_MATCH_6}") # Handle dot separation as list.
string(SUBSTRING "${CMAKE_MATCH_6}" 1 -1 CMAKE_MATCH_6)
set(${OUT_VAR}_BUILD "${CMAKE_MATCH_6}" PARENT_SCOPE)
@@ -165,9 +180,9 @@ function(version)
)
# Do we have the major component, and is it valid?
if(_32070faa_MAJOR)
if(NOT "${_32070faa_MAJOR}" STREQUAL "")
string(STRIP "${_32070faa_MAJOR}" _32070faa_MAJOR)
if(_32070faa_MAJOR STREQUAL "")
if("${_32070faa_MAJOR}" STREQUAL "")
set(_32070faa_MAJOR 0)
elseif(NOT (_32070faa_MAJOR MATCHES [[^[0-9]+$]]))
set(${OUT_VAR}_ERROR "MAJOR component must be a numeric identifier, but is: '${_32070faa_MAJOR}'" PARENT_SCOPE)
@@ -179,9 +194,9 @@ function(version)
set(_feeb1eff "${_feeb1eff}${_32070faa_MAJOR}")
# Do we have the minor component, and is it valid?
if(_32070faa_MINOR)
if(NOT "${_32070faa_MINOR}" STREQUAL "")
string(STRIP "${_32070faa_MINOR}" _32070faa_MINOR)
if(_32070faa_MINOR STREQUAL "")
if("${_32070faa_MINOR}" STREQUAL "")
set(_32070faa_MINOR 0)
elseif(NOT (_32070faa_MINOR MATCHES [[^[0-9]+$]]))
set(${OUT_VAR}_ERROR "MINOR component must be a numeric identifier, but is: '${_32070faa_MINOR}'" PARENT_SCOPE)
@@ -193,10 +208,10 @@ function(version)
set(_feeb1eff "${_feeb1eff}.${_32070faa_MINOR}")
# Do we have the patch component, and is it valid?
if(_32070faa_PATCH)
if(NOT "${_32070faa_PATCH}" STREQUAL "")
string(STRIP "${_32070faa_PATCH}" _32070faa_PATCH)
if(_32070faa_PATCH STREQUAL "")
unset(_32070faa_PATCH)
if("${_32070faa_PATCH}" STREQUAL "")
set(_32070faa_PATCH "")
elseif(_32070faa_PATCH MATCHES [[^[0-9]+$]])
set(_feeb1eff "${_feeb1eff}.${_32070faa_PATCH}")
else()
@@ -206,12 +221,13 @@ function(version)
endif()
# Do we have the tweak component, and is it valid?
if(_32070faa_TWEAK)
if(NOT "${_32070faa_TWEAK}" STREQUAL "")
string(STRIP "${_32070faa_TWEAK}" _32070faa_TWEAK)
if(_32070faa_TWEAK STREQUAL "")
unset(_32070faa_TWEAK)
if("${_32070faa_TWEAK}" STREQUAL "")
set(_32070faa_TWEAK "")
elseif(_32070faa_TWEAK MATCHES [[^[0-9]+$]])
if(NOT _32070faa_PATCH)
if("${_32070faa_PATCH}" STREQUAL "")
# Patch did not exist, so it is zero.
set(_feeb1eff "${_feeb1eff}.0")
endif()
set(_feeb1eff "${_feeb1eff}.${_32070faa_TWEAK}")
@@ -222,13 +238,13 @@ function(version)
endif()
# Do we have the pre-release component, and is it valid?
if(_32070faa_PRERELEASE)
if(NOT "${_32070faa_PRERELEASE}" STREQUAL "")
string(STRIP "${_32070faa_PRERELEASE}" _32070faa_PRERELEASE)
list(JOIN _32070faa_PRERELEASE "." _32070faa_PRERELEASE)
if(_32070faa_PRERELEASE STREQUAL "")
unset(_32070faa_PRERELEASE)
if("${_32070faa_PRERELEASE}" STREQUAL "")
set(_32070faa_PRERELEASE "")
elseif(_32070faa_PRERELEASE MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]*$]])
if(_32070faa_COMPRESS AND (_32070faa_PRERELEASE MATCHES [[[a-zA-Z]+[a-zA-Z0-9\-\.]*$]]))
if(_32070faa_COMPRESS AND (_32070faa_PRERELEASE MATCHES [[^[a-zA-Z]+[a-zA-Z0-9\-\.]*$]]))
set(_feeb1eff "${_feeb1eff}${_32070faa_PRERELEASE}")
else()
set(_feeb1eff "${_feeb1eff}-${_32070faa_PRERELEASE}")
@@ -240,10 +256,10 @@ function(version)
endif()
# Do we have the build component, and is it valid?
if(_32070faa_BUILD)
string(STRIP "${_32070faa_BUILD}" _32070faa_PRERELEASE)
if(NOT "${_32070faa_BUILD}" STREQUAL "")
string(STRIP "${_32070faa_BUILD}" _32070faa_BUILD)
list(JOIN _32070faa_BUILD "." _32070faa_BUILD)
if(_32070faa_BUILD STREQUAL "")
if("${_32070faa_BUILD}" STREQUAL "")
unset(_32070faa_BUILD)
elseif(_32070faa_BUILD MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]*$]])
set(_feeb1eff "${_feeb1eff}+${_32070faa_BUILD}")
@@ -269,17 +285,17 @@ function(version)
_fe7bcddd
"COMPRESS"
"MAJOR;MINOR;PATCH;TWEAK;PRERELEASE;BUILD"
""
"REQUIRE"
)
# Helpers
macro(modify_version_number)
if(${ARGV1})
if(${ARGV1} MATCHES "^(\\+|\\-)([0-9]+)$")
if(${ARGV0})
math(EXPR ${ARGV0} "${${ARGV0}} ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}")
else()
if(NOT ("${${ARGV1}}" STREQUAL ""))
if("${${ARGV1}}" MATCHES "^(\\+|\\-)([0-9]+)$")
if("${${ARGV0}}" STREQUAL "")
math(EXPR ${ARGV0} "0 ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}")
else()
math(EXPR ${ARGV0} "${${ARGV0}} ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}")
endif()
else()
set(${ARGV0} "${${ARGV1}}")
@@ -296,7 +312,7 @@ function(version)
set(_df8abcce_PRERELEASE "")
set(_df8abcce_BUILD "")
set(_df8abcce_ERROR "")
version(PARSE _df8abcce "${ARGV2}")
version(PARSE _df8abcce "${ARGV2}" REQUIRE "${_df8abcce_REQUIRE}")
if(_df8abcce_ERROR)
set(${OUT_VAR}_ERROR ${_df8abcce_ERROR} PARENT_SCOPE)
return()
@@ -309,31 +325,31 @@ function(version)
modify_version_number(_df8abcce_TWEAK _fe7bcddd_TWEAK)
# Replace other components if defined.
if(_fe7bcddd_PRERELEASE)
if(NOT "${_fe7bcddd_PRERELEASE}" STREQUAL "")
set(_df8abcce_PRERELEASE "${_fe7bcddd_PRERELEASE}")
endif()
if(_fe7bcddd_BUILD)
if(NOT "${_fe7bcddd_BUILD}" STREQUAL "")
set(_df8abcce_BUILD "${_fe7bcddd_BUILD}")
endif()
# Generate a new version.
set(_fe7bcddd_GEN "")
if(_df8abcce_MAJOR AND (NOT _df8abcce_MAJOR STREQUAL ""))
if(NOT "${_df8abcce_MAJOR}" STREQUAL "")
set(_fe7bcddd_GEN "${_fe7bcddd_GEN} MAJOR \"${_df8abcce_MAJOR}\"")
endif()
if(_df8abcce_MINOR AND (NOT _df8abcce_MINOR STREQUAL ""))
if(NOT "${_df8abcce_MINOR}" STREQUAL "")
set(_fe7bcddd_GEN "${_fe7bcddd_GEN} MINOR \"${_df8abcce_MINOR}\"")
endif()
if(_df8abcce_PATCH AND (NOT _df8abcce_PATCH STREQUAL ""))
if(NOT "${_df8abcce_PATCH}" STREQUAL "")
set(_fe7bcddd_GEN "${_fe7bcddd_GEN} PATCH \"${_df8abcce_PATCH}\"")
endif()
if(_df8abcce_TWEAK AND (NOT _df8abcce_TWEAK STREQUAL ""))
if(NOT "${_df8abcce_TWEAK}" STREQUAL "")
set(_fe7bcddd_GEN "${_fe7bcddd_GEN} TWEAK \"${_df8abcce_TWEAK}\"")
endif()
if(_df8abcce_PRERELEASE AND (NOT _df8abcce_PRERELEASE STREQUAL ""))
if(NOT "${_df8abcce_PRERELEASE}" STREQUAL "")
set(_fe7bcddd_GEN "${_fe7bcddd_GEN} PRERELEASE \"${_df8abcce_PRERELEASE}\"")
endif()
if(_df8abcce_BUILD AND (NOT _df8abcce_BUILD STREQUAL ""))
if(NOT "${_df8abcce_BUILD}" STREQUAL "")
set(_fe7bcddd_GEN "${_fe7bcddd_GEN} BUILD \"${_df8abcce_BUILD}\"")
endif()
if(_fe7bcddd_COMPRESS)
@@ -403,11 +419,11 @@ function(version)
elseif(_00fdeadb_PATCH LESS _ca75feel_PATCH)
set(${OUT_VAR} "<PATCH" PARENT_SCOPE)
return()
elseif((_00fdeadb_PATCH STREQUAL "") OR (_ca75feel_PATCH STREQUAL ""))
if(_00fdeadb_PATCH)
elseif(("${_00fdeadb_PATCH}" STREQUAL "") OR ("${_ca75feel_PATCH}" STREQUAL ""))
if(NOT "${_00fdeadb_PATCH}" STREQUAL "")
set(${OUT_VAR} "+PATCH" PARENT_SCOPE)
return()
elseif(_ca75feel_PATCH)
elseif(NOT "${_ca75feel_PATCH}" STREQUAL "")
set(${OUT_VAR} "-PATCH" PARENT_SCOPE)
return()
endif()
@@ -420,22 +436,22 @@ function(version)
elseif(_00fdeadb_TWEAK LESS _ca75feel_TWEAK)
set(${OUT_VAR} "<TWEAK" PARENT_SCOPE)
return()
elseif((_00fdeadb_TWEAK STREQUAL "") OR (_ca75feel_TWEAK STREQUAL ""))
if(_00fdeadb_TWEAK)
elseif(("${_00fdeadb_TWEAK}" STREQUAL "") OR ("${_ca75feel_TWEAK}" STREQUAL ""))
if(NOT "${_00fdeadb_TWEAK}" STREQUAL "")
set(${OUT_VAR} "+TWEAK" PARENT_SCOPE)
return()
elseif(_ca75feel_TWEAK)
elseif(NOT "${_ca75feel_TWEAK}" STREQUAL "")
set(${OUT_VAR} "-TWEAK" PARENT_SCOPE)
return()
endif()
endif()
# Pre-Release
if((_00fdeadb_PRERELEASE STREQUAL "") OR (_ca75feel_PRERELEASE STREQUAL ""))
if(_00fdeadb_PRERELEASE)
if(("${_00fdeadb_PRERELEASE}" STREQUAL "") OR ("${_ca75feel_PRERELEASE}" STREQUAL ""))
if(NOT "${_00fdeadb_PRERELEASE}" STREQUAL "")
set(${OUT_VAR} "+PRERELEASE" PARENT_SCOPE)
return()
elseif(_ca75feel_PRERELEASE)
elseif(NOT "${_ca75feel_PRERELEASE}" STREQUAL "")
set(${OUT_VAR} "-PRERELEASE" PARENT_SCOPE)
return()
endif()
@@ -445,11 +461,11 @@ function(version)
endif()
# Build
if((_00fdeadb_BUILD STREQUAL "") OR (_ca75feel_BUILD STREQUAL ""))
if(_00fdeadb_BUILD)
if(("${_00fdeadb_BUILD}" STREQUAL "") OR ("${_ca75feel_BUILD}" STREQUAL ""))
if(NOT "${_00fdeadb_BUILD}" STREQUAL "")
set(${OUT_VAR} "+BUILD" PARENT_SCOPE)
return()
elseif(_ca75feel_BUILD)
elseif(NOT "${_ca75feel_BUILD}" STREQUAL "")
set(${OUT_VAR} "-BUILD" PARENT_SCOPE)
return()
endif()