Skip to content

Commit 79f6ce5

Browse files
committed
Merge branch 'mo/bin-wrappers'
* mo/bin-wrappers: INSTALL: document a simpler way to run uninstalled builds run test suite without dashed git-commands in PATH build dashless "bin-wrappers" directory similar to installed bindir
2 parents 2df3299 + 9045801 commit 79f6ce5

File tree

6 files changed

+93
-32
lines changed

6 files changed

+93
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/GIT-CFLAGS
33
/GIT-GUI-VARS
44
/GIT-VERSION-FILE
5+
/bin-wrappers/
56
/git
67
/git-add
78
/git-add--interactive

INSTALL

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ Issues of note:
3838
Interactive Tools package still can install "git", but you can build it
3939
with --disable-transition option to avoid this.
4040

41-
- You can use git after building but without installing if you
42-
wanted to. Various git commands need to find other git
43-
commands and scripts to do their work, so you would need to
44-
arrange a few environment variables to tell them that their
45-
friends will be found in your built source area instead of at
46-
their standard installation area. Something like this works
47-
for me:
41+
- You can use git after building but without installing if you want
42+
to test drive it. Simply run git found in bin-wrappers directory
43+
in the build directory, or prepend that directory to your $PATH.
44+
This however is less efficient than running an installed git, as
45+
you always need an extra fork+exec to run any git subcommand.
46+
47+
It is still possible to use git without installing by setting a few
48+
environment variables, which was the way this was done
49+
traditionally. But using git found in bin-wrappers directory in
50+
the build directory is far simpler. As a historical reference, the
51+
old way went like this:
4852

4953
GIT_EXEC_PATH=`pwd`
5054
PATH=`pwd`:$PATH

Makefile

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,15 @@ ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
431431
# what 'all' will build but not install in gitexecdir
432432
OTHER_PROGRAMS = git$X
433433

434+
# what test wrappers are needed and 'install' will install, in bindir
435+
BINDIR_PROGRAMS_NEED_X += git
436+
BINDIR_PROGRAMS_NEED_X += git-upload-pack
437+
BINDIR_PROGRAMS_NEED_X += git-receive-pack
438+
BINDIR_PROGRAMS_NEED_X += git-upload-archive
439+
BINDIR_PROGRAMS_NEED_X += git-shell
440+
441+
BINDIR_PROGRAMS_NO_X += git-cvsserver
442+
434443
# Set paths to tools early so that they can be used for version tests.
435444
ifndef SHELL_PATH
436445
SHELL_PATH = /bin/sh
@@ -1762,19 +1771,30 @@ endif
17621771

17631772
### Testing rules
17641773

1765-
TEST_PROGRAMS += test-chmtime$X
1766-
TEST_PROGRAMS += test-ctype$X
1767-
TEST_PROGRAMS += test-date$X
1768-
TEST_PROGRAMS += test-delta$X
1769-
TEST_PROGRAMS += test-dump-cache-tree$X
1770-
TEST_PROGRAMS += test-genrandom$X
1771-
TEST_PROGRAMS += test-match-trees$X
1772-
TEST_PROGRAMS += test-parse-options$X
1773-
TEST_PROGRAMS += test-path-utils$X
1774-
TEST_PROGRAMS += test-sha1$X
1775-
TEST_PROGRAMS += test-sigchain$X
1774+
TEST_PROGRAMS_NEED_X += test-chmtime
1775+
TEST_PROGRAMS_NEED_X += test-ctype
1776+
TEST_PROGRAMS_NEED_X += test-date
1777+
TEST_PROGRAMS_NEED_X += test-delta
1778+
TEST_PROGRAMS_NEED_X += test-dump-cache-tree
1779+
TEST_PROGRAMS_NEED_X += test-genrandom
1780+
TEST_PROGRAMS_NEED_X += test-match-trees
1781+
TEST_PROGRAMS_NEED_X += test-parse-options
1782+
TEST_PROGRAMS_NEED_X += test-path-utils
1783+
TEST_PROGRAMS_NEED_X += test-sha1
1784+
TEST_PROGRAMS_NEED_X += test-sigchain
1785+
1786+
TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
17761787

1777-
all:: $(TEST_PROGRAMS)
1788+
test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(BINDIR_PROGRAMS_NO_X) $(TEST_PROGRAMS_NEED_X))
1789+
1790+
all:: $(TEST_PROGRAMS) $(test_bindir_programs)
1791+
1792+
bin-wrappers/%: wrap-for-bin.sh
1793+
@mkdir -p bin-wrappers
1794+
$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
1795+
-e 's|@@BUILD_DIR@@|$(shell pwd)|' \
1796+
-e 's|@@PROG@@|$(@F)|' < $< > $@ && \
1797+
chmod +x $@
17781798

17791799
# GNU make supports exporting all variables by "export" without parameters.
17801800
# However, the environment gets quite big, and some programs have problems
@@ -1835,11 +1855,13 @@ endif
18351855
gitexec_instdir_SQ = $(subst ','\'',$(gitexec_instdir))
18361856
export gitexec_instdir
18371857

1858+
install_bindir_programs := $(patsubst %,%$X,$(BINDIR_PROGRAMS_NEED_X)) $(BINDIR_PROGRAMS_NO_X)
1859+
18381860
install: all
18391861
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
18401862
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
18411863
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
1842-
$(INSTALL) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X git-shell$X git-cvsserver '$(DESTDIR_SQ)$(bindir_SQ)'
1864+
$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
18431865
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
18441866
ifndef NO_PERL
18451867
$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
@@ -1953,6 +1975,7 @@ clean:
19531975
$(LIB_FILE) $(XDIFF_LIB)
19541976
$(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X
19551977
$(RM) $(TEST_PROGRAMS)
1978+
$(RM) -r bin-wrappers
19561979
$(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags cscope*
19571980
$(RM) -r autom4te.cache
19581981
$(RM) config.log config.mak.autogen config.mak.append config.status config.cache

t/README

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ appropriately before running "make".
7575
As the names depend on the tests' file names, it is safe to
7676
run the tests with this option in parallel.
7777

78+
--with-dashes::
79+
By default tests are run without dashed forms of
80+
commands (like git-commit) in the PATH (it only uses
81+
wrappers from ../bin-wrappers). Use this option to include
82+
the build directory (..) in the PATH, which contains all
83+
the dashed forms of commands. This option is currently
84+
implied by other options like --valgrind and
85+
GIT_TEST_INSTALLED.
86+
7887
You can also set the GIT_TEST_INSTALLED environment variable to
7988
the bindir of an existing git installation to test that installation.
8089
You still need to have built this git sandbox, from which various

t/test-lib.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ do
105105
verbose=t; shift ;;
106106
-q|--q|--qu|--qui|--quie|--quiet)
107107
quiet=t; shift ;;
108+
--with-dashes)
109+
with_dashes=t; shift ;;
108110
--no-color)
109111
color=; shift ;;
110112
--no-python)
@@ -562,19 +564,8 @@ test_done () {
562564
# Test the binaries we have just built. The tests are kept in
563565
# t/ subdirectory and are run in 'trash directory' subdirectory.
564566
TEST_DIRECTORY=$(pwd)
565-
if test -z "$valgrind"
567+
if test -n "$valgrind"
566568
then
567-
if test -z "$GIT_TEST_INSTALLED"
568-
then
569-
PATH=$TEST_DIRECTORY/..:$PATH
570-
GIT_EXEC_PATH=$TEST_DIRECTORY/..
571-
else
572-
GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||
573-
error "Cannot run git from $GIT_TEST_INSTALLED."
574-
PATH=$GIT_TEST_INSTALLED:$TEST_DIRECTORY/..:$PATH
575-
GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
576-
fi
577-
else
578569
make_symlink () {
579570
test -h "$2" &&
580571
test "$1" = "$(readlink "$2")" || {
@@ -636,6 +627,24 @@ else
636627
PATH=$GIT_VALGRIND/bin:$PATH
637628
GIT_EXEC_PATH=$GIT_VALGRIND/bin
638629
export GIT_VALGRIND
630+
elif test -n "$GIT_TEST_INSTALLED" ; then
631+
GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||
632+
error "Cannot run git from $GIT_TEST_INSTALLED."
633+
PATH=$GIT_TEST_INSTALLED:$TEST_DIRECTORY/..:$PATH
634+
GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
635+
else # normal case, use ../bin-wrappers only unless $with_dashes:
636+
git_bin_dir="$TEST_DIRECTORY/../bin-wrappers"
637+
if ! test -x "$git_bin_dir/git" ; then
638+
if test -z "$with_dashes" ; then
639+
say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
640+
fi
641+
with_dashes=t
642+
fi
643+
PATH="$git_bin_dir:$PATH"
644+
GIT_EXEC_PATH=$TEST_DIRECTORY/..
645+
if test -n "$with_dashes" ; then
646+
PATH="$TEST_DIRECTORY/..:$PATH"
647+
fi
639648
fi
640649
GIT_TEMPLATE_DIR=$(pwd)/../templates/blt
641650
unset GIT_CONFIG

wrap-for-bin.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
# wrap-for-bin.sh: Template for git executable wrapper scripts
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@@.
8+
9+
GIT_EXEC_PATH='@@BUILD_DIR@@'
10+
GIT_TEMPLATE_DIR='@@BUILD_DIR@@/templates/blt'
11+
GITPERLLIB='@@BUILD_DIR@@/perl/blib/lib'
12+
PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH"
13+
export GIT_EXEC_PATH GIT_TEMPLATE_DIR GITPERLLIB PATH
14+
15+
exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"

0 commit comments

Comments
 (0)