Skip to content

Commit 3bda3b6

Browse files
pks-tgitster
authored andcommitted
t: better support for out-of-tree builds
Our in-tree builds used by the Makefile use various different build directories scattered around different locations. The paths to those build directories have to be propagated to our tests such that they can find the contained files. This is done via a mixture of hardcoded paths in our test library and injected variables in our bin-wrappers or "GIT-BUILD-OPTIONS". The latter two mechanisms are preferable over using hardcoded paths. For one, we have all paths which are subject to change stored in a small set of central files instead of having the knowledge of build paths in many files. And second, it allows build systems which build files elsewhere to adapt those paths based on their own needs. This is especially nice in the context of build systems that use out-of-tree builds like CMake or Meson. Remove hardcoded knowledge of build paths from our test library and move it into our bin-wrappers and "GIT-BUILD-OPTIONS". Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6473c2e commit 3bda3b6

File tree

7 files changed

+34
-11
lines changed

7 files changed

+34
-11
lines changed

GIT-BUILD-OPTIONS.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ GIT_PERF_MAKE_COMMAND=@GIT_PERF_MAKE_COMMAND@
3333
GIT_INTEROP_MAKE_OPTS=@GIT_INTEROP_MAKE_OPTS@
3434
GIT_TEST_INDEX_VERSION=@GIT_TEST_INDEX_VERSION@
3535
GIT_TEST_PERL_FATAL_WARNINGS=@GIT_TEST_PERL_FATAL_WARNINGS@
36+
GIT_TEST_TEXTDOMAINDIR=@GIT_TEST_TEXTDOMAINDIR@
37+
GIT_TEST_POPATH=@GIT_TEST_POPATH@
38+
GIT_TEST_TEMPLATE_DIR=@GIT_TEST_TEMPLATE_DIR@
39+
GIT_TEST_GITPERLLIB=@GIT_TEST_GITPERLLIB@
40+
GIT_TEST_MERGE_TOOLS_DIR=@GIT_TEST_MERGE_TOOLS_DIR@
3641
RUNTIME_PREFIX=@RUNTIME_PREFIX@

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,6 +3194,11 @@ GIT-BUILD-OPTIONS: FORCE
31943194
-e "s|@GIT_INTEROP_MAKE_OPTS@|\'$(GIT_INTEROP_MAKE_OPTS)\'|" \
31953195
-e "s|@GIT_TEST_INDEX_VERSION@|\'$(GIT_TEST_INDEX_VERSION)\'|" \
31963196
-e "s|@GIT_TEST_PERL_FATAL_WARNINGS@|\'$(GIT_TEST_PERL_FATAL_WARNINGS)\'|" \
3197+
-e "s|@GIT_TEST_TEXTDOMAINDIR@|\'$(shell pwd)/po/build/locale\'|" \
3198+
-e "s|@GIT_TEST_POPATH@|\'$(shell pwd)/po\'|" \
3199+
-e "s|@GIT_TEST_TEMPLATE_DIR@|\'$(shell pwd)/templates/blt\'|" \
3200+
-e "s|@GIT_TEST_GITPERLLIB@|\'$(shell pwd)/perl/build/lib\'|" \
3201+
-e "s|@GIT_TEST_MERGE_TOOLS_DIR@|\'$(shell pwd)/mergetools\'|" \
31973202
-e "s|@RUNTIME_PREFIX@|\'$(RUNTIME_PREFIX)\'|" \
31983203
GIT-BUILD-OPTIONS.in >$@+
31993204
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
@@ -3218,6 +3223,10 @@ all:: $(TEST_PROGRAMS) $(test_bindir_programs) $(UNIT_TEST_PROGS) $(CLAR_TEST_PR
32183223
bin-wrappers/%: bin-wrappers/wrap-for-bin.sh
32193224
$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
32203225
-e 's|@BUILD_DIR@|$(shell pwd)|' \
3226+
-e 's|@GIT_TEXTDOMAINDIR@|$(shell pwd)/po/build/locale|' \
3227+
-e 's|@GITPERLLIB@|$(shell pwd)/perl/build/lib|' \
3228+
-e 's|@MERGE_TOOLS_DIR@|$(shell pwd)/mergetools|' \
3229+
-e 's|@TEMPLATE_DIR@|$(shell pwd)/templates/blt|' \
32213230
-e 's|@PROG@|$(patsubst test-%,t/helper/test-%,$(@F))$(if $(filter-out $(BINDIR_PROGRAMS_NO_X),$(@F)),$(X),)|' < $< > $@ && \
32223231
chmod +x $@
32233232

bin-wrappers/wrap-for-bin.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
# to run test suite against sandbox, but with only bindir-installed
55
# executables in PATH. The Makefile copies this into various
66
# files in bin-wrappers, substituting
7-
# @BUILD_DIR@ and @PROG@.
7+
# @BUILD_DIR@, @TEMPLATE_DIR@ and @PROG@.
88

99
GIT_EXEC_PATH='@BUILD_DIR@'
1010
if test -n "$NO_SET_GIT_TEMPLATE_DIR"
1111
then
1212
unset GIT_TEMPLATE_DIR
1313
else
14-
GIT_TEMPLATE_DIR='@BUILD_DIR@/templates/blt'
14+
GIT_TEMPLATE_DIR='@TEMPLATE_DIR@'
1515
export GIT_TEMPLATE_DIR
1616
fi
17-
GITPERLLIB='@BUILD_DIR@/perl/build/lib'"${GITPERLLIB:+:$GITPERLLIB}"
18-
GIT_TEXTDOMAINDIR='@BUILD_DIR@/po/build/locale'
17+
MERGE_TOOLS_DIR='@MERGE_TOOLS_DIR@'
18+
GITPERLLIB='@GITPERLLIB@'"${GITPERLLIB:+:$GITPERLLIB}"
19+
GIT_TEXTDOMAINDIR='@GIT_TEXTDOMAINDIR@'
1920
PATH='@BUILD_DIR@/bin-wrappers:'"$PATH"
2021

21-
export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
22+
export MERGE_TOOLS_DIR GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
2223

2324
case "$GIT_DEBUGGER" in
2425
'')

contrib/buildsystems/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,9 @@ endforeach()
10871087

10881088
file(STRINGS ${CMAKE_SOURCE_DIR}/bin-wrappers/wrap-for-bin.sh content NEWLINE_CONSUME)
10891089
string(REPLACE "@BUILD_DIR@" "${CMAKE_BINARY_DIR}" content "${content}")
1090+
string(REPLACE "@GIT_TEXTDOMAINDIR@" "${CMAKE_BINARY_DIR}/po/build/locale" content "${content}")
1091+
string(REPLACE "@GITPERLLIB@" "${CMAKE_BINARY_DIR}/perl/build/lib" content "${content}")
1092+
string(REPLACE "@MERGE_TOOLS_DIR@" "${CMAKE_SOURCE_DIR}/mergetools" content "${content}")
10901093
string(REPLACE "@PROG@" "git-cvsserver" content "${content}")
10911094
file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
10921095

@@ -1171,6 +1174,11 @@ string(REPLACE "@GIT_INTEROP_MAKE_OPTS@" "" git_build_options "${git_build_optio
11711174
string(REPLACE "@GIT_TEST_INDEX_VERSION@" "" git_build_options "${git_build_options}")
11721175
string(REPLACE "@GIT_TEST_PERL_FATAL_WARNINGS@" "" git_build_options "${git_build_options}")
11731176
string(REPLACE "@RUNTIME_PREFIX@" "${RUNTIME_PREFIX}" git_build_options "${git_build_options}")
1177+
string(REPLACE "@GIT_TEST_TEXTDOMAINDIR@" "${CMAKE_BINARY_DIR}/po/build/locale" git_build_options "${git_build_options}")
1178+
string(REPLACE "@GIT_TEST_POPATH@" "${CMAKE_BINARY_DIR}/po" git_build_options "${git_build_options}")
1179+
string(REPLACE "@GIT_TEST_TEMPLATE_DIR@" "${CMAKE_BINARY_DIR}/templates/blt" git_build_options "${git_build_options}")
1180+
string(REPLACE "@GIT_TEST_GITPERLLIB@" "${CMAKE_BINARY_DIR}/perl/build/lib" git_build_options "${git_build_options}")
1181+
string(REPLACE "@GIT_TEST_MERGE_TOOLS_DIR@" "${RUNTIME_PREFIX}" git_build_options "${git_build_options}")
11741182
if(USE_VCPKG)
11751183
string(APPEND git_build_options "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
11761184
endif()

t/lib-gettext.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
. ./test-lib.sh
88

9-
GIT_TEXTDOMAINDIR="$GIT_BUILD_DIR/po/build/locale"
10-
GIT_PO_PATH="$GIT_BUILD_DIR/po"
9+
GIT_TEXTDOMAINDIR="$GIT_TEST_TEXTDOMAINDIR"
10+
GIT_PO_PATH="$GIT_TEST_POPATH"
1111
export GIT_TEXTDOMAINDIR GIT_PO_PATH
1212

1313
if test -n "$GIT_TEST_INSTALLED"

t/t7609-mergetool--lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ TEST_PASSES_SANITIZE_LEAK=true
88
. ./test-lib.sh
99

1010
test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '
11-
. "$GIT_BUILD_DIR"/mergetools/vimdiff &&
11+
. "$GIT_TEST_MERGE_TOOLS_DIR"/vimdiff &&
1212
run_unit_tests
1313
'
1414

t/test-lib.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ else # normal case, use ../bin-wrappers only unless $with_dashes:
14781478
PATH="$GIT_BUILD_DIR:$GIT_BUILD_DIR/t/helper:$PATH"
14791479
fi
14801480
fi
1481-
GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
1481+
GIT_TEMPLATE_DIR="$GIT_TEST_TEMPLATE_DIR"
14821482
GIT_CONFIG_NOSYSTEM=1
14831483
GIT_ATTR_NOSYSTEM=1
14841484
GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/.."
@@ -1494,9 +1494,9 @@ then
14941494
fi
14951495
fi
14961496

1497-
GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib
1497+
GITPERLLIB="$GIT_TEST_GITPERLLIB"
14981498
export GITPERLLIB
1499-
test -d "$GIT_BUILD_DIR"/templates/blt || {
1499+
test -d "$GIT_TEMPLATE_DIR" || {
15001500
BAIL_OUT "You haven't built things yet, have you?"
15011501
}
15021502

0 commit comments

Comments
 (0)