Skip to content

Commit 7e0730c

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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 023c337 commit 7e0730c

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
@@ -3176,6 +3176,11 @@ GIT-BUILD-OPTIONS: FORCE
31763176
-e "s|@GIT_INTEROP_MAKE_OPTS@|\'$(GIT_INTEROP_MAKE_OPTS)\'|" \
31773177
-e "s|@GIT_TEST_INDEX_VERSION@|\'$(GIT_TEST_INDEX_VERSION)\'|" \
31783178
-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\'|" \
31793184
-e "s|@RUNTIME_PREFIX@|\'$(RUNTIME_PREFIX_OPTION)\'|" \
31803185
-e "s|@GITWEBDIR@|\'$(gitwebdir_SQ)\'|" \
31813186
-e "s|@USE_GETTEXT_SCHEME@|\'$(USE_GETTEXT_SCHEME)\'|" \
@@ -3205,6 +3210,10 @@ all:: $(TEST_PROGRAMS) $(test_bindir_programs) $(UNIT_TEST_PROGS) $(CLAR_TEST_PR
32053210
$(test_bindir_programs): bin-wrappers/%: bin-wrappers/wrap-for-bin.sh
32063211
$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
32073212
-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|' \
32083217
-e 's|@PROG@|$(shell pwd)/$(patsubst test-%,t/helper/test-%,$(@F))$(if $(filter-out $(BINDIR_PROGRAMS_NO_X),$(@F)),$(X),)|' < $< > $@ && \
32093218
chmod +x $@
32103219

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

11011101
file(STRINGS ${CMAKE_SOURCE_DIR}/bin-wrappers/wrap-for-bin.sh content NEWLINE_CONSUME)
11021102
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}")
11031106
string(REPLACE "@PROG@" "${CMAKE_BINARY_DIR}/git-cvsserver" content "${content}")
11041107
file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
11051108

@@ -1185,6 +1188,11 @@ string(REPLACE "@GIT_PERF_MAKE_COMMAND@" "" git_build_options "${git_build_optio
11851188
string(REPLACE "@GIT_INTEROP_MAKE_OPTS@" "" git_build_options "${git_build_options}")
11861189
string(REPLACE "@GIT_TEST_INDEX_VERSION@" "" git_build_options "${git_build_options}")
11871190
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}")
11881196
string(REPLACE "@RUNTIME_PREFIX@" "'${RUNTIME_PREFIX}'" git_build_options "${git_build_options}")
11891197
string(REPLACE "@GITWEBDIR@" "'${GITWEBDIR}'" git_build_options "${git_build_options}")
11901198
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
@@ -7,7 +7,7 @@ Testing basic merge tools options'
77
. ./test-lib.sh
88

99
test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '
10-
. "$GIT_BUILD_DIR"/mergetools/vimdiff &&
10+
. "$GIT_TEST_MERGE_TOOLS_DIR"/vimdiff &&
1111
run_unit_tests
1212
'
1313

t/test-lib.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ else # normal case, use ../bin-wrappers only unless $with_dashes:
14191419
PATH="$GIT_BUILD_DIR:$GIT_BUILD_DIR/t/helper:$PATH"
14201420
fi
14211421
fi
1422-
GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
1422+
GIT_TEMPLATE_DIR="$GIT_TEST_TEMPLATE_DIR"
14231423
GIT_CONFIG_NOSYSTEM=1
14241424
GIT_ATTR_NOSYSTEM=1
14251425
GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/.."
@@ -1485,9 +1485,9 @@ then
14851485
fi
14861486
fi
14871487

1488-
GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib
1488+
GITPERLLIB="$GIT_TEST_GITPERLLIB"
14891489
export GITPERLLIB
1490-
test -d "$GIT_BUILD_DIR"/templates/blt || {
1490+
test -d "$GIT_TEMPLATE_DIR" || {
14911491
BAIL_OUT "You haven't built things yet, have you?"
14921492
}
14931493

0 commit comments

Comments
 (0)