Skip to content

Commit da3b8a3

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 e9b1ec9 commit da3b8a3

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
@@ -3180,6 +3180,11 @@ GIT-BUILD-OPTIONS: FORCE
31803180
-e "s|@GIT_INTEROP_MAKE_OPTS@|\'$(GIT_INTEROP_MAKE_OPTS)\'|" \
31813181
-e "s|@GIT_TEST_INDEX_VERSION@|\'$(GIT_TEST_INDEX_VERSION)\'|" \
31823182
-e "s|@GIT_TEST_PERL_FATAL_WARNINGS@|\'$(GIT_TEST_PERL_FATAL_WARNINGS)\'|" \
3183+
-e "s|@GIT_TEST_TEXTDOMAINDIR@|\'$(shell pwd)/po/build/locale\'|" \
3184+
-e "s|@GIT_TEST_POPATH@|\'$(shell pwd)/po\'|" \
3185+
-e "s|@GIT_TEST_TEMPLATE_DIR@|\'$(shell pwd)/templates/blt\'|" \
3186+
-e "s|@GIT_TEST_GITPERLLIB@|\'$(shell pwd)/perl/build/lib\'|" \
3187+
-e "s|@GIT_TEST_MERGE_TOOLS_DIR@|\'$(shell pwd)/mergetools\'|" \
31833188
-e "s|@RUNTIME_PREFIX@|\'$(RUNTIME_PREFIX_OPTION)\'|" \
31843189
-e "s|@GITWEBDIR@|\'$(gitwebdir_SQ)\'|" \
31853190
-e "s|@USE_GETTEXT_SCHEME@|\'$(USE_GETTEXT_SCHEME)\'|" \
@@ -3209,6 +3214,10 @@ all:: $(TEST_PROGRAMS) $(test_bindir_programs) $(UNIT_TEST_PROGS) $(CLAR_TEST_PR
32093214
$(test_bindir_programs): bin-wrappers/%: bin-wrappers/wrap-for-bin.sh
32103215
$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
32113216
-e 's|@BUILD_DIR@|$(shell pwd)|' \
3217+
-e 's|@GIT_TEXTDOMAINDIR@|$(shell pwd)/po/build/locale|' \
3218+
-e 's|@GITPERLLIB@|$(shell pwd)/perl/build/lib|' \
3219+
-e 's|@MERGE_TOOLS_DIR@|$(shell pwd)/mergetools|' \
3220+
-e 's|@TEMPLATE_DIR@|$(shell pwd)/templates/blt|' \
32123221
-e 's|@PROG@|$(patsubst test-%,t/helper/test-%,$(@F))$(if $(filter-out $(BINDIR_PROGRAMS_NO_X),$(@F)),$(X),)|' < $< > $@ && \
32133222
chmod +x $@
32143223

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

10941094
file(STRINGS ${CMAKE_SOURCE_DIR}/bin-wrappers/wrap-for-bin.sh content NEWLINE_CONSUME)
10951095
string(REPLACE "@BUILD_DIR@" "${CMAKE_BINARY_DIR}" content "${content}")
1096+
string(REPLACE "@GIT_TEXTDOMAINDIR@" "${CMAKE_BINARY_DIR}/po/build/locale" content "${content}")
1097+
string(REPLACE "@GITPERLLIB@" "${CMAKE_BINARY_DIR}/perl/build/lib" content "${content}")
1098+
string(REPLACE "@MERGE_TOOLS_DIR@" "${CMAKE_SOURCE_DIR}/mergetools" content "${content}")
10961099
string(REPLACE "@PROG@" "git-cvsserver" content "${content}")
10971100
file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
10981101

@@ -1178,6 +1181,11 @@ string(REPLACE "@GIT_PERF_MAKE_COMMAND@" "" git_build_options "${git_build_optio
11781181
string(REPLACE "@GIT_INTEROP_MAKE_OPTS@" "" git_build_options "${git_build_options}")
11791182
string(REPLACE "@GIT_TEST_INDEX_VERSION@" "" git_build_options "${git_build_options}")
11801183
string(REPLACE "@GIT_TEST_PERL_FATAL_WARNINGS@" "" git_build_options "${git_build_options}")
1184+
string(REPLACE "@GIT_TEST_TEXTDOMAINDIR@" "'${CMAKE_BINARY_DIR}/po/build/locale'" git_build_options "${git_build_options}")
1185+
string(REPLACE "@GIT_TEST_POPATH@" "'${CMAKE_BINARY_DIR}/po'" git_build_options "${git_build_options}")
1186+
string(REPLACE "@GIT_TEST_TEMPLATE_DIR@" "'${CMAKE_BINARY_DIR}/templates/blt'" git_build_options "${git_build_options}")
1187+
string(REPLACE "@GIT_TEST_GITPERLLIB@" "'${CMAKE_BINARY_DIR}/perl/build/lib'" git_build_options "${git_build_options}")
1188+
string(REPLACE "@GIT_TEST_MERGE_TOOLS_DIR@" "'${RUNTIME_PREFIX}'" git_build_options "${git_build_options}")
11811189
string(REPLACE "@RUNTIME_PREFIX@" "'${RUNTIME_PREFIX}'" git_build_options "${git_build_options}")
11821190
string(REPLACE "@GITWEBDIR@" "'${GITWEBDIR}'" git_build_options "${git_build_options}")
11831191
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
@@ -1440,7 +1440,7 @@ else # normal case, use ../bin-wrappers only unless $with_dashes:
14401440
PATH="$GIT_BUILD_DIR:$GIT_BUILD_DIR/t/helper:$PATH"
14411441
fi
14421442
fi
1443-
GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
1443+
GIT_TEMPLATE_DIR="$GIT_TEST_TEMPLATE_DIR"
14441444
GIT_CONFIG_NOSYSTEM=1
14451445
GIT_ATTR_NOSYSTEM=1
14461446
GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/.."
@@ -1506,9 +1506,9 @@ then
15061506
fi
15071507
fi
15081508

1509-
GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib
1509+
GITPERLLIB="$GIT_TEST_GITPERLLIB"
15101510
export GITPERLLIB
1511-
test -d "$GIT_BUILD_DIR"/templates/blt || {
1511+
test -d "$GIT_TEMPLATE_DIR" || {
15121512
BAIL_OUT "You haven't built things yet, have you?"
15131513
}
15141514

0 commit comments

Comments
 (0)