[Cmake-commits] CMake branch, next, updated. v3.1.0-rc1-211-gd62a616

Rolf Eike Beer eike at sf-mail.de
Wed Oct 29 16:48:21 EDT 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  d62a6161aeca493054c4c42bab90897d41f505b1 (commit)
       via  cdf2df2b38ba6744bc1fb00f451af286bf25c60b (commit)
       via  667560c88a707ca7eeaad129e253cce371beed1d (commit)
      from  9bbd6210e900046e2dd8f80b6380afa2bca25cd8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d62a6161aeca493054c4c42bab90897d41f505b1
commit d62a6161aeca493054c4c42bab90897d41f505b1
Merge: 9bbd621 cdf2df2
Author:     Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Wed Oct 29 16:48:20 2014 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Wed Oct 29 16:48:20 2014 -0400

    Merge topic 'VERSION_no_sscanf' into next
    
    cdf2df2b cmSystemTools: reimplement verson comparison without sscanf()
    667560c8 extend the testing for version comparison


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cdf2df2b38ba6744bc1fb00f451af286bf25c60b
commit cdf2df2b38ba6744bc1fb00f451af286bf25c60b
Author:     Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Sat Oct 25 19:27:40 2014 +0200
Commit:     Rolf Eike Beer <eike at sf-mail.de>
CommitDate: Wed Oct 29 21:28:33 2014 +0100

    cmSystemTools: reimplement verson comparison without sscanf()
    
    This now has the advantage that it works with version strings with any number
    of components.

diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 6b7009a..3abbc37 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -2634,29 +2634,37 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
 bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op,
                                    const char* lhss, const char* rhss)
 {
-  // Parse out up to 8 components.
-  unsigned int lhs[8] = {0,0,0,0,0,0,0,0};
-  unsigned int rhs[8] = {0,0,0,0,0,0,0,0};
-  sscanf(lhss, "%u.%u.%u.%u.%u.%u.%u.%u",
-         &lhs[0], &lhs[1], &lhs[2], &lhs[3],
-         &lhs[4], &lhs[5], &lhs[6], &lhs[7]);
-  sscanf(rhss, "%u.%u.%u.%u.%u.%u.%u.%u",
-         &rhs[0], &rhs[1], &rhs[2], &rhs[3],
-         &rhs[4], &rhs[5], &rhs[6], &rhs[7]);
+  char *endl = const_cast<char *>(lhss);
+  char *endr = const_cast<char *>(rhss);
+  unsigned long lhs, rhs;
 
-  // Do component-wise comparison.
-  for(unsigned int i=0; i < 8; ++i)
+  while (((*endl >= '0') && (*endl <= '9')) ||
+         ((*endr >= '0') && (*endr <= '9')))
     {
-    if(lhs[i] < rhs[i])
+    // Do component-wise comparison.
+    lhs = strtoul(endl, &endl, 10);
+    rhs = strtoul(endr, &endr, 10);
+
+    if(lhs < rhs)
       {
       // lhs < rhs, so true if operation is LESS
       return op == cmSystemTools::OP_LESS;
       }
-    else if(lhs[i] > rhs[i])
+    else if(lhs > rhs)
       {
       // lhs > rhs, so true if operation is GREATER
       return op == cmSystemTools::OP_GREATER;
       }
+
+    if (*endr == '.')
+      {
+      endr++;
+      }
+
+    if (*endl == '.')
+      {
+      endl++;
+      }
     }
   // lhs == rhs, so true if operation is EQUAL
   return op == cmSystemTools::OP_EQUAL;
diff --git a/Tests/CMakeTests/VersionTest.cmake.in b/Tests/CMakeTests/VersionTest.cmake.in
index bd54de5..4e946ab 100644
--- a/Tests/CMakeTests/VersionTest.cmake.in
+++ b/Tests/CMakeTests/VersionTest.cmake.in
@@ -10,7 +10,9 @@ endif()
 
 set(EQUALV "1 1")
 list(APPEND EQUALV "1.0 1")
+list(APPEND EQUALV "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0 1")
 list(APPEND EQUALV "1.2.3.4.5.6.7 1.2.3.4.5.6.7")
+list(APPEND EQUALV "1.2.3.4.5.6.7.8.9 1.2.3.4.5.6.7.8.9")
 
 foreach(v IN LISTS EQUALV)
   string(REGEX MATCH "(.*) (.*)" _dummy "${v}")

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=667560c88a707ca7eeaad129e253cce371beed1d
commit 667560c88a707ca7eeaad129e253cce371beed1d
Author:     Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Sun Oct 26 17:54:26 2014 +0100
Commit:     Rolf Eike Beer <eike at sf-mail.de>
CommitDate: Wed Oct 29 21:28:33 2014 +0100

    extend the testing for version comparison
    
    This now checks also the negative outcome of the comparision operation, and
    adds a bunch more different cases.

diff --git a/Tests/CMakeTests/VersionTest.cmake.in b/Tests/CMakeTests/VersionTest.cmake.in
index 9e31cb4..bd54de5 100644
--- a/Tests/CMakeTests/VersionTest.cmake.in
+++ b/Tests/CMakeTests/VersionTest.cmake.in
@@ -8,9 +8,83 @@ else()
   message("CMAKE_VERSION=[${CMAKE_VERSION}] is not less than [${min_ver}]")
 endif()
 
-set(v 1.2.3.4.5.6.7)
-if("${v}.8" VERSION_LESS "${v}.9")
-  message(STATUS "${v}.8 is less than ${v}.9")
-else()
-  message(FATAL_ERROR "${v}.8 is not less than ${v}.9?")
-endif()
+set(EQUALV "1 1")
+list(APPEND EQUALV "1.0 1")
+list(APPEND EQUALV "1.2.3.4.5.6.7 1.2.3.4.5.6.7")
+
+foreach(v IN LISTS EQUALV)
+  string(REGEX MATCH "(.*) (.*)" _dummy "${v}")
+  # modify any of the operands to see the negative check also works
+  if("${CMAKE_MATCH_1}.2" VERSION_EQUAL CMAKE_MATCH_2)
+    message(FATAL_ERROR "${CMAKE_MATCH_1}.2 is equal ${CMAKE_MATCH_2}?")
+  else()
+    message(STATUS "${CMAKE_MATCH_1}.2 is not equal ${CMAKE_MATCH_2}")
+  endif()
+
+  if(CMAKE_MATCH_1 VERSION_EQUAL "${CMAKE_MATCH_2}.2")
+    message(FATAL_ERROR "${CMAKE_MATCH_1} is equal ${CMAKE_MATCH_2}.2?")
+  else()
+    message(STATUS "${CMAKE_MATCH_1} is not equal ${CMAKE_MATCH_2}.2")
+  endif()
+endforeach()
+
+# test the negative outcomes first, due to the implementation the positive
+# allow some additional strings to pass that would not fail for the negative
+# tests
+
+list(APPEND EQUALV "1a 1")
+list(APPEND EQUALV "1.1a 1.1")
+list(APPEND EQUALV "1.0a 1")
+list(APPEND EQUALV "1a 1.0")
+
+foreach(v IN LISTS EQUALV)
+  # check equal versions
+  string(REGEX MATCH "(.*) (.*)" _dummy "${v}")
+  if(CMAKE_MATCH_1 VERSION_EQUAL CMAKE_MATCH_2)
+    message(STATUS "${CMAKE_MATCH_1} is equal ${CMAKE_MATCH_2}")
+  else()
+    message(FATAL_ERROR "${CMAKE_MATCH_1} is not equal ${CMAKE_MATCH_2}?")
+  endif()
+
+  # still equal, but inverted order of operands
+  string(REGEX MATCH "(.*) (.*)" _dummy "${v}")
+  if(CMAKE_MATCH_2 VERSION_EQUAL CMAKE_MATCH_1)
+    message(STATUS "${CMAKE_MATCH_2} is equal ${CMAKE_MATCH_1}")
+  else()
+    message(FATAL_ERROR "${CMAKE_MATCH_2} is not equal ${CMAKE_MATCH_1}?")
+  endif()
+endforeach()
+
+set(LESSV "1.2.3.4.5.6.7.8 1.2.3.4.5.6.7.9")
+list(APPEND LESSV "1.2.3.4.5.6.7 1.2.3.4.5.6.7.9")
+list(APPEND LESSV "1 1.0.0.1")
+foreach(v IN LISTS LESSV)
+  string(REGEX MATCH "(.*) (.*)" _dummy "${v}")
+  # check less
+  if(CMAKE_MATCH_1 VERSION_LESS CMAKE_MATCH_2)
+    message(STATUS "${CMAKE_MATCH_1} is less than ${CMAKE_MATCH_2}")
+  else()
+    message(FATAL_ERROR "${CMAKE_MATCH_1} is not less than ${CMAKE_MATCH_2}?")
+  endif()
+
+  # check greater
+  if(CMAKE_MATCH_2 VERSION_GREATER CMAKE_MATCH_1)
+    message(STATUS "${CMAKE_MATCH_2} is greater than ${CMAKE_MATCH_1}")
+  else()
+    message(FATAL_ERROR "${CMAKE_MATCH_2} is not greater than ${CMAKE_MATCH_1}?")
+  endif()
+
+  # check less negative case
+  if(NOT CMAKE_MATCH_2 VERSION_LESS CMAKE_MATCH_1)
+    message(STATUS "${CMAKE_MATCH_2} is not less than ${CMAKE_MATCH_1}")
+  else()
+    message(FATAL_ERROR "${CMAKE_MATCH_2} is less than ${CMAKE_MATCH_1}?")
+  endif()
+
+  # check greater negative case
+  if(NOT CMAKE_MATCH_1 VERSION_GREATER CMAKE_MATCH_2)
+    message(STATUS "${CMAKE_MATCH_1} is not greater than ${CMAKE_MATCH_2}")
+  else()
+    message(FATAL_ERROR "${CMAKE_MATCH_1} is greater than ${CMAKE_MATCH_2}?")
+  endif()
+endforeach()

-----------------------------------------------------------------------

Summary of changes:
 Source/cmSystemTools.cxx              |   34 ++++++++-----
 Tests/CMakeTests/VersionTest.cmake.in |   88 ++++++++++++++++++++++++++++++---
 2 files changed, 103 insertions(+), 19 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list