Skip to content

Commit 976aaed

Browse files
dschogitster
authored andcommitted
msvc: add a Makefile target to pre-generate the Visual Studio solution
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 384a61b commit 976aaed

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

compat/vcbuild/README

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ The Steps to Build Git with VS2015 or VS2017 from the command line.
3737

3838
================================================================
3939

40+
Alternatively, run `make vcxproj` and then load the generated `git.sln` in
41+
Visual Studio. The initial build will install the vcpkg system and build the
42+
dependencies automatically. This will take a while.
43+
44+
Instead of generating the `git.sln` file yourself (which requires a full Git
45+
for Windows SDK), you may want to consider fetching the `vs/master` branch of
46+
https://github.com/git-for-windows/git instead (which is updated automatically
47+
via CI running `make vcxproj`). The `vs/master` branch does not require a Git
48+
for Windows to build, but you can run the test scripts in a regular Git Bash.
49+
50+
Note that `make vcxproj` will automatically add and commit the generated `.sln`
51+
and `.vcxproj` files to the repo. This is necessary to allow building a
52+
fully-testable Git in Visual Studio, where a regular Git Bash can be used to
53+
run the test scripts (as opposed to a full Git for Windows SDK): a number of
54+
build targets, such as Git commands implemented as Unix shell scripts (where
55+
`@@SHELL_PATH@@` and other placeholders are interpolated) require a full-blown
56+
Git for Windows SDK (which is about 10x the size of a regular Git for Windows
57+
installation).
58+
59+
If your plan is to open a Pull Request with Git for Windows, it is a good idea
60+
to drop this commit before submitting.
61+
62+
================================================================
4063
The Steps of Build Git with VS2008
4164

4265
1. You need the build environment, which contains the Git dependencies

config.mak.uname

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ include compat/vcbuild/MSVC-DEFS-GEN
2525
# See if vcpkg and the vcpkg-build versions of the third-party
2626
# libraries that we use are installed. We include the result
2727
# to get $(vcpkg_*) variables defined for the Makefile.
28+
ifeq (,$(SKIP_VCPKG))
2829
compat/vcbuild/VCPKG-DEFS: compat/vcbuild/vcpkg_install.bat
2930
@"$<"
3031
include compat/vcbuild/VCPKG-DEFS
3132
endif
33+
endif
3234

3335
# We choose to avoid "if .. else if .. else .. endif endif"
3436
# because maintaining the nesting to match is a pain. If
@@ -689,3 +691,62 @@ ifeq ($(uname_S),QNX)
689691
NO_STRCASESTR = YesPlease
690692
NO_STRLCPY = YesPlease
691693
endif
694+
695+
vcxproj:
696+
# Require clean work tree
697+
git update-index -q --refresh && \
698+
git diff-files --quiet && \
699+
git diff-index --cached --quiet HEAD --
700+
701+
# Make .vcxproj files and add them
702+
unset QUIET_GEN QUIET_BUILT_IN; \
703+
perl contrib/buildsystems/generate -g Vcxproj
704+
git add -f git.sln {*,*/lib,t/helper/*}/*.vcxproj
705+
706+
# Add command-list.h
707+
$(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 command-list.h
708+
git add -f command-list.h
709+
710+
# Add scripts
711+
rm -f perl/perl.mak
712+
$(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 \
713+
$(SCRIPT_LIB) $(SCRIPT_SH_GEN) $(SCRIPT_PERL_GEN)
714+
# Strip out the sane tool path, needed only for building
715+
sed -i '/^git_broken_path_fix ".*/d' git-sh-setup
716+
git add -f $(SCRIPT_LIB) $(SCRIPT_SH_GEN) $(SCRIPT_PERL_GEN)
717+
718+
# Add Perl module
719+
$(MAKE) $(LIB_PERL_GEN)
720+
git add -f perl/build
721+
722+
# Add bin-wrappers, for testing
723+
rm -rf bin-wrappers/
724+
$(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 $(test_bindir_programs)
725+
# Ensure that the GIT_EXEC_PATH is a Unix-y one, and that the absolute
726+
# path of the repository is not hard-coded (GIT_EXEC_PATH will be set
727+
# by test-lib.sh according to the current setup)
728+
sed -i -e 's/^\(GIT_EXEC_PATH\)=.*/test -n "$${\1##*:*}" ||\
729+
\1="$$(cygpath -u "$$\1")"/' \
730+
-e "s|'$$(pwd)|\"\$$GIT_EXEC_PATH\"'|g" bin-wrappers/*
731+
# Ensure that test-* helpers find the .dll files copied to top-level
732+
sed -i 's|^PATH=.*|&:"$$GIT_EXEC_PATH"|' bin-wrappers/test-*
733+
# We do not want to force hard-linking builtins
734+
sed -i 's|\(git\)-\([-a-z]*\)\.exe"|\1.exe" \2|g' \
735+
bin-wrappers/git-{receive-pack,upload-archive}
736+
git add -f $(test_bindir_programs)
737+
# remote-ext is a builtin, but invoked as if it were external
738+
sed 's|receive-pack|remote-ext|g' \
739+
<bin-wrappers/git-receive-pack >bin-wrappers/git-remote-ext
740+
git add -f bin-wrappers/git-remote-ext
741+
742+
# Add templates
743+
$(MAKE) -C templates
744+
git add -f templates/boilerplates.made templates/blt/
745+
746+
# Add build options
747+
$(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 GIT-BUILD-OPTIONS
748+
git add -f GIT-BUILD-OPTIONS
749+
750+
# Commit the whole shebang
751+
git commit -m "Generate Visual Studio solution" \
752+
-m "Auto-generated by \`$(MAKE)$(MAKEFLAGS) $@\`"

contrib/buildsystems/engine.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ sub showUsage
8282
# Capture the make dry stderr to file for review (will be empty for a release build).
8383

8484
my $ErrsFile = "msvc-build-makedryerrors.txt";
85-
@makedry = `make -C $git_dir -n MSVC=1 V=1 2>$ErrsFile` if !@makedry;
85+
@makedry = `make -C $git_dir -n MSVC=1 SKIP_VCPKG=1 V=1 2>$ErrsFile`
86+
if !@makedry;
8687
# test for an empty Errors file and remove it
8788
unlink $ErrsFile if -f -z $ErrsFile;
8889

0 commit comments

Comments
 (0)