From c5a9c3e6f7695b1a1e6e07e026c00811b8320c16 Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit Date: Sun, 22 Apr 2018 20:29:18 -0400 Subject: [PATCH] Fix issues with VTKmDetermineVersion. The code had 2 issues: 1. used obsolete 'output' if Git executable was missing. There was a possibility that output variable was never set and used some garbage value from parent scope. 2. version pattern matching was too liberal and would match absolute any long txt so long as it has some numbers in it that matched a typical version number. --- CMake/VTKmDetermineVersion.cmake | 46 +++++++++++++++++++------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/CMake/VTKmDetermineVersion.cmake b/CMake/VTKmDetermineVersion.cmake index 25cb7f906..3c2ea924f 100644 --- a/CMake/VTKmDetermineVersion.cmake +++ b/CMake/VTKmDetermineVersion.cmake @@ -41,21 +41,27 @@ function(determine_version source_dir git_command var_prefix) # information. Just return here to avoid the warning message at the end of # this function. return () - elseif (NOT VTKm_GIT_DESCRIBE) - if(EXISTS ${git_command} AND EXISTS ${source_dir}/.git) - execute_process( - COMMAND ${git_command} describe - WORKING_DIRECTORY ${source_dir} - RESULT_VARIABLE result - OUTPUT_VARIABLE output - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE) + elseif (NOT VTKm_GIT_DESCRIBE AND + EXISTS ${git_command} AND + EXISTS ${source_dir}/.git) + execute_process( + COMMAND ${git_command} describe + WORKING_DIRECTORY ${source_dir} + RESULT_VARIABLE result + OUTPUT_VARIABLE output + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + if (NOT result EQUAL 0) + # git describe failed (bad return code). + set(output "") endif() - else() - set(result 0) - set(output ${VTKm_GIT_DESCRIBE}) + else () + # note, output may be set to empty if VTKm_GIT_DESCRIBE is not defined. + set(output "${VTKm_GIT_DESCRIBE}") endif() + + unset(tmp_VERSION) extract_version_components("${output}" tmp) if(DEFINED tmp_VERSION) if (NOT "${tmp_VERSION}" STREQUAL "${${var_prefix}_VERSION}") @@ -74,14 +80,16 @@ endfunction() # Extracts components from a version string. See determine_version() for usage. function(extract_version_components version_string var_prefix) - string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)[-]*(.*)" + string(REGEX MATCH "^v?(([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*))$" version_matches "${version_string}") if(CMAKE_MATCH_0) - set(full ${CMAKE_MATCH_0}) - set(major ${CMAKE_MATCH_1}) - set(minor ${CMAKE_MATCH_2}) - set(patch ${CMAKE_MATCH_3}) - set(patch_extra ${CMAKE_MATCH_4}) + # note, we don't use CMAKE_MATCH_0 for `full` since it may or may not have + # the `v` prefix. + set(full ${CMAKE_MATCH_1}) + set(major ${CMAKE_MATCH_2}) + set(minor ${CMAKE_MATCH_3}) + set(patch ${CMAKE_MATCH_4}) + set(patch_extra ${CMAKE_MATCH_5}) set(${var_prefix}_VERSION "${major}.${minor}" PARENT_SCOPE) set(${var_prefix}_VERSION_MAJOR ${major} PARENT_SCOPE)