git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 02/10] cmake: do find Git for Windows' shell interpreter

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Sep 28, 2020, 19:39 UTC
Message-ID
<nycvar.QRO.7.76.6.2009281557390.50@tvgsbejvaqbjf.bet>
In-Reply-To
<20200928111748.4122-1-oystwa@gmail.com>
Hi Øystein,
On Mon, 28 Sep 2020, Øystein Walle wrote:
Show 17 quoted lines
> >  find_program(SH_EXE sh)
> >  if(NOT SH_EXE)
> > -	message(FATAL_ERROR "sh: shell interpreter was not found in your path, please install one."
> > -			"On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/")
> > +	set(SH_EXE "C:/Program Files/Git/bin/sh.exe")
> > +	if(NOT EXISTS ${SH_EXE})
> > +		message(FATAL_ERROR "sh: shell interpreter was not found in your path, please install one."
> > +				"On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/")
> > +	endif()
> >  endif()
>
> You can write the find_program() command more succinctly as:
>
> 	find_program(SH_EXE sh PATHS "C:/Program Files/Git/bin")
>
> PATHS is is a list of extra directories to search, which are usually hard-coded
> guesses[1]. This way we avoid an extra check and indentation level.
Thank you, I was not aware of this neat feature.
Show 11 quoted lines
> I found my Visual Studio installation already contains a sh.exe.  I think it
> ships with VS by default; I can't even find a way to remove it. It's located
> at:
>
> C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\usr\bin\sh.exe
>
> When I started writing this up I figured that could serve as an additional
> fallback. However, if I use that shell I have to add (...)/usr/bin to PATH as
> the various scripts need expr and sed among other things. I get the same result
> if I search "C:/Program Files/Git/usr/bin", but there is no equivalent
> (...)/bin in the Git included with VS for some reason.
Indeed. This is what I get in that case:

-- snip -- 1> [CMake] Generating GIT-VERSION-FILE 1> [CMake] C:/git-sdk-64/usr/src/vs2017-test/contrib/buildsystems/../../GIT-VERSION-GEN: line 24: sed: command not found 1> [CMake] C:/git-sdk-64/usr/src/vs2017-test/contrib/buildsystems/../../GIT-VERSION-GEN: line 29: expr: command not found 1> [CMake] GIT_VERSION = 1> [CMake] CMake Error at C:\git-sdk-64\usr\src\vs2017-test\contrib\buildsystems\CMakeLists.txt:79 (string): 1> [CMake] string sub-command FIND requires 3 or 4 parameters. 1> [CMake] 1> [CMake] 1> [CMake] CMake Error at C:\git-sdk-64\usr\src\vs2017-test\contrib\buildsystems\CMakeLists.txt:83 (string): 1> [CMake] string sub-command REGEX, mode MATCH needs at least 5 arguments total to 1> [CMake] command. 1> [CMake] 1> [CMake] 1> [CMake] CMake Error at C:\git-sdk-64\usr\src\vs2017-test\contrib\buildsystems\CMakeLists.txt:87 (project): 1> [CMake] VERSION ".0" format invalid. -- snap --

The explanation is pretty simple: you cannot just call into `sh.exe` via an absolute path and expect it to add its containing directory to the `PATH`. It does not, and the symptom is that neither `sed` nor `expr` are found.

One solution is to add it to the `PATH` manually, which is the original expectation in our `CMakeLists.txt` version.

Another solution is to point it to `C:\Program Files\Git\bin\sh.exe` which is not, in fact, a shell, but a small wrapper executable whose job it is to set up a couple environment variables (`PATH` being one of them) and then spawning the _actual_ `sh.exe`. The source code for that wrapper: https://github.com/git-for-windows/MINGW-packages/blob/main/mingw-w64-git/git-wrapper.c

As you figured out, it is _not_ enough to use `...\usr\bin\sh.exe` directly without adjusting the `PATH`.

Ciao, Dscho

Previous: Øystein WalleNext: Junio C Hamano via GitGitGadget
Message 36 of 70 in “CMake and Visual Studio”
  1. 00/10 CMake and Visual StudioJohannes Schindelin via GitGitGadget, Sep 25, 2020
  2. 01/10 cmake: ignore files generated by CMake as run in Visual StudioJohannes Schindelin via GitGitGadget, Sep 25, 2020
  3. 02/10 cmake: do find Git for Windows' shell interpreterJohannes Schindelin via GitGitGadget, Sep 25, 2020
  4. Sibi SiddharthanSep 25, 2020
  5. Johannes SchindelinSep 26, 2020
  6. Đoàn Trần Công DanhSep 27, 2020
  7. Johannes SchindelinSep 28, 2020
  8. Đoàn Trần Công DanhSep 29, 2020
  9. Johannes SchindelinSep 29, 2020
  10. 03/10 cmake: ensure that the `vcpkg` packages are found on WindowsJohannes Schindelin via GitGitGadget, Sep 25, 2020
  11. 07/10 cmake (Windows): complain when encountering an unknown compilerJohannes Schindelin via GitGitGadget, Sep 25, 2020
  12. Sibi SiddharthanSep 25, 2020
  13. Johannes SchindelinSep 26, 2020
  14. 06/10 cmake (Windows): let the `.dll` files are found when running the testsJohannes Schindelin via GitGitGadget, Sep 25, 2020
  15. Eric SunshineSep 25, 2020
  16. Johannes SchindelinSep 26, 2020
  17. 05/10 cmake: quote the path accurately when editing `test-lib.sh`Johannes Schindelin via GitGitGadget, Sep 25, 2020
  18. 08/10 cmake (Windows): initialize vcpkg/build dependencies automaticallyJohannes Schindelin via GitGitGadget, Sep 25, 2020
  19. Sibi SiddharthanSep 30, 2020
  20. Johannes SchindelinSep 30, 2020
  21. 09/10 cmake (Windows): recommend using Visual Studio's built-in CMake supportJohannes Schindelin via GitGitGadget, Sep 25, 2020
  22. Junio C HamanoSep 25, 2020
  23. Johannes SchindelinSep 26, 2020
  24. 10/10 hashmap_for_each_entry(): work around MSVC's run-time check failure #3Johannes Schindelin via GitGitGadget, Sep 25, 2020
  25. Junio C HamanoSep 25, 2020
  26. Junio C HamanoSep 26, 2020
  27. Johannes SchindelinSep 26, 2020
  28. 04/10 cmake: fall back to using `vcpkg`'s `msgfmt.exe` on WindowsJohannes Schindelin via GitGitGadget, Sep 25, 2020
  29. 00/10 CMake and Visual StudioJohannes Schindelin via GitGitGadget, Sep 26, 2020
  30. 01/10 cmake: ignore files generated by CMake as run in Visual StudioJohannes Schindelin via GitGitGadget, Sep 26, 2020
  31. 05/10 cmake: quote the path accurately when editing `test-lib.sh`Johannes Schindelin via GitGitGadget, Sep 26, 2020
  32. 03/10 cmake: ensure that the `vcpkg` packages are found on WindowsJohannes Schindelin via GitGitGadget, Sep 26, 2020
  33. 04/10 cmake: fall back to using `vcpkg`'s `msgfmt.exe` on WindowsJohannes Schindelin via GitGitGadget, Sep 26, 2020
  34. 02/10 cmake: do find Git for Windows' shell interpreterJohannes Schindelin via GitGitGadget, Sep 26, 2020
  35. Øystein WalleSep 28, 2020
  36. Johannes SchindelinSep 28, 2020
  37. 10/10 hashmap_for_each_entry(): workaround MSVC's runtime check failure #3Junio C Hamano via GitGitGadget, Sep 26, 2020
  38. 09/10 cmake (Windows): recommend using Visual Studio's built-in CMake supportJohannes Schindelin via GitGitGadget, Sep 26, 2020
  39. 08/10 cmake (Windows): initialize vcpkg/build dependencies automaticallyJohannes Schindelin via GitGitGadget, Sep 26, 2020
  40. 06/10 cmake (Windows): let the `.dll` files be found when running the testsJohannes Schindelin via GitGitGadget, Sep 26, 2020
  41. 07/10 cmake (Windows): complain when encountering an unknown compilerJohannes Schindelin via GitGitGadget, Sep 26, 2020
  42. 00/11 CMake and Visual StudioJohannes Schindelin via GitGitGadget, Sep 28, 2020
  43. 01/11 cmake: ignore files generated by CMake as run in Visual StudioJohannes Schindelin via GitGitGadget, Sep 28, 2020
  44. 03/11 cmake: ensure that the `vcpkg` packages are found on WindowsJohannes Schindelin via GitGitGadget, Sep 28, 2020
  45. 02/11 cmake: do find Git for Windows' shell interpreterJohannes Schindelin via GitGitGadget, Sep 28, 2020
  46. 05/11 cmake: quote the path accurately when editing `test-lib.sh`Johannes Schindelin via GitGitGadget, Sep 28, 2020
  47. 04/11 cmake: fall back to using `vcpkg`'s `msgfmt.exe` on WindowsJohannes Schindelin via GitGitGadget, Sep 28, 2020
  48. 09/11 cmake (Windows): recommend using Visual Studio's built-in CMake supportJohannes Schindelin via GitGitGadget, Sep 28, 2020
  49. 10/11 hashmap_for_each_entry(): workaround MSVC's runtime check failure #3Junio C Hamano via GitGitGadget, Sep 28, 2020
  50. 06/11 cmake (Windows): let the `.dll` files be found when running the testsJohannes Schindelin via GitGitGadget, Sep 28, 2020
  51. 07/11 cmake (Windows): complain when encountering an unknown compilerJohannes Schindelin via GitGitGadget, Sep 28, 2020
  52. 11/11 cmake: fix typo in message when `msgfmt` was not foundJohannes Schindelin via GitGitGadget, Sep 28, 2020
  53. Junio C HamanoSep 28, 2020
  54. Johannes SchindelinSep 29, 2020
  55. 08/11 cmake (Windows): initialize vcpkg/build dependencies automaticallyJohannes Schindelin via GitGitGadget, Sep 28, 2020
  56. Sibi SiddharthanSep 29, 2020
  57. Johannes SchindelinSep 29, 2020
  58. 00/10 CMake and Visual StudioJohannes Schindelin via GitGitGadget, Sep 30, 2020
  59. 05/10 cmake: quote the path accurately when editing `test-lib.sh`Johannes Schindelin via GitGitGadget, Sep 30, 2020
  60. 04/10 cmake: fall back to using `vcpkg`'s `msgfmt.exe` on WindowsJohannes Schindelin via GitGitGadget, Sep 30, 2020
  61. 06/10 cmake (Windows): let the `.dll` files be found when running the testsJohannes Schindelin via GitGitGadget, Sep 30, 2020
  62. 07/10 cmake (Windows): complain when encountering an unknown compilerJohannes Schindelin via GitGitGadget, Sep 30, 2020
  63. 08/10 cmake (Windows): initialize vcpkg/build dependencies automaticallyJohannes Schindelin via GitGitGadget, Sep 30, 2020
  64. Johannes SchindelinSep 30, 2020
  65. Junio C HamanoSep 30, 2020
  66. 09/10 cmake (Windows): recommend using Visual Studio's built-in CMake supportJohannes Schindelin via GitGitGadget, Sep 30, 2020
  67. 10/10 hashmap_for_each_entry(): workaround MSVC's runtime check failure #3Junio C Hamano via GitGitGadget, Sep 30, 2020
  68. 02/10 cmake: do find Git for Windows' shell interpreterJohannes Schindelin via GitGitGadget, Sep 30, 2020
  69. 03/10 cmake: ensure that the `vcpkg` packages are found on WindowsJohannes Schindelin via GitGitGadget, Sep 30, 2020
  70. 01/10 cmake: ignore files generated by CMake as run in Visual StudioJohannes Schindelin via GitGitGadget, Sep 30, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.