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

[PATCH 18/24] msvc: add a Makefile target to pre-generate the Visual Studio solution

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 18, 2019, 13:19 UTC
Message-ID
<23615bc8cfd6e3d12d769f99051916ca5b2641e8.1563455939.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.287.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

The entire idea of generating the VS solution makes only sense if we generate it via Continuous Integration; otherwise potential users would still have to download the entire Git for Windows SDK.

If we pre-generate the Visual Studio solution, Git can be built entirely within Visual Studio, and the test scripts can be run in a regular Git for Windows (e.g. the Portable Git flavor, which does not include a full GCC toolchain and therefore weighs only about a tenth of Git for Windows' SDK).

So let's just add a target in the Makefile that can be used to generate said solution; The generated files will then be committed so that they can be pushed to a branch ready to check out by Visual Studio users.

To make things even more useful, we also generate and commit other files that are required to run the test suite, such as templates and bin-wrappers: with this, developers can run the test suite in a regular Git Bash after building the solution in Visual Studio.

Note: for this build target, we do not actually need to initialize the
`vcpkg` system, so we don't.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 compat/vcbuild/README          | 23 +++++++++++++
 config.mak.uname               | 61 ++++++++++++++++++++++++++++++++++
 contrib/buildsystems/engine.pl |  3 +-
 3 files changed, 86 insertions(+), 1 deletion(-)
diff --git a/compat/vcbuild/README b/compat/vcbuild/README
index b633e7db98..1b6dabf5a2 100644
--- a/compat/vcbuild/README
+++ b/compat/vcbuild/README
@@ -37,6 +37,29 @@ The Steps to Build Git with VS2015 or VS2017 from the command line.
 
 ================================================================
 
+Alternatively, run `make vcxproj` and then load the generated `git.sln` in
+Visual Studio. The initial build will install the vcpkg system and build the
+dependencies automatically. This will take a while.
+
+Instead of generating the `git.sln` file yourself (which requires a full Git
+for Windows SDK), you may want to consider fetching the `vs/master` branch of
+https://github.com/git-for-windows/git instead (which is updated automatically
+via CI running `make vcxproj`). The `vs/master` branch does not require a Git
+for Windows to build, but you can run the test scripts in a regular Git Bash.
+
+Note that `make vcxproj` will automatically add and commit the generated `.sln`
+and `.vcxproj` files to the repo. This is necessary to allow building a
+fully-testable Git in Visual Studio, where a regular Git Bash can be used to
+run the test scripts (as opposed to a full Git for Windows SDK): a number of
+build targets, such as Git commands implemented as Unix shell scripts (where
+`@@SHELL_PATH@@` and other placeholders are interpolated) require a full-blown
+Git for Windows SDK (which is about 10x the size of a regular Git for Windows
+installation).
+
+If your plan is to open a Pull Request with Git for Windows, it is a good idea
+to drop this commit before submitting.
+
+================================================================
 The Steps of Build Git with VS2008
 
 1. You need the build environment, which contains the Git dependencies
diff --git a/config.mak.uname b/config.mak.uname
index 48a6723222..6d0ed923b8 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -25,10 +25,12 @@ include compat/vcbuild/MSVC-DEFS-GEN
 	# See if vcpkg and the vcpkg-build versions of the third-party
 	# libraries that we use are installed.  We include the result
 	# to get $(vcpkg_*) variables defined for the Makefile.
+ifeq (,$(SKIP_VCPKG))
 compat/vcbuild/VCPKG-DEFS: compat/vcbuild/vcpkg_install.bat
 	@"$<"
 include compat/vcbuild/VCPKG-DEFS
 endif
+endif
 
 # We choose to avoid "if .. else if .. else .. endif endif"
 # because maintaining the nesting to match is a pain.  If
@@ -689,3 +691,62 @@ ifeq ($(uname_S),QNX)
 	NO_STRCASESTR = YesPlease
 	NO_STRLCPY = YesPlease
 endif
+
+vcxproj:
+	# Require clean work tree
+	git update-index -q --refresh && \
+	git diff-files --quiet && \
+	git diff-index --cached --quiet HEAD --
+
+	# Make .vcxproj files and add them
+	unset QUIET_GEN QUIET_BUILT_IN; \
+	perl contrib/buildsystems/generate -g Vcxproj
+	git add -f git.sln {*,*/lib,t/helper/*}/*.vcxproj
+
+	# Add command-list.h
+	$(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 command-list.h
+	git add -f command-list.h
+
+	# Add scripts
+	rm -f perl/perl.mak
+	$(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 \
+		$(SCRIPT_LIB) $(SCRIPT_SH_GEN) $(SCRIPT_PERL_GEN)
+	# Strip out the sane tool path, needed only for building
+	sed -i '/^git_broken_path_fix ".*/d' git-sh-setup
+	git add -f $(SCRIPT_LIB) $(SCRIPT_SH_GEN) $(SCRIPT_PERL_GEN)
+
+	# Add Perl module
+	$(MAKE) $(LIB_PERL_GEN)
+	git add -f perl/build
+
+	# Add bin-wrappers, for testing
+	rm -rf bin-wrappers/
+	$(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 $(test_bindir_programs)
+	# Ensure that the GIT_EXEC_PATH is a Unix-y one, and that the absolute
+	# path of the repository is not hard-coded (GIT_EXEC_PATH will be set
+	# by test-lib.sh according to the current setup)
+	sed -i -e 's/^\(GIT_EXEC_PATH\)=.*/test -n "$${\1##*:*}" ||\
+			\1="$$(cygpath -u "$$\1")"/' \
+		-e "s|'$$(pwd)|\"\$$GIT_EXEC_PATH\"'|g" bin-wrappers/*
+	# Ensure that test-* helpers find the .dll files copied to top-level
+	sed -i 's|^PATH=.*|&:"$$GIT_EXEC_PATH"|' bin-wrappers/test-*
+	# We do not want to force hard-linking builtins
+	sed -i 's|\(git\)-\([-a-z]*\)\.exe"|\1.exe" \2|g' \
+		bin-wrappers/git-{receive-pack,upload-archive}
+	git add -f $(test_bindir_programs)
+	# remote-ext is a builtin, but invoked as if it were external
+	sed 's|receive-pack|remote-ext|g' \
+		<bin-wrappers/git-receive-pack >bin-wrappers/git-remote-ext
+	git add -f bin-wrappers/git-remote-ext
+
+	# Add templates
+	$(MAKE) -C templates
+	git add -f templates/boilerplates.made templates/blt/
+
+	# Add build options
+	$(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 GIT-BUILD-OPTIONS
+	git add -f GIT-BUILD-OPTIONS
+
+	# Commit the whole shebang
+	git commit -m "Generate Visual Studio solution" \
+		-m "Auto-generated by \`$(MAKE)$(MAKEFLAGS) $@\`"
diff --git a/contrib/buildsystems/engine.pl b/contrib/buildsystems/engine.pl
index 8bb07e8e25..fba8a3f056 100755
--- a/contrib/buildsystems/engine.pl
+++ b/contrib/buildsystems/engine.pl
@@ -82,7 +82,8 @@ sub showUsage
 # Capture the make dry stderr to file for review (will be empty for a release build).
 
 my $ErrsFile = "msvc-build-makedryerrors.txt";
-@makedry = `make -C $git_dir -n MSVC=1 V=1 2>$ErrsFile` if !@makedry;
+@makedry = `make -C $git_dir -n MSVC=1 SKIP_VCPKG=1 V=1 2>$ErrsFile`
+if !@makedry;
 # test for an empty Errors file and remove it
 unlink $ErrsFile if -f -z $ErrsFile;
 
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Philip Oakley via GitGitGadget
Message 14 of 63 in “Reinstate support for Visual Studio”
  1. 00/24 Reinstate support for Visual StudioJohannes Schindelin via GitGitGadget, Jul 18, 2019
  2. 01/24 Vcproj.pm: auto-generate GUIDsJohannes Schindelin via GitGitGadget, Jul 18, 2019
  3. 03/24 Vcproj.pm: do not configure VCWebServiceProxyGeneratorToolJohannes Schindelin via GitGitGadget, Jul 18, 2019
  4. 02/24 Vcproj.pm: list git.exe first to be startup projectPhilip Oakley via GitGitGadget, Jul 18, 2019
  5. 09/24 contrib/buildsystems: ignore gettext stuffPhilip Oakley via GitGitGadget, Jul 18, 2019
  6. 06/24 contrib/buildsystems: ignore irrelevant files in Generators/Johannes Schindelin via GitGitGadget, Jul 18, 2019
  7. 07/24 contrib/buildsystems: fix misleading error messagePhilip Oakley via GitGitGadget, Jul 18, 2019
  8. 05/24 contrib/buildsystems: ignore invalidcontinue.objPhilip Oakley via GitGitGadget, Jul 18, 2019
  9. 10/24 contrib/buildsystems: redirect errors of the dry run into a log filePhilip Oakley via GitGitGadget, Jul 18, 2019
  10. 11/24 contrib/buildsystems: optionally capture the dry-run in a filePhilip Oakley via GitGitGadget, Jul 18, 2019
  11. 15/24 contrib/buildsystems: also handle -lexpatJohannes Schindelin via GitGitGadget, Jul 18, 2019
  12. 13/24 contrib/buildsystems: handle the curl library optionPhilip Oakley via GitGitGadget, Jul 18, 2019
  13. 12/24 contrib/buildsystems: error out on unknown optionJohannes Schindelin via GitGitGadget, Jul 18, 2019
  14. 18/24 msvc: add a Makefile target to pre-generate the Visual Studio solutionJohannes Schindelin via GitGitGadget, Jul 18, 2019
  15. 20/24 .gitignore: touch up the entries regarding Visual StudioPhilip Oakley via GitGitGadget, Jul 18, 2019
  16. 17/24 contrib/buildsystems: add a backend for modern Visual Studio versionsJohannes Schindelin via GitGitGadget, Jul 18, 2019
  17. 22/24 bin-wrappers: append `.exe` to target paths if necessaryJohannes Schindelin via GitGitGadget, Jul 18, 2019
  18. 24/24 git: avoid calling aliased builtins via their dashed formJohannes Schindelin via GitGitGadget, Jul 18, 2019
  19. 23/24 t5505,t5516: create .git/branches/ when neededJohannes Schindelin via GitGitGadget, Jul 18, 2019
  20. Junio C HamanoJul 18, 2019
  21. Johannes SchindelinJul 19, 2019
  22. Junio C HamanoJul 19, 2019
  23. Junio C HamanoJul 19, 2019
  24. Junio C HamanoJul 19, 2019
  25. 14/24 contrib/buildsystems: handle libiconv, tooJohannes Schindelin via GitGitGadget, Jul 18, 2019
  26. 21/24 .gitignore: ignore Visual Studio's temporary/generated filesJohannes Schindelin via GitGitGadget, Jul 18, 2019
  27. 19/24 vcxproj: also link-or-copy builtinsJohannes Schindelin via GitGitGadget, Jul 18, 2019
  28. 16/24 contrib/buildsystems: handle options starting with a slashJohannes Schindelin via GitGitGadget, Jul 18, 2019
  29. 08/24 contrib/buildsystems: handle quoted spaces in filenamesPhilip Oakley via GitGitGadget, Jul 18, 2019
  30. 04/24 Vcproj.pm: urlencode '<' and '>' when generating VC projectsJohannes Schindelin via GitGitGadget, Jul 18, 2019
  31. 00/23 Reinstate support for Visual StudioJohannes Schindelin via GitGitGadget, Jul 29, 2019
  32. 01/23 Vcproj.pm: auto-generate GUIDsJohannes Schindelin via GitGitGadget, Jul 29, 2019
  33. 02/23 Vcproj.pm: list git.exe first to be startup projectPhilip Oakley via GitGitGadget, Jul 29, 2019
  34. 03/23 Vcproj.pm: do not configure VCWebServiceProxyGeneratorToolJohannes Schindelin via GitGitGadget, Jul 29, 2019
  35. 04/23 Vcproj.pm: urlencode '<' and '>' when generating VC projectsJohannes Schindelin via GitGitGadget, Jul 29, 2019
  36. 05/23 contrib/buildsystems: ignore invalidcontinue.objPhilip Oakley via GitGitGadget, Jul 29, 2019
  37. 11/23 contrib/buildsystems: optionally capture the dry-run in a filePhilip Oakley via GitGitGadget, Jul 29, 2019
  38. 12/23 contrib/buildsystems: error out on unknown optionJohannes Schindelin via GitGitGadget, Jul 29, 2019
  39. 16/23 contrib/buildsystems: handle options starting with a slashJohannes Schindelin via GitGitGadget, Jul 29, 2019
  40. 15/23 contrib/buildsystems: also handle -lexpatJohannes Schindelin via GitGitGadget, Jul 29, 2019
  41. 17/23 contrib/buildsystems: add a backend for modern Visual Studio versionsJohannes Schindelin via GitGitGadget, Jul 29, 2019
  42. 20/23 .gitignore: touch up the entries regarding Visual StudioPhilip Oakley via GitGitGadget, Jul 29, 2019
  43. SZEDER GáborAug 25, 2019
  44. Philip OakleyAug 25, 2019
  45. SZEDER GáborAug 25, 2019
  46. Philip OakleyAug 25, 2019
  47. SZEDER GáborAug 26, 2019
  48. Johannes SchindelinAug 28, 2019
  49. Johannes SchindelinAug 26, 2019
  50. Junio C HamanoAug 26, 2019
  51. 21/23 .gitignore: ignore Visual Studio's temporary/generated filesJohannes Schindelin via GitGitGadget, Jul 29, 2019
  52. 23/23 git: avoid calling aliased builtins via their dashed formJohannes Schindelin via GitGitGadget, Jul 29, 2019
  53. 14/23 contrib/buildsystems: handle libiconv, tooJohannes Schindelin via GitGitGadget, Jul 29, 2019
  54. 19/23 vcxproj: also link-or-copy builtinsJohannes Schindelin via GitGitGadget, Jul 29, 2019
  55. 22/23 bin-wrappers: append `.exe` to target paths if necessaryJohannes Schindelin via GitGitGadget, Jul 29, 2019
  56. 18/23 msvc: add a Makefile target to pre-generate the Visual Studio solutionJohannes Schindelin via GitGitGadget, Jul 29, 2019
  57. 10/23 contrib/buildsystems: redirect errors of the dry run into a log filePhilip Oakley via GitGitGadget, Jul 29, 2019
  58. 06/23 contrib/buildsystems: ignore irrelevant files in Generators/Johannes Schindelin via GitGitGadget, Jul 29, 2019
  59. 13/23 contrib/buildsystems: handle the curl library optionPhilip Oakley via GitGitGadget, Jul 29, 2019
  60. 09/23 contrib/buildsystems: ignore gettext stuffPhilip Oakley via GitGitGadget, Jul 29, 2019
  61. 07/23 contrib/buildsystems: fix misleading error messagePhilip Oakley via GitGitGadget, Jul 29, 2019
  62. 08/23 contrib/buildsystems: handle quoted spaces in filenamesPhilip Oakley via GitGitGadget, Jul 29, 2019
  63. Junio C HamanoJul 29, 2019

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.