diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 48ff9029374df3..4560774b2526bf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -85,6 +85,65 @@ CMake, either by letting Visual Studio configure it automatically (simply open G top-level directory via `File>Open>Folder...`) or by (downloading and) running [CMake](https://cmake.org) manually. +## Building and testing in Windows Subsystem for Linux ("WSL") + +Install the Linux packages `gcc-mingw-w64-x86-64` and +`libz-mingw-w64-dev`. From the source directory in Linux Bash: + +```bash +cross=x86_64-w64-mingw32 +MSYSTEM=MINGW64 make -j"$(nproc)" uname_S=MINGW \ + CC="$cross-gcc" AR="$cross-ar" RC="$cross-windres -O coff" \ + MINGW_CHOST="$cross" NO_CURL=1 NO_GETTEXT=1 \ + NO_ICONV=1 NO_OPENSSL=1 NO_PERL=1 NO_PYTHON=1 \ + NO_RUST=1 NO_TCLTK=1 USE_LIBPCRE= +``` + +Prefer WSL Bash for speed. Use SDK Bash for Windows-specific prerequisites, +MSYS path handling or integrations such as `git svn` with Perl/SVN enabled. + +### Run tests with WSL Bash + +Install the Git for Windows SDK before testing. + +```bash +sdk=/mnt/d/git-sdk-64 +script=t0014-alias.sh +zlib=/usr/$cross/lib +ssp=$(dirname "$("$cross-gcc" -print-file-name=libssp-0.dll)") +output=$(mktemp -d) +( + export MSYSTEM=MINGW64 GIT_TEST_WSL=1 + export TEST_OUTPUT_DIRECTORY="$output" + export PATH="$ssp:$zlib:$sdk/mingw64/bin:$sdk/usr/bin:$PATH" + export Path="$PATH" + export WSLENV=MSYSTEM:Path/pl + # -V will write the detailed output to t/test-results/.out + cd t && time bash "$script" -iVx +) +``` + +Use `Path/pl`, not `PATH/pl`, to avoid duplicate Windows path entries. + +### Run tests with Git SDK Bash + +```bash +# MSYS2 `mkdir` cannot create directories in UNC paths; use $env:Temp +scratch=$(wslpath -u "$("$sdk/usr/bin/cygpath.exe" -m /tmp)") +output=$(mktemp -d -p "$scratch") +runtime="$(wslpath -m "$ssp"):$(wslpath -m "$zlib")" + +( + cd t && + time "$sdk/usr/bin/env.exe" MSYSTEM=MINGW64 \ + "PATH=$runtime:/mingw64/bin:/usr/bin" \ + "TEST_OUTPUT_DIRECTORY=$(wslpath -m "$output")" \ + "GIT_TEST_TEMPLATE_DIR=$(wslpath -m "$PWD/../templates/blt")" \ + "$(wslpath -m "$sdk")/usr/bin/bash.exe" \ + "$script" -iVx --no-bin-wrappers +) +``` + What to Change? --------------- diff --git a/GIT-BUILD-OPTIONS.in b/GIT-BUILD-OPTIONS.in index 0a9884e0ade556..2537e2285bc893 100644 --- a/GIT-BUILD-OPTIONS.in +++ b/GIT-BUILD-OPTIONS.in @@ -16,7 +16,7 @@ GIT_TEST_GITPERLLIB=@GIT_TEST_GITPERLLIB@ GIT_TEST_INDEX_VERSION=@GIT_TEST_INDEX_VERSION@ GIT_TEST_OPTS=@GIT_TEST_OPTS@ GIT_TEST_PERL_FATAL_WARNINGS=@GIT_TEST_PERL_FATAL_WARNINGS@ -GIT_TEST_TEMPLATE_DIR=@GIT_TEST_TEMPLATE_DIR@ +GIT_TEST_TEMPLATE_DIR=${GIT_TEST_TEMPLATE_DIR:-@GIT_TEST_TEMPLATE_DIR@} GIT_TEST_TEXTDOMAINDIR=@GIT_TEST_TEXTDOMAINDIR@ GIT_TEST_UTF8_LOCALE=@GIT_TEST_UTF8_LOCALE@ LOCALEDIR=@LOCALEDIR@ diff --git a/bin-wrappers/wrap-for-bin.sh b/bin-wrappers/wrap-for-bin.sh index 4b658ffd2d0960..d6fc9d99817be3 100755 --- a/bin-wrappers/wrap-for-bin.sh +++ b/bin-wrappers/wrap-for-bin.sh @@ -21,6 +21,26 @@ PATH='@BUILD_DIR@/bin-wrappers:'"$PATH" export MERGE_TOOLS_DIR GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR +if test "$GIT_TEST_WSL" = 1 +then + export Path="$PATH" + if test -n "$TEST_OUTPUT_DIRECTORY" + then + safe=$(wslpath -m "$TEST_OUTPUT_DIRECTORY") || exit + safe=$(printf '%s' "$safe" | sed "s/'/'\\\\''/g") || exit + params="${GIT_CONFIG_PARAMETERS:+$GIT_CONFIG_PARAMETERS }" + export GIT_CONFIG_PARAMETERS="$params'safe.directory'='$safe/*'" + fi + WSLENV="$WSLENV:HOME/p:GITPERLLIB/pl:LANG:LC_ALL:TZ:TERM" + WSLENV="$WSLENV:EDITOR:PAGER:COLUMNS:$(env -0 | sed -zE ' + /^(TEST|GIT)_/!d + s/=.*// + s/^GIT_(EXEC_PATH|TEMPLATE_DIR|TEXTDOMAINDIR)$/&\/p/ + s/^GIT_CEILING_DIRECTORIES$/&\/pl/ + ' | tr '\0' :)" + export WSLENV +fi + case "$GIT_DEBUGGER" in '') exec "@PROG@" "$@" diff --git a/t/README b/t/README index a02200615f59a0..4b20c029858036 100644 --- a/t/README +++ b/t/README @@ -356,6 +356,14 @@ that cannot be easily covered by a few specific test cases. These could be enabled by running the test suite with correct GIT_TEST_ environment set. +GIT_TEST_TEMPLATE_DIR= overrides the generated location of the +templates used by the tests. + +GIT_TEST_WSL=1 forwards the test environment when the generated wrappers +run Windows executables from WSL. It also grants a command-scope +safe.directory exception for repositories under TEST_OUTPUT_DIRECTORY. +See CONTRIBUTING.md for the cross-build and runner setup. + GIT_TEST_FAIL_PREREQS= fails all prerequisites. This is useful for discovering issues with the tests where say a later test implicitly depends on an optional earlier test.