Skip to content

Commit

Permalink
Fix finding .git directory in CMake when z3 is a submodule of some ot…
Browse files Browse the repository at this point in the history
…her repository (#4850)

* Fix finding .git directory in CMake when z3 is a submodule of some other repository

* Check that z3 is a submodule
  • Loading branch information
SweetVishnya committed Dec 6, 2020
1 parent b0cecf7 commit 0c93c7a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmake/git_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,20 @@ function(add_git_dir_dependency GIT_DOT_FILE SUCCESS_VAR)
# Figure out where real git directory lives
set(GIT_COMMON_DIR_FILE "${GIT_WORKTREE_DIR}/commondir")
if (NOT EXISTS "${GIT_COMMON_DIR_FILE}")
message(FATAL_ERROR "Found git worktree dir but could not find \"${GIT_COMMON_DIR_FILE}\"")
get_filename_component(GIT_WORKTREE_PARENT "${GIT_WORKTREE_DIR}" DIRECTORY)
get_filename_component(GIT_WORKTREE_PARENT "${GIT_WORKTREE_PARENT}" NAME)
if ("${GIT_WORKTREE_PARENT}" STREQUAL "modules")
# Z3 is a git submodule
set(GIT_HEAD_FILE "${CMAKE_SOURCE_DIR}/${GIT_HEAD_FILE}")
set(GIT_DIR "${CMAKE_SOURCE_DIR}/${GIT_WORKTREE_DIR}")
else()
message(FATAL_ERROR "Found git worktree dir but could not find \"${GIT_COMMON_DIR_FILE}\"")
endif()
else()
file(READ "${GIT_COMMON_DIR_FILE}" GIT_COMMON_DIR_FILE_DATA LIMIT 512)
string(STRIP "${GIT_COMMON_DIR_FILE_DATA}" GIT_COMMON_DIR_FILE_DATA_STRIPPED)
get_filename_component(GIT_DIR "${GIT_WORKTREE_DIR}/${GIT_COMMON_DIR_FILE_DATA_STRIPPED}" ABSOLUTE)
endif()
file(READ "${GIT_COMMON_DIR_FILE}" GIT_COMMON_DIR_FILE_DATA LIMIT 512)
string(STRIP "${GIT_COMMON_DIR_FILE_DATA}" GIT_COMMON_DIR_FILE_DATA_STRIPPED)
get_filename_component(GIT_DIR "${GIT_WORKTREE_DIR}/${GIT_COMMON_DIR_FILE_DATA_STRIPPED}" ABSOLUTE)
if (NOT IS_DIRECTORY "${GIT_DIR}")
message(FATAL_ERROR "Failed to compute path to git directory from git worktree")
endif()
Expand Down

0 comments on commit 0c93c7a

Please sign in to comment.