#!/usr/bin/env bats load test_helper export PYTHON_BUILD_CACHE_PATH="$TMP/cache" export MAKE=make export MAKE_OPTS="-j 2" export CC=cc export PYTHON_BUILD_HTTP_CLIENT="curl" export TMP_FIXTURES="$TMP/fixtures" setup() { mkdir -p "$INSTALL_ROOT" stub md5 false stub curl false } executable() { local file="$1" mkdir -p "${file%/*}" cat > "$file" chmod +x "$file" } cached_tarball() { mkdir -p "$PYTHON_BUILD_CACHE_PATH" pushd "$PYTHON_BUILD_CACHE_PATH" >/dev/null tarball "$@" popd >/dev/null } tarball() { local name="$1" local path="$PWD/$name" local configure="$path/configure" shift 1 executable "$configure" <> build.log echo "$name: \$@" \${PYTHONOPT:+PYTHONOPT=\$PYTHONOPT} >> build.log OUT for file; do mkdir -p "$(dirname "${path}/${file}")" touch "${path}/${file}" done tar czf "${path}.tar.gz" -C "${path%/*}" "$name" } stub_make_install() { stub "$MAKE" \ " : echo \"$MAKE \$@\" >> build.log" \ "install : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'" } assert_build_log() { run cat "$INSTALL_ROOT/build.log" assert_output } install_patch() { local name="$1" local patch="$2" [ -n "$patch" ] || patch="python.patch" mkdir -p "${TMP_FIXTURES}/${name%/*}/patches/${name##*/}/${patch%/*}" cat > "${TMP_FIXTURES}/${name%/*}/patches/${name##*/}/${patch}" } install_tmp_fixture() { local args while [ "${1#-}" != "$1" ]; do args="$args $1" shift 1 done local name="$1" local destination="$2" [ -n "$destination" ] || destination="$INSTALL_ROOT" # Copy fixture to temporary path mkdir -p "${TMP_FIXTURES}/${name%/*}" cp "${FIXTURE_ROOT}/${name}" "${TMP_FIXTURES}/${name}" run python-build $args "$TMP_FIXTURES/$name" "$destination" } resolve_link() { $(type -P greadlink readlink | head -n1) "$1" } run_inline_definition_with_name() { local definition_name="build-definition" case "$1" in "--name="* ) local definition_name="${1#--name=}" shift 1 ;; esac local definition="${TMP}/${definition_name}" cat > "$definition" run python-build "$definition" "${1:-$INSTALL_ROOT}" } @test "apply built-in python patch before building" { cached_tarball "Python-3.6.2" stub brew false stub_make_install stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log' echo | install_patch definitions/vanilla-python "Python-3.6.2/empty.patch" # yyuu/pyenv#257 stub uname '-s : echo Linux' stub uname '-s : echo Linux' TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null assert_success assert_build_log <> build.log' echo "foo" | install_patch definitions/vanilla-python "Python-3.6.2/foo.patch" echo "bar" | install_patch definitions/vanilla-python "Python-3.6.2/bar.patch" echo "baz" | install_patch definitions/vanilla-python "Python-3.6.2/baz.patch" for i in {1..2}; do stub uname '-s : echo Linux'; done TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null assert_success assert_build_log <> build.log" \ " : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'" for i in {1..4}; do stub uname '-s : echo Darwin'; done PYTHON_MAKE_INSTALL_TARGET="altinstall" TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null assert_success assert_build_log < "${INSTALL_ROOT}/bin/python" #!$BASH echo "python \$@" >> "${INSTALL_ROOT}/build.log" OUT chmod +x "${INSTALL_ROOT}/bin/python" PYTHON_MAKE_INSTALL_TARGET="" TMPDIR="$TMP" run_inline_definition < "${INSTALL_ROOT}/bin/python" #!$BASH echo "python \$@" >> "${INSTALL_ROOT}/build.log" OUT chmod +x "${INSTALL_ROOT}/bin/python" PYTHON_MAKE_INSTALL_TARGET="altinstall" TMPDIR="$TMP" run_inline_definition <> build.log" \ " : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'" PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null assert_success assert_build_log <