]> granicus.if.org Git - esp-idf/commitdiff
cmake: fix build failure when git repo is initialized but no first commit
authorRenz Christian Bagaporo <renz@espressif.com>
Tue, 27 Aug 2019 01:24:17 +0000 (09:24 +0800)
committerRenz Christian Bagaporo <renz@espressif.com>
Wed, 28 Aug 2019 01:53:37 +0000 (09:53 +0800)
Closes https://github.com/espressif/esp-idf/issues/3920

tools/cmake/project.cmake
tools/cmake/third_party/GetGitRevisionDescription.cmake.in

index a8e28a12d8709678f8e42ed4cd64391630a82115..3deb0148899c06e93cf975ffccbaedc29fbdf2f9 100644 (file)
@@ -38,8 +38,9 @@ function(__project_get_revision var)
             if(PROJECT_VER_GIT)
                 set(PROJECT_VER ${PROJECT_VER_GIT})
             else()
-                message(STATUS "Project is not inside a git repository, \
-                        will not use 'git describe' to determine PROJECT_VER.")
+                message(STATUS "Project is not inside a git repository, or git repository has no commits;"
+                        " will not use 'git describe' to determine PROJECT_VER.")
+                set(PROJECT_VER 1)
             endif()
         endif()
     endif()
index 6d8b708efe56a66852752a7a30ec5c16b51cdc9e..0cf025b147c653f12d08f3e25948aa25d454637f 100644 (file)
@@ -24,10 +24,12 @@ if(HEAD_CONTENTS MATCHES "ref")
        if(EXISTS "@GIT_DIR@/${HEAD_REF}")
                configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
        else()
-               configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
-               file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
-               if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
-                       set(HEAD_HASH "${CMAKE_MATCH_1}")
+               if(EXISTS "@GIT_DIR@/packed-refs")
+                       configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
+                       file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
+                       if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
+                               set(HEAD_HASH "${CMAKE_MATCH_1}")
+                       endif()
                endif()
        endif()
 else()