Merge pull request #1 from Xaymar/dot-separation

code, docs, tests: Add support for dot-separation
This commit was merged in pull request #1.
This commit is contained in:
Xaymar
2022-07-04 22:46:03 +02:00
committed by GitHub
4 changed files with 25 additions and 17 deletions
+5 -6
View File
@@ -18,9 +18,7 @@ The following version constructs are currently supported:
.. code-block:: .. code-block::
<major> "." <minor> ["." <patch> ["." <tweak>]] <major> "." <minor> ["." <patch> ["." <tweak>]] [["-"] <pre-release> ["." <pre-release> [...]]] ["+" <build> ["." <build> [...]]]
<major> "." <minor> ["." <patch> ["." <tweak>]] [["-"] <pre-release>] ["+" <build>]
Parsing Parsing
^^^^^^^ ^^^^^^^
@@ -31,7 +29,7 @@ Parsing
version(PARSE <out-var> <string>) version(PARSE <out-var> <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 undefined. If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message. 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 undefined. If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message. The ``PRERELEASE`` and ``BUILD`` components support the dot-separation specifier and will be turned into a list if they are encountered.
Generating Generating
^^^^^^^^^^ ^^^^^^^^^^
@@ -42,7 +40,7 @@ Generating
version(GENERATE <out-var> [COMPRESS] [MAJOR <major>] [MINOR <minor>] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>]) version(GENERATE <out-var> [COMPRESS] [MAJOR <major>] [MINOR <minor>] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>])
Generates a version from the components provided and stores the result in ``<out-var>``. The components ``<major>`` and ``<minor>`` will default to ``0`` if not provided. If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message. Generates a version from the components provided and stores the result in ``<out-var>``. The components ``<major>`` and ``<minor>`` will default to ``0`` if not provided. If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message. The ``PRERELEASE`` and ``BUILD`` components support the dot-separation specifier and will be converted from a list if encountered.
Modifying Modifying
^^^^^^^^^ ^^^^^^^^^
@@ -71,6 +69,7 @@ Compares the version ``<a>`` against ``<b>`` and stores the result in ``<out-var
- If a component is numerical and the value is larger in ``<a>``, ``<out-var>`` will contain the componenent name prefixed by ``>``. - If a component is numerical and the value is larger in ``<a>``, ``<out-var>`` will contain the componenent name prefixed by ``>``.
- If a component is numerical and the value is larger in ``<b>``, ``<out-var>`` will contain the componenent name prefixed by ``<``. - If a component is numerical and the value is larger in ``<b>``, ``<out-var>`` will contain the componenent name prefixed by ``<``.
- If a component is alphanumerical and the value is different in either, ``<out-var>`` will contain the component name with no prefix. - If a component is alphanumerical and the value is different in either, ``<out-var>`` will contain the component name with no prefix.
- In all other cases, ``<out-var>`` will be empty.
- If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message, and ``<out-var>`` will be undefined. - If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message, and ``<out-var>`` will be undefined.
- In all other cases, ``<out-var>`` will be empty.
There is no special handling for dot-separated ``PRERELEASE`` and ``BUILD`` component. They will be treated as if they were a string, as special handling for these is up to the application.
+5
View File
@@ -15,7 +15,9 @@ test_generate("0.0.3" PATCH 3)
test_generate("0.0.0.4" TWEAK 4) test_generate("0.0.0.4" TWEAK 4)
test_generate("0.0-5" COMPRESS PRERELEASE 5) test_generate("0.0-5" COMPRESS PRERELEASE 5)
test_generate("0.0a5" COMPRESS PRERELEASE a5) test_generate("0.0a5" COMPRESS PRERELEASE a5)
test_generate("0.0a5.5" COMPRESS PRERELEASE "a5;5")
test_generate("0.0+6" BUILD 6) test_generate("0.0+6" BUILD 6)
test_generate("0.0+6.8" BUILD "6;8")
# - Invalid Cases # - Invalid Cases
test_generate("-1.0.0" FAIL MAJOR "-1") test_generate("-1.0.0" FAIL MAJOR "-1")
test_generate("0.-1.0" FAIL MINOR "-1") test_generate("0.-1.0" FAIL MINOR "-1")
@@ -47,6 +49,9 @@ test_parse("1.2.3.4-5+6" MAJOR 1 MINOR 2 PATCH 3 TWEAK 4 PRERELEASE 5 BUILD 6)
test_parse("1.2a5+6" MAJOR 1 MINOR 2 PRERELEASE a5 BUILD 6) test_parse("1.2a5+6" MAJOR 1 MINOR 2 PRERELEASE a5 BUILD 6)
test_parse("1.2.3a5+6" MAJOR 1 MINOR 2 PATCH 3 PRERELEASE a5 BUILD 6) test_parse("1.2.3a5+6" MAJOR 1 MINOR 2 PATCH 3 PRERELEASE a5 BUILD 6)
test_parse("1.2.3.4a5+6" MAJOR 1 MINOR 2 PATCH 3 TWEAK 4 PRERELEASE a5 BUILD 6) test_parse("1.2.3.4a5+6" MAJOR 1 MINOR 2 PATCH 3 TWEAK 4 PRERELEASE a5 BUILD 6)
test_parse("1.2a5.b5+6.66" MAJOR 1 MINOR 2 PRERELEASE "a5;b5" BUILD "6;66")
test_parse("1.2.3a5.b5+6.66" MAJOR 1 MINOR 2 PATCH 3 PRERELEASE "a5;b5" BUILD "6;66")
test_parse("1.2.3.4a5.b5+6.66" MAJOR 1 MINOR 2 PATCH 3 TWEAK 4 PRERELEASE "a5;b5" BUILD "6;66")
# - Invalid Cases # - Invalid Cases
test_parse("" FAIL) test_parse("" FAIL)
test_parse("cmake" FAIL) test_parse("cmake" FAIL)
+6 -6
View File
@@ -66,7 +66,7 @@ function(test_parse)
set(MESSAGE "MAJOR component missing during parse.") set(MESSAGE "MAJOR component missing during parse.")
set(FAILED ON) set(FAILED ON)
elseif(NOT (_TEST_MAJOR STREQUAL _ARGS_MAJOR)) elseif(NOT (_TEST_MAJOR STREQUAL _ARGS_MAJOR))
set(MESSAGE "MAJOR component mismatch.") set(MESSAGE "MAJOR component mismatch: '${_TEST_MAJOR}' != '${_ARGS_MAJOR}'")
set(FAILED ON) set(FAILED ON)
endif() endif()
endif() endif()
@@ -76,7 +76,7 @@ function(test_parse)
set(MESSAGE "MINOR component missing during parse.") set(MESSAGE "MINOR component missing during parse.")
set(FAILED ON) set(FAILED ON)
elseif(NOT (_TEST_MINOR STREQUAL _ARGS_MINOR)) elseif(NOT (_TEST_MINOR STREQUAL _ARGS_MINOR))
set(MESSAGE "MINOR component mismatch.") set(MESSAGE "MINOR component mismatch: '${_TEST_MINOR}' != '${_ARGS_MINOR}'")
set(FAILED ON) set(FAILED ON)
endif() endif()
endif() endif()
@@ -86,7 +86,7 @@ function(test_parse)
set(MESSAGE "PATCH component missing during parse.") set(MESSAGE "PATCH component missing during parse.")
set(FAILED ON) set(FAILED ON)
elseif(NOT (_TEST_PATCH STREQUAL _ARGS_PATCH)) elseif(NOT (_TEST_PATCH STREQUAL _ARGS_PATCH))
set(MESSAGE "PATCH component mismatch.") set(MESSAGE "PATCH component mismatch: '${_TEST_PATCH}' != '${_ARGS_PATCH}'")
set(FAILED ON) set(FAILED ON)
endif() endif()
endif() endif()
@@ -96,7 +96,7 @@ function(test_parse)
set(MESSAGE "TWEAK component missing during parse.") set(MESSAGE "TWEAK component missing during parse.")
set(FAILED ON) set(FAILED ON)
elseif(NOT (_TEST_TWEAK STREQUAL _ARGS_TWEAK)) elseif(NOT (_TEST_TWEAK STREQUAL _ARGS_TWEAK))
set(MESSAGE "TWEAK component mismatch.") set(MESSAGE "TWEAK component mismatch: '${_TEST_TWEAK}' != '${_ARGS_TWEAK}'")
set(FAILED ON) set(FAILED ON)
endif() endif()
endif() endif()
@@ -106,7 +106,7 @@ function(test_parse)
set(MESSAGE "PRERELEASE component missing during parse.") set(MESSAGE "PRERELEASE component missing during parse.")
set(FAILED ON) set(FAILED ON)
elseif(NOT (_TEST_PRERELEASE STREQUAL _ARGS_PRERELEASE)) elseif(NOT (_TEST_PRERELEASE STREQUAL _ARGS_PRERELEASE))
set(MESSAGE "PRERELEASE component mismatch.") set(MESSAGE "PRERELEASE component mismatch: '${_TEST_PRERELEASE}' != '${_ARGS_PRERELEASE}'")
set(FAILED ON) set(FAILED ON)
endif() endif()
endif() endif()
@@ -116,7 +116,7 @@ function(test_parse)
set(MESSAGE "BUILD component missing during parse.") set(MESSAGE "BUILD component missing during parse.")
set(FAILED ON) set(FAILED ON)
elseif(NOT (_TEST_BUILD STREQUAL _ARGS_BUILD)) elseif(NOT (_TEST_BUILD STREQUAL _ARGS_BUILD))
set(MESSAGE "BUILD component mismatch.") set(MESSAGE "BUILD component mismatch: '${_TEST_BUILD}' != '${_ARGS_BUILD}'")
set(FAILED ON) set(FAILED ON)
endif() endif()
endif() endif()
+9 -5
View File
@@ -125,10 +125,11 @@ function(version)
endif() endif()
# {5} = PreRelease # {5} = PreRelease
if(CMAKE_MATCH_5) if(CMAKE_MATCH_5)
string(REPLACE "." ";" CMAKE_MATCH_5 "${CMAKE_MATCH_5}") # Handle dot separation as list.
string(SUBSTRING "${CMAKE_MATCH_5}" 0 1 _TMP) string(SUBSTRING "${CMAKE_MATCH_5}" 0 1 _TMP)
if(_TMP STREQUAL "-") if(_TMP STREQUAL "-")
string(SUBSTRING "${CMAKE_MATCH_5}" 1 -1 _TMP) string(SUBSTRING "${CMAKE_MATCH_5}" 1 -1 CMAKE_MATCH_5)
set(${OUT_VAR}_PRERELEASE "${_TMP}" PARENT_SCOPE) set(${OUT_VAR}_PRERELEASE "${CMAKE_MATCH_5}" PARENT_SCOPE)
else() else()
set(${OUT_VAR}_PRERELEASE "${CMAKE_MATCH_5}" PARENT_SCOPE) set(${OUT_VAR}_PRERELEASE "${CMAKE_MATCH_5}" PARENT_SCOPE)
endif() endif()
@@ -137,8 +138,9 @@ function(version)
endif() endif()
# {6} = Build # {6} = Build
if(CMAKE_MATCH_6) if(CMAKE_MATCH_6)
string(SUBSTRING "${CMAKE_MATCH_6}" 1 -1 _TMP) string(REPLACE "." ";" CMAKE_MATCH_6 "${CMAKE_MATCH_6}") # Handle dot separation as list.
set(${OUT_VAR}_BUILD "${_TMP}" PARENT_SCOPE) string(SUBSTRING "${CMAKE_MATCH_6}" 1 -1 CMAKE_MATCH_6)
set(${OUT_VAR}_BUILD "${CMAKE_MATCH_6}" PARENT_SCOPE)
else() else()
unset(${OUT_VAR}_BUILD PARENT_SCOPE) unset(${OUT_VAR}_BUILD PARENT_SCOPE)
endif() endif()
@@ -211,10 +213,11 @@ function(version)
# Do we have the pre-release component, and is it valid? # Do we have the pre-release component, and is it valid?
if(DEFINED _ARGS_PRERELEASE) if(DEFINED _ARGS_PRERELEASE)
string(STRIP "${_ARGS_PRERELEASE}" _ARGS_PRERELEASE) string(STRIP "${_ARGS_PRERELEASE}" _ARGS_PRERELEASE)
list(JOIN _ARGS_PRERELEASE "." _ARGS_PRERELEASE)
if(_ARGS_PRERELEASE STREQUAL "") if(_ARGS_PRERELEASE STREQUAL "")
unset(_ARGS_PRERELEASE) unset(_ARGS_PRERELEASE)
elseif(_ARGS_PRERELEASE MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]*$]]) elseif(_ARGS_PRERELEASE MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]*$]])
if(_ARGS_COMPRESS AND (_ARGS_PRERELEASE MATCHES [[[a-zA-Z]+[a-zA-Z0-9\\-\\.]*$]])) if(_ARGS_COMPRESS AND (_ARGS_PRERELEASE MATCHES [[[a-zA-Z]+[a-zA-Z0-9\-\.]*$]]))
set(_ "${_}${_ARGS_PRERELEASE}") set(_ "${_}${_ARGS_PRERELEASE}")
else() else()
set(_ "${_}-${_ARGS_PRERELEASE}") set(_ "${_}-${_ARGS_PRERELEASE}")
@@ -228,6 +231,7 @@ function(version)
# Do we have the build component, and is it valid? # Do we have the build component, and is it valid?
if(DEFINED _ARGS_BUILD) if(DEFINED _ARGS_BUILD)
string(STRIP "${_ARGS_BUILD}" _ARGS_PRERELEASE) string(STRIP "${_ARGS_BUILD}" _ARGS_PRERELEASE)
list(JOIN _ARGS_BUILD "." _ARGS_BUILD)
if(_ARGS_BUILD STREQUAL "") if(_ARGS_BUILD STREQUAL "")
unset(_ARGS_BUILD) unset(_ARGS_BUILD)
elseif(_ARGS_BUILD MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]*$]]) elseif(_ARGS_BUILD MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]*$]])