Jelajahi Sumber

cmake: Provide a clear error on version check fail

Currently, when git describe fails to get a git tag for the OBS Version,
a non-fatal message is printed, and the generator is left to continue,
usually ending up with a more cryptic error message down the line.

Instead, print the git output together with a short description of what
actually happened, and exit fatally so the problematic line of code is
clear. An added advantage is that the git output is printed in red
instead of (say) white on color-enabled terminals.
Aleks Todorov 1 tahun lalu
induk
melakukan
80ad63a6da
2 mengubah file dengan 10 tambahan dan 0 penghapusan
  1. 5 0
      cmake/Modules/VersionConfig.cmake
  2. 5 0
      cmake/common/versionconfig.cmake

+ 5 - 0
cmake/Modules/VersionConfig.cmake

@@ -17,10 +17,15 @@ if(NOT DEFINED OBS_VERSION_OVERRIDE)
     execute_process(
       COMMAND git describe --always --tags --dirty=-modified
       OUTPUT_VARIABLE _OBS_VERSION
+      ERROR_VARIABLE _GIT_DESCRIBE_ERR
       WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
       RESULT_VARIABLE _OBS_VERSION_RESULT
       OUTPUT_STRIP_TRAILING_WHITESPACE)
 
+    if(_GIT_DESCRIBE_ERR)
+      message(FATAL_ERROR "Could not fetch OBS version tag from git.\n" ${_GIT_DESCRIBE_ERR})
+    endif()
+
     if(_OBS_VERSION_RESULT EQUAL 0)
       if(${_OBS_VERSION} MATCHES "rc[0-9]+$")
         set(RELEASE_CANDIDATE ${_OBS_VERSION})

+ 5 - 0
cmake/common/versionconfig.cmake

@@ -10,10 +10,15 @@ if(NOT DEFINED OBS_VERSION_OVERRIDE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git
   execute_process(
     COMMAND git describe --always --tags --dirty=-modified
     OUTPUT_VARIABLE _obs_version
+    ERROR_VARIABLE _git_describe_err
     WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
     RESULT_VARIABLE _obs_version_result
     OUTPUT_STRIP_TRAILING_WHITESPACE)
 
+  if(_git_describe_err)
+    message(FATAL_ERROR "Could not fetch OBS version tag from git.\n" ${_git_describe_err})
+  endif()
+
   if(_obs_version_result EQUAL 0)
     string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1;\\2;\\3" _obs_version_canonical ${_obs_version})
   endif()