Skip to content

Commit b76e914

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 019064e commit b76e914

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
@@ -35,6 +35,11 @@ GIT_PERF_MAKE_COMMAND=@GIT_PERF_MAKE_COMMAND@
3535
GIT_INTEROP_MAKE_OPTS=@GIT_INTEROP_MAKE_OPTS@
3636
GIT_TEST_INDEX_VERSION=@GIT_TEST_INDEX_VERSION@
3737
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@
3843
RUNTIME_PREFIX=@RUNTIME_PREFIX@
3944
GITWEBDIR=@GITWEBDIR@
4045
USE_GETTEXT_SCHEME=@USE_GETTEXT_SCHEME@

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,6 +3173,11 @@ GIT-BUILD-OPTIONS: FORCE
31733173
-e "s|@GIT_INTEROP_MAKE_OPTS@|\'$(GIT_INTEROP_MAKE_OPTS)\'|" \
31743174
-e "s|@GIT_TEST_INDEX_VERSION@|\'$(GIT_TEST_INDEX_VERSION)\'|" \
31753175
-e "s|@GIT_TEST_PERL_FATAL_WARNINGS@|\'$(GIT_TEST_PERL_FATAL_WARNINGS)\'|" \
3176+
-e "s|@GIT_TEST_TEXTDOMAINDIR@|\'$(shell pwd)/po/build/locale\'|" \
3177+
-e "s|@GIT_TEST_POPATH@|\'$(shell pwd)/po\'|" \
3178+
-e "s|@GIT_TEST_TEMPLATE_DIR@|\'$(shell pwd)/templates/blt\'|" \
3179+
-e "s|@GIT_TEST_GITPERLLIB@|\'$(shell pwd)/perl/build/lib\'|" \
3180+
-e "s|@GIT_TEST_MERGE_TOOLS_DIR@|\'$(shell pwd)/mergetools\'|" \
31763181
-e "s|@RUNTIME_PREFIX@|\'$(RUNTIME_PREFIX)\'|" \
31773182
-e "s|@GITWEBDIR@|\'$(gitwebdir_SQ)\'|" \
31783183
-e "s|@USE_GETTEXT_SCHEME@|\'$(USE_GETTEXT_SCHEME)\'|" \
@@ -3202,6 +3207,10 @@ all:: $(TEST_PROGRAMS) $(test_bindir_programs) $(UNIT_TEST_PROGS) $(CLAR_TEST_PR
32023207
$(test_bindir_programs): bin-wrappers/%: bin-wrappers/wrap-for-bin.sh
32033208
$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
32043209
-e 's|@BUILD_DIR@|$(shell pwd)|' \
3210+
-e 's|@GIT_TEXTDOMAINDIR@|$(shell pwd)/po/build/locale|' \
3211+
-e 's|@GITPERLLIB@|$(shell pwd)/perl/build/lib|' \
3212+
-e 's|@MERGE_TOOLS_DIR@|$(shell pwd)/mergetools|' \
3213+
-e 's|@TEMPLATE_DIR@|$(shell pwd)/templates/blt|' \
32053214
-e 's|@PROG@|$(patsubst test-%,t/helper/test-%,$(@F))$(if $(filter-out $(BINDIR_PROGRAMS_NO_X),$(@F)),$(X),)|' < $< > $@ && \
32063215
chmod +x $@
32073216

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
@@ -1066,6 +1066,9 @@ endforeach()
10661066

10671067
file(STRINGS ${CMAKE_SOURCE_DIR}/bin-wrappers/wrap-for-bin.sh content NEWLINE_CONSUME)
10681068
string(REPLACE "@BUILD_DIR@" "${CMAKE_BINARY_DIR}" content "${content}")
1069+
string(REPLACE "@GIT_TEXTDOMAINDIR@" "${CMAKE_BINARY_DIR}/po/build/locale" content "${content}")
1070+
string(REPLACE "@GITPERLLIB@" "${CMAKE_BINARY_DIR}/perl/build/lib" content "${content}")
1071+
string(REPLACE "@MERGE_TOOLS_DIR@" "${CMAKE_SOURCE_DIR}/mergetools" content "${content}")
10691072
string(REPLACE "@PROG@" "git-cvsserver" content "${content}")
10701073
file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
10711074

@@ -1151,6 +1154,11 @@ string(REPLACE "@GIT_PERF_MAKE_COMMAND@" "" git_build_options "${git_build_optio
11511154
string(REPLACE "@GIT_INTEROP_MAKE_OPTS@" "" git_build_options "${git_build_options}")
11521155
string(REPLACE "@GIT_TEST_INDEX_VERSION@" "" git_build_options "${git_build_options}")
11531156
string(REPLACE "@GIT_TEST_PERL_FATAL_WARNINGS@" "" git_build_options "${git_build_options}")
1157+
string(REPLACE "@GIT_TEST_TEXTDOMAINDIR@" "${CMAKE_BINARY_DIR}/po/build/locale" git_build_options "${git_build_options}")
1158+
string(REPLACE "@GIT_TEST_POPATH@" "${CMAKE_BINARY_DIR}/po" git_build_options "${git_build_options}")
1159+
string(REPLACE "@GIT_TEST_TEMPLATE_DIR@" "${CMAKE_BINARY_DIR}/templates/blt" git_build_options "${git_build_options}")
1160+
string(REPLACE "@GIT_TEST_GITPERLLIB@" "${CMAKE_BINARY_DIR}/perl/build/lib" git_build_options "${git_build_options}")
1161+
string(REPLACE "@GIT_TEST_MERGE_TOOLS_DIR@" "${RUNTIME_PREFIX}" git_build_options "${git_build_options}")
11541162
string(REPLACE "@RUNTIME_PREFIX@" "${RUNTIME_PREFIX}" git_build_options "${git_build_options}")
11551163
string(REPLACE "@GITWEBDIR@" "${GITWEBDIR}" git_build_options "${git_build_options}")
11561164
string(REPLACE "@USE_GETTEXT_SCHEME@" "" git_build_options "${git_build_options}")

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)