From: Matthew Fernandez Date: Mon, 8 Nov 2021 00:13:38 +0000 (-0800) Subject: fix: use 'find_program' instead of 'find_package' to locate Git in CMake build X-Git-Tag: 2.50.0~36^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1997723433f3330df73ceca454c5f9259eef863f;p=graphviz fix: use 'find_program' instead of 'find_package' to locate Git in CMake build The Cygwin CMake CI task recently started stalling after the “Found FLEX” step. Reordering CMake steps to debug this revealed that it was definitely the `find_package(Git REQUIRED)` step that was stalling. I have not been able to root cause what is going on, but some educated guesses: 1. A CMake FindGit.cmake bug? This could certainly cause the described behavior, but I cannot find anything online to corroborate this and cannot see anything in the upstream history of this file¹ that looks like a fix for something like this. 2. Installing a version of CMake via Choco and then running it via Cygwin causes some bad Windows/UNIX interaction? Perhaps, but I cannot find any corroborating evidence for this either. Also, I cannot guess why such a thing would _only_ cause problems in FindGit.cmake. 3. FindGit.cmake is picking up a Visual Studio shim for Git that responds in a way that confuses the `find_package` check? I found vague hints about a shim like this online, but I still cannot explain why this would cause a stall. A work around for this is to use the less nuanced `find_program`. This has no negative impact on the CMake setup because (1) all we are attempting to detect is the `git` binary itself and (2) the CMake files never call `git` directly anyway; we are performing this detection to avoid gen_version.py failing cryptically. Note that it is not possible to use `REQUIRED` in this `find_program` directive because this was only added in CMake 3.18 and we currently only require CMake 3.1. This also re-enables the Cygwin CMake CI task now that it no longer stalls. Fixes #2145. ¹ https://github.com/Kitware/CMake/commits/master/Modules/FindGit.cmake --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 819145e28..7b67af9a4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -840,32 +840,31 @@ windows-mingw64-cmake-build: except: - tags -# FIXME: https://gitlab.com/graphviz/graphviz/-/issues/2145 -# windows-cygwin-cmake-build: -# stage: build -# needs: [] -# script: -# # change line endings from crlf to lf -# - git rm --cached -r . -# - git -c core.autocrlf=false reset --hard -# - choco config set cacheLocation choco-cache -# - choco install --yes --no-progress cygwin -# - $Env:build_system = "cmake" -# - C:\tools\cygwin\bin\bash -l -c 'cd $CI_PROJECT_DIR && ci/cygwin-build.sh' -# artifacts: -# when: always -# expire_in: 1 week -# paths: -# - Packages/*/*/*.zip -# - Packages/*/*/*.bz2 -# cache: -# key: windows-cygwin-cmake-build -# paths: -# - choco-cache -# tags: -# - windows -# except: -# - tags +windows-cygwin-cmake-build: + stage: build + needs: [] + script: + # change line endings from crlf to lf + - git rm --cached -r . + - git -c core.autocrlf=false reset --hard + - choco config set cacheLocation choco-cache + - choco install --yes --no-progress cygwin + - $Env:build_system = "cmake" + - C:\tools\cygwin\bin\bash -l -c 'cd $CI_PROJECT_DIR && ci/cygwin-build.sh' + artifacts: + when: always + expire_in: 1 week + paths: + - Packages/*/*/*.zip + - Packages/*/*/*.bz2 + cache: + key: windows-cygwin-cmake-build + paths: + - choco-cache + tags: + - windows + except: + - tags meta-data: stage: test diff --git a/CMakeLists.txt b/CMakeLists.txt index 98eaaa7c5..ad63eb3ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,10 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") find_package(AWK REQUIRED) find_package(BISON 3.0 REQUIRED) find_package(FLEX REQUIRED) -find_package(Git REQUIRED) +find_program(GIT git) +if(NOT GIT) + message(FATAL_ERROR "git not found") +endif(NOT GIT) find_program(GZIP gzip) # ================== Convenient values for CMake configuration =================