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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 6, 2024 at 14:24 UTC 7e0730c8baaac43fcf0366e686066ec2c1fc2f31
7 files changed +34 -11
GIT-BUILD-OPTIONS.in
+5
@@ -35,6 +35,11 @@ GIT_PERF_MAKE_COMMAND=@GIT_PERF_MAKE_COMMAND@
35 GIT_INTEROP_MAKE_OPTS=@GIT_INTEROP_MAKE_OPTS@
36 GIT_TEST_INDEX_VERSION=@GIT_TEST_INDEX_VERSION@
37 GIT_TEST_PERL_FATAL_WARNINGS=@GIT_TEST_PERL_FATAL_WARNINGS@
38 +GIT_TEST_TEXTDOMAINDIR=@GIT_TEST_TEXTDOMAINDIR@
39 +GIT_TEST_POPATH=@GIT_TEST_POPATH@
40 +GIT_TEST_TEMPLATE_DIR=@GIT_TEST_TEMPLATE_DIR@
41 +GIT_TEST_GITPERLLIB=@GIT_TEST_GITPERLLIB@
42 +GIT_TEST_MERGE_TOOLS_DIR=@GIT_TEST_MERGE_TOOLS_DIR@
43 RUNTIME_PREFIX=@RUNTIME_PREFIX@
44 GITWEBDIR=@GITWEBDIR@
45 USE_GETTEXT_SCHEME=@USE_GETTEXT_SCHEME@
Makefile
+9
@@ -3176,6 +3176,11 @@ GIT-BUILD-OPTIONS: FORCE
3176 -e "s|@GIT_INTEROP_MAKE_OPTS@|\'$(GIT_INTEROP_MAKE_OPTS)\'|" \
3177 -e "s|@GIT_TEST_INDEX_VERSION@|\'$(GIT_TEST_INDEX_VERSION)\'|" \
3178 -e "s|@GIT_TEST_PERL_FATAL_WARNINGS@|\'$(GIT_TEST_PERL_FATAL_WARNINGS)\'|" \
3179 + -e "s|@GIT_TEST_TEXTDOMAINDIR@|\'$(shell pwd)/po/build/locale\'|" \
3180 + -e "s|@GIT_TEST_POPATH@|\'$(shell pwd)/po\'|" \
3181 + -e "s|@GIT_TEST_TEMPLATE_DIR@|\'$(shell pwd)/templates/blt\'|" \
3182 + -e "s|@GIT_TEST_GITPERLLIB@|\'$(shell pwd)/perl/build/lib\'|" \
3183 + -e "s|@GIT_TEST_MERGE_TOOLS_DIR@|\'$(shell pwd)/mergetools\'|" \
3184 -e "s|@RUNTIME_PREFIX@|\'$(RUNTIME_PREFIX_OPTION)\'|" \
3185 -e "s|@GITWEBDIR@|\'$(gitwebdir_SQ)\'|" \
3186 -e "s|@USE_GETTEXT_SCHEME@|\'$(USE_GETTEXT_SCHEME)\'|" \
@@ -3205,6 +3210,10 @@ all:: $(TEST_PROGRAMS) $(test_bindir_programs) $(UNIT_TEST_PROGS) $(CLAR_TEST_PR
3210 $(test_bindir_programs): bin-wrappers/%: bin-wrappers/wrap-for-bin.sh
3211 $(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
3212 -e 's|@BUILD_DIR@|$(shell pwd)|' \
3213 + -e 's|@GIT_TEXTDOMAINDIR@|$(shell pwd)/po/build/locale|' \
3214 + -e 's|@GITPERLLIB@|$(shell pwd)/perl/build/lib|' \
3215 + -e 's|@MERGE_TOOLS_DIR@|$(shell pwd)/mergetools|' \
3216 + -e 's|@TEMPLATE_DIR@|$(shell pwd)/templates/blt|' \
3217 -e 's|@PROG@|$(shell pwd)/$(patsubst test-%,t/helper/test-%,$(@F))$(if $(filter-out $(BINDIR_PROGRAMS_NO_X),$(@F)),$(X),)|' < $< > $@ && \
3218 chmod +x $@
3219
bin-wrappers/wrap-for-bin.sh
+6 -5
@@ -4,21 +4,22 @@
4 # to run test suite against sandbox, but with only bindir-installed
5 # executables in PATH. The Makefile copies this into various
6 # files in bin-wrappers, substituting
7 -# @BUILD_DIR@ and @PROG@.
7 +# @BUILD_DIR@, @TEMPLATE_DIR@ and @PROG@.
8
9 GIT_EXEC_PATH='@BUILD_DIR@'
10 if test -n "$NO_SET_GIT_TEMPLATE_DIR"
11 then
12 unset GIT_TEMPLATE_DIR
13 else
14 - GIT_TEMPLATE_DIR='@BUILD_DIR@/templates/blt'
14 + GIT_TEMPLATE_DIR='@TEMPLATE_DIR@'
15 export GIT_TEMPLATE_DIR
16 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@'
20 PATH='@BUILD_DIR@/bin-wrappers:'"$PATH"
21
21 -export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
22 +export MERGE_TOOLS_DIR GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
23
24 case "$GIT_DEBUGGER" in
25 '')
contrib/buildsystems/CMakeLists.txt
+8
@@ -1100,6 +1100,9 @@ endforeach()
1100
1101 file(STRINGS ${CMAKE_SOURCE_DIR}/bin-wrappers/wrap-for-bin.sh content NEWLINE_CONSUME)
1102 string(REPLACE "@BUILD_DIR@" "${CMAKE_BINARY_DIR}" content "${content}")
1103 +string(REPLACE "@GIT_TEXTDOMAINDIR@" "${CMAKE_BINARY_DIR}/po/build/locale" content "${content}")
1104 +string(REPLACE "@GITPERLLIB@" "${CMAKE_BINARY_DIR}/perl/build/lib" content "${content}")
1105 +string(REPLACE "@MERGE_TOOLS_DIR@" "${CMAKE_SOURCE_DIR}/mergetools" content "${content}")
1106 string(REPLACE "@PROG@" "${CMAKE_BINARY_DIR}/git-cvsserver" content "${content}")
1107 file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
1108
@@ -1185,6 +1188,11 @@ string(REPLACE "@GIT_PERF_MAKE_COMMAND@" "" git_build_options "${git_build_optio
1188 string(REPLACE "@GIT_INTEROP_MAKE_OPTS@" "" git_build_options "${git_build_options}")
1189 string(REPLACE "@GIT_TEST_INDEX_VERSION@" "" git_build_options "${git_build_options}")
1190 string(REPLACE "@GIT_TEST_PERL_FATAL_WARNINGS@" "" git_build_options "${git_build_options}")
1191 +string(REPLACE "@GIT_TEST_TEXTDOMAINDIR@" "'${CMAKE_BINARY_DIR}/po/build/locale'" git_build_options "${git_build_options}")
1192 +string(REPLACE "@GIT_TEST_POPATH@" "'${CMAKE_BINARY_DIR}/po'" git_build_options "${git_build_options}")
1193 +string(REPLACE "@GIT_TEST_TEMPLATE_DIR@" "'${CMAKE_BINARY_DIR}/templates/blt'" git_build_options "${git_build_options}")
1194 +string(REPLACE "@GIT_TEST_GITPERLLIB@" "'${CMAKE_BINARY_DIR}/perl/build/lib'" git_build_options "${git_build_options}")
1195 +string(REPLACE "@GIT_TEST_MERGE_TOOLS_DIR@" "'${RUNTIME_PREFIX}'" git_build_options "${git_build_options}")
1196 string(REPLACE "@RUNTIME_PREFIX@" "'${RUNTIME_PREFIX}'" git_build_options "${git_build_options}")
1197 string(REPLACE "@GITWEBDIR@" "'${GITWEBDIR}'" git_build_options "${git_build_options}")
1198 string(REPLACE "@USE_GETTEXT_SCHEME@" "" git_build_options "${git_build_options}")
t/lib-gettext.sh
+2 -2
@@ -6,8 +6,8 @@
6
7 . ./test-lib.sh
8
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"
11 export GIT_TEXTDOMAINDIR GIT_PO_PATH
12
13 if test -n "$GIT_TEST_INSTALLED"
t/t7609-mergetool--lib.sh
+1 -1
@@ -7,7 +7,7 @@ Testing basic merge tools options'
7 . ./test-lib.sh
8
9 test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '
10 - . "$GIT_BUILD_DIR"/mergetools/vimdiff &&
10 + . "$GIT_TEST_MERGE_TOOLS_DIR"/vimdiff &&
11 run_unit_tests
12 '
13
t/test-lib.sh
+3 -3
@@ -1419,7 +1419,7 @@ else # normal case, use ../bin-wrappers only unless $with_dashes:
1419 PATH="$GIT_BUILD_DIR:$GIT_BUILD_DIR/t/helper:$PATH"
1420 fi
1421 fi
1422 -GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
1422 +GIT_TEMPLATE_DIR="$GIT_TEST_TEMPLATE_DIR"
1423 GIT_CONFIG_NOSYSTEM=1
1424 GIT_ATTR_NOSYSTEM=1
1425 GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/.."
@@ -1485,9 +1485,9 @@ then
1485 fi
1486 fi
1487
1488 -GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib
1488 +GITPERLLIB="$GIT_TEST_GITPERLLIB"
1489 export GITPERLLIB
1490 -test -d "$GIT_BUILD_DIR"/templates/blt || {
1490 +test -d "$GIT_TEMPLATE_DIR" || {
1491 BAIL_OUT "You haven't built things yet, have you?"
1492 }
1493