Files
git/t/interop/interop-lib.sh
Jeff King 22ef5f02a8 t/interop: allow per-version make options
Building older versions of Git may require tweaking some build knobs. In
particular, very old versions of Git will fail to build with recent
OpenSSL, because the bignum type switched from a struct to a pointer.

The i5500 interop test uses Git v1.0.0 by default, which triggers this
problem. You can work around it by setting NO_OPENSSL in your
GIT_TEST_MAKE_OPTS variable. But there are two downsides:

  1. You have to know to do this, and it's not at all obvious.

  2. That sets the options for _all_ versions of Git that we build. And
     it's possible for two versions to require conflicting knobs. E.g.,
     building with "make NO_OPENSSL=Nope OPENSSL_SHA1=Yes" causes
     imap-send.c to barf, because it declares a fallback typedef for SSL.
     This is something we may want to fix, but of course many historical
     versions are affected, and the interop scripts should be flexible
     enough to build everything.

So let's introduce per-version make options, along with the ability for
scripts to specify knobs that match their default versions. That should
make everything build out of the box, but also allow testers flexibility
if they are testing interoperability between non-default versions.

We'll set NO_OPENSSL by default for v1.0.0 in i5500. It doesn't have to
worry about the conflict with OPENSSL_SHA1 because imap-send did not
exist back then (but if it did, it could also just explicitly use a
different hash implementation).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-09-12 13:27:36 -07:00

95 lines
2.0 KiB
Bash

# 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 $2 $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}
MAKE_OPTS_A=${GIT_INTEROP_MAKE_OPTS_A:-$MAKE_OPTS_A}
MAKE_OPTS_B=${GIT_INTEROP_MAKE_OPTS_B:-$MAKE_OPTS_B}
if ! DIR_A=$(build_version "$VERSION_A" "$MAKE_OPTS_A") ||
! DIR_B=$(build_version "$VERSION_B" "$MAKE_OPTS_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"