summaryrefslogtreecommitdiffstats
path: root/t/interop/interop-lib.sh
blob: 3e0a2911d4f9baa889eef85877a6332b27015dfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Interoperability testing framework. Each script should source
# this after setting default $VERSION_A and $VERSION_B variables.

. ../../GIT-BUILD-OPTIONS
INTEROP_ROOT=$(pwd)
BUILD_ROOT=$INTEROP_ROOT/build

build_version () {
	if test -z "$1"
	then
		echo >&2 "error: test script did not set default versions"
		return 1
	fi

	if test "$1" = "."
	then
		git rev-parse --show-toplevel
		return 0
	fi

	sha1=$(git rev-parse "$1^{tree}") || return 1
	dir=$BUILD_ROOT/$sha1

	if test -e "$dir/.built"
	then
		echo "$dir"
		return 0
	fi

	echo >&2 "==> Building $1..."

	mkdir -p "$dir" || return 1

	(cd "$(git rev-parse --show-cdup)" && git archive --format=tar "$sha1") |
	(cd "$dir" && tar x) ||
	return 1

	for config in config.mak config.mak.autogen config.status
	do
		if test -e "$INTEROP_ROOT/../../$config"
		then
			cp "$INTEROP_ROOT/../../$config" "$dir/" || return 1
		fi
	done

	(
		cd "$dir" &&
		make $GIT_INTEROP_MAKE_OPTS >&2 &&
		touch .built
	) || return 1

	echo "$dir"
}

# Old versions of git don't have bin-wrappers, so let's give a rough emulation.
wrap_git () {
	write_script "$1" <<-EOF
	GIT_EXEC_PATH="$2"
	export GIT_EXEC_PATH
	PATH="$2:\$PATH"
	export GIT_EXEC_PATH
	exec git "\$@"
	EOF
}

generate_wrappers () {
	mkdir -p .bin &&
	wrap_git .bin/git.a "$DIR_A" &&
	wrap_git .bin/git.b "$DIR_B" &&
	write_script .bin/git <<-\EOF &&
	echo >&2 fatal: test tried to run generic git
	exit 1
	EOF
	PATH=$(pwd)/.bin:$PATH
}

VERSION_A=${GIT_TEST_VERSION_A:-$VERSION_A}
VERSION_B=${GIT_TEST_VERSION_B:-$VERSION_B}

if ! DIR_A=$(build_version "$VERSION_A") ||
   ! DIR_B=$(build_version "$VERSION_B")
then
	echo >&2 "fatal: unable to build git versions"
	exit 1
fi

TEST_DIRECTORY=$INTEROP_ROOT/..
TEST_OUTPUT_DIRECTORY=$INTEROP_ROOT
TEST_NO_CREATE_REPO=t
. "$TEST_DIRECTORY"/test-lib.sh

generate_wrappers || die "unable to set up interop test environment"