Skip to content

Commit

Permalink
Merge branch 'visual-studio'
Browse files Browse the repository at this point in the history
This topic branch teaches the project generator to generate a Visual
Studio solution, ready to be opened in Visual Studio 2010 or later.

The idea, of course, is to let some automatic build job generate and
commit the project files with

	make MSVC=1 vcxproj

and then (force-)push to a special-purpose branch.

The major part of this branch thicket concerns itself not only with
generating the Visual Studio project files, but making sure that the
user can then run the test suite from a regular Git Bash (i.e. *not*
requiring a Git for Windows SDK), e.g. by running

	cd t
	prove --timer --jobs 15 ./t[0-9]*.sh

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Oct 12, 2018
2 parents 2ddda64 + c6585c2 commit 2a8356c
Show file tree
Hide file tree
Showing 16 changed files with 692 additions and 40 deletions.
47 changes: 45 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,42 @@
/gitweb/static/gitweb.js
/gitweb/static/gitweb.min.*
/command-list.h
/libgit
/test-chmtime
/test-ctype
/test-config
/test-date
/test-delta
/test-dump-cache-tree
/test-dump-split-index
/test-dump-untracked-cache
/test-fake-ssh
/test-scrap-cache-tree
/test-genrandom
/test-hashmap
/test-index-version
/test-line-buffer
/test-match-trees
/test-mergesort
/test-mktemp
/test-parse-options
/test-path-utils
/test-prio-queue
/test-read-cache
/test-regex
/test-revision-walking
/test-run-command
/test-sha1
/test-sha1-array
/test-sigchain
/test-string-list
/test-submodule-config
/test-subprocess
/test-svn-fe
/test-urlmatch-normalization
/test-wildmatch
/vcs-svn_lib
/xdiff_lib
*.tar.gz
*.dsc
*.deb
Expand Down Expand Up @@ -224,6 +260,13 @@
*.idb
*.pdb
*.ilk
*.iobj
*.ipdb
*.dll
.vs/
/Debug/
/Release/
*.manifest
Debug/
Release/
/UpgradeLog*.htm
/git.VC.VC.opendb
/git.VC.db
6 changes: 6 additions & 0 deletions .nuget/NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="..\compat\vcbuild\GEN.PKGS" />
</config>
</configuration>
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,9 @@ ifdef GIT_INTEROP_MAKE_OPTS
endif
ifdef TEST_GIT_INDEX_VERSION
@echo TEST_GIT_INDEX_VERSION=\''$(subst ','\'',$(subst ','\'',$(TEST_GIT_INDEX_VERSION)))'\' >>$@+
endif
ifdef MSVC_DEPS
@echo MSVC_DEPS=\''$(subst ','\'',$(subst ','\'',$(MSVC_DEPS)))'\' >>$@+
endif
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi

Expand All @@ -2626,7 +2629,7 @@ bin-wrappers/%: wrap-for-bin.sh
@mkdir -p bin-wrappers
$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-e 's|@@BUILD_DIR@@|$(shell pwd)|' \
-e 's|@@PROG@@|$(patsubst test-%,t/helper/test-%,$(@F))|' < $< > $@ && \
-e 's|@@PROG@@|$(patsubst test-%,t/helper/test-%$(X),$(@F))$(patsubst git%,$(X),$(filter $(@F),$(BINDIR_PROGRAMS_NEED_X)))|' < $< > $@ && \
chmod +x $@

# GNU make supports exporting all variables by "export" without parameters.
Expand Down
8 changes: 8 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,10 @@ static void adjust_symlink_flags(void)

#if defined(_MSC_VER)

#ifdef _DEBUG
#include <crtdbg.h>
#endif

/*
* This routine sits between wmain() and "main" in git.exe.
* We receive UNICODE (wchar_t) values for argv and env.
Expand All @@ -3231,6 +3235,10 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env)
int maxlen;
int k, exit_status;

#ifdef _DEBUG
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
#endif

#ifdef USE_MSVC_CRTDBG
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
Expand Down
4 changes: 4 additions & 0 deletions compat/msvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <malloc.h>
#include <io.h>

#pragma warning(disable: 4018) /* signed/unsigned comparison */
#pragma warning(disable: 4244) /* type conversion, possible loss of data */
#pragma warning(disable: 4090) /* 'function' : different 'const' qualifiers (ALLOC_GROW etc.)*/

/* porting function */
#define inline __inline
#define __inline__ __inline
Expand Down
2 changes: 1 addition & 1 deletion compat/obstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ __extension__ \
( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \
((((h)->temp.tempint > 0 \
&& (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \
? (int) ((h)->next_free = (h)->object_base \
? (ptrdiff_t) ((h)->next_free = (h)->object_base \
= (h)->temp.tempint + (char *) (h)->chunk) \
: (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))

Expand Down
2 changes: 2 additions & 0 deletions compat/terminal.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#ifndef NO_INTTYPES_H
#include <inttypes.h>
#endif
#include "git-compat-util.h"
#include "run-command.h"
#include "compat/terminal.h"
Expand Down
72 changes: 72 additions & 0 deletions config.mak.uname
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Platform specific Makefile tweaks based on uname detection

# Define NO_SAFESEH if you need MSVC/Visual Studio to ignore the lack of
# Microsoft's Safe Exception Handling in libraries (such as zlib).
# Typically required for VS2013+/32-bit compilation on Vista+ versions.

uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
Expand Down Expand Up @@ -383,6 +387,7 @@ ifeq ($(uname_S),Windows)
NEEDS_LIBICONV = YesPlease
NO_STRTOUMAX = YesPlease
NO_MKDTEMP = YesPlease
NO_INTTYPES_H = YesPlease
# VS2015 with UCRT claims that snprintf and friends are C99 compliant,
# so we don't need this.
#
Expand Down Expand Up @@ -416,6 +421,9 @@ ifeq ($(uname_S),Windows)
compat/win32/dirent.o compat/win32/fscache.o
COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DDETECT_MSYS_TTY -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE
# invalidcontinue.obj allows Git's source code to close the same file
# handle twice, or to access the osfhandle of an already-closed stdout
# See https://msdn.microsoft.com/en-us/library/ms235330.aspx
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj kernel32.lib ntdll.lib
PTHREAD_LIBS =
lib =
Expand All @@ -434,6 +442,11 @@ ifeq ($(uname_S),Windows)
# release mode) to force a PDB to be generated (like RelWithDebInfo).
BASIC_CFLAGS += -Zi
BASIC_LDFLAGS += -debug

ifdef NO_SAFESEH
LDFLAGS += -SAFESEH:NO
endif

ifndef DEBUG
BASIC_CFLAGS += -GL -Gy -O2 -Oy- -MD -DNDEBUG
BASIC_LDFLAGS += -release -LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:CV,FIXUP
Expand All @@ -444,6 +457,65 @@ endif
X = .exe

compat/msvc.o: compat/msvc.c compat/mingw.c GIT-CFLAGS

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/*}/{packages.config,*.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 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 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 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) $@\`"
endif
ifeq ($(uname_S),Interix)
NO_INITGROUPS = YesPlease
Expand Down
2 changes: 1 addition & 1 deletion contrib/buildsystems/Generators.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BEGIN {
$me = dirname($me);
if (opendir(D,"$me/Generators")) {
foreach my $gen (readdir(D)) {
next if ($gen =~ /^\.\.?$/);
next unless ($gen =~ /\.pm$/);
require "${me}/Generators/$gen";
$gen =~ s,\.pm,,;
push(@AVAILABLE, $gen);
Expand Down
Loading

0 comments on commit 2a8356c

Please sign in to comment.