[Bazel] Use pyenv to select Python 3.9.5 on our linux/bazel builds. (#10009)

We still need to use python2 when running autotools.
pull/10010/head
David L. Jones 3 years ago committed by GitHub
parent 30f6c7851b
commit bb27447f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      kokoro/common/pyenv.sh
  2. 7
      kokoro/linux/bazel/build.sh
  3. 37
      kokoro/linux/bazel_distcheck/build.sh

@ -0,0 +1,16 @@
# Shared logic to choose a Python version with pyenv.
#
# This file should be `source`d.
# Requested version of Python can be overridden by env variable.
: ${PYTHON_VERSION:=3.9.5}
if pyenv --version >/dev/null ; then
eval "$(pyenv init -)"
if ! pyenv global ${PYTHON_VERSION}; then
echo "Python ${PYTHON_VERSION} is not available. Versions available:" >&2
pyenv versions >&2
exit 1
fi
fi
echo "Using $(python --version || python3 --version)"

@ -9,6 +9,7 @@ bazel version
# Change to repo root
cd $(dirname $0)/../../..
source kokoro/common/pyenv.sh
git submodule update --init --recursive
@ -24,7 +25,11 @@ bazel test \
@com_google_protobuf_examples//...
# Verify that we can build successfully from generated tar files.
./autogen.sh && ./configure && make -j$(nproc) dist
(
pyenv versions
pyenv shell 2.7.9 # python2 required for old googletest autotools support
./autogen.sh && ./configure && make -j$(nproc) dist
)
DIST=`ls *.tar.gz`
tar -xf $DIST
cd ${DIST//.tar.gz}

@ -23,14 +23,17 @@ TEST_TARGETS=(
@com_google_protobuf_examples//...
)
CONTAINER_NAME=gcr.io/protobuf-build/bazel/linux
CONTAINER_VERSION=5.1.1-e41ccfa1648716433276ebe077c665796550fcbb
use_bazel.sh 5.0.0 || true
bazel version
# Change to repo root
cd $(dirname $0)/../../..
source kokoro/common/pyenv.sh
# Build distribution archive
date
bazel build //pkg:dist_all_tar
bazel shutdown
# Construct temp directory for running the dist build.
# If you want to run locally and keep the build dir, create a directory
@ -43,43 +46,19 @@ if [[ -z ${DIST_WORK_ROOT:-} ]]; then
trap dist_cleanup EXIT
fi
# Let Bazel share the distdir.
TMP_DISTDIR=${DIST_WORK_ROOT}/bazel-distdir
mkdir -p ${TMP_DISTDIR}
# Build distribution archive
date
bazel fetch --distdir=${TMP_DISTDIR} //pkg:dist_all_tar
bazel build --distdir=${TMP_DISTDIR} //pkg:dist_all_tar
DIST_ARCHIVE=$(readlink $(bazel info bazel-bin)/pkg/dist_all_tar.tar.gz)
bazel shutdown
# The `pkg_tar` rule emits a symlink based on the rule name. The actual
# file is named with the current version.
date
echo "Resolved archive path: ${DIST_ARCHIVE}"
# Extract the dist archive.
date
DIST_WORKSPACE=${DIST_WORK_ROOT}/protobuf
mkdir -p ${DIST_WORKSPACE}
tar -C ${DIST_WORKSPACE} --strip-components=1 -axf ${DIST_ARCHIVE}
tar -C ${DIST_WORKSPACE} --strip-components=1 -axf bazel-bin/pkg/dist_all_tar.tar.gz
# Perform build steps in the extracted dist sources.
cd ${DIST_WORKSPACE}
FAILED=false
until docker pull gcr.io/protobuf-build/bazel/linux:${CONTAINER_VERSION}; do
sleep 10
done
date
docker run --rm \
-v ${DIST_WORKSPACE}:/workspace \
-v ${TMP_DISTDIR}:${TMP_DISTDIR} \
${CONTAINER_NAME}:${CONTAINER_VERSION} \
test --distdir=${TMP_DISTDIR} --test_output=errors -k \
bazel test --test_output=errors -k \
"${BUILD_ONLY_TARGETS[@]}" "${TEST_TARGETS[@]}" || FAILED=true
if ${FAILED}; then

Loading…
Cancel
Save