Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install_bazel.sh script to make it easy to install the correctly needed version of Bazel. #946

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions oss_scripts/install_bazel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
set -e # fail and exit on any command erroring
set -x # print evaluated commands

# Read the bazel version from the path; slowly moving up parents
while [[ $PWD != / && -z $(find ~+/ -maxdepth 1 -type f -name .bazelversion) ]]
do cd ..; done
BAZEL_VERSION=$(<.bazelversion)
if [[ -z "$BAZEL_VERSION" ]]; then exit 1; fi

# If (due to e.g., $PATH settings), bazel is actually running bazelisk,
# https://github.com/bazelbuild/bazelisk, make sure it downloads the bazel
# version we want (not the latest one, which we haven't tested yet).
export USE_BAZEL_VERSION=${BAZEL_VERSION}

# Install the given bazel version.
function update_bazel_version {
local BAZEL_VERSION=$1
local BAZEL_URL=https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}
case "$(uname -s)" in
MSYS_NT*)
# Windows is a special case: there is no installer, just a big .exe, see
# https://docs.bazel.build/versions/master/install-windows.html
local INSTALL_DIR=`pwd`/bazel-${BAZEL_VERSION}
mkdir -p ${INSTALL_DIR}
wget -q ${BAZEL_URL}/bazel-${BAZEL_VERSION}-windows-x86_64.exe \
-O ${INSTALL_DIR}/bazel.exe
PATH=${INSTALL_DIR}:$PATH
return
;;
Darwin)
echo "Delete bazel install cache to address http://b/161389448"
rm -fr /var/tmp/_bazel_kbuilder/install/9be5dadb2a2b38082dbe665bf2db6464
local OS_TOKEN=darwin
;;
Linux)
local OS_TOKEN=linux
;;
*)
die "Unknown OS: $(uname -s)"
;;
esac
local BAZEL_INSTALLER=bazel-${BAZEL_VERSION}-installer-${OS_TOKEN}-x86_64.sh
rm -f ${BAZEL_INSTALLER}
curl -fSsL -O ${BAZEL_URL}/${BAZEL_INSTALLER}
chmod +x ${BAZEL_INSTALLER}

# Due to --user, the installer puts the bazel binary into $HOME/bin (where we
# have access rights). We add that at the top of our $PATH.
./${BAZEL_INSTALLER} --user
PATH=$HOME/bin:$PATH
rm -f ${BAZEL_INSTALLER}
}

# First check if new version of Bazel needs to be installed.
# Install different bazel if needed
installed_bazel_version=$(bazel version | grep label | sed -e 's/.*: //')
if [ "$installed_bazel_version" == "$BAZEL_VERSION" ]; then
echo "Bazel version ${BAZEL_VERSION} is already correctly installed."
else
update_bazel_version ${BAZEL_VERSION}
which bazel
bazel version
fi
10 changes: 10 additions & 0 deletions oss_scripts/run_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ fi
# Run configure.
source oss_scripts/configure.sh

# Verify correct version of Bazel
installed_bazel_version=$(bazel version | grep label | sed -e 's/.*: //')
tf_bazel_version=$(cat .bazelversion)
if [ "$installed_bazel_version" != "$tf_bazel_version" ]; then
echo "Incorrect version of Bazel installed."
echo "Version $tf_bazel_version should be installed, but found version ${installed_bazel_version}."
echo "Run oss_scripts/install_bazel.sh or manually install the correct version."
exit 1
fi

# Set tensorflow version
if [[ $osname != "Darwin" ]] || [[ ! $(sysctl -n machdep.cpu.brand_string) =~ "Apple" ]]; then
source oss_scripts/prepare_tf_dep.sh
Expand Down
16 changes: 16 additions & 0 deletions oss_scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ set -x # print commands as they are executed
set -e # fail and exit on any command erroring

./oss_scripts/configure.sh

# Verify correct version of Bazel
installed_bazel_version=$(bazel version | grep label | sed -e 's/.*: //')
tf_bazel_version=$(cat .bazelversion)
if [ "$installed_bazel_version" != "$tf_bazel_version" ]; then
echo "Incorrect version of Bazel installed."
echo "Version $tf_bazel_version should be installed, but found version ${installed_bazel_version}."
echo "Run oss_scripts/install_bazel.sh or manually install the correct version."
exit 1
fi

# Set tensorflow version
if [[ $osname != "Darwin" ]] || [[ ! $(sysctl -n machdep.cpu.brand_string) =~ "Apple" ]]; then
source oss_scripts/prepare_tf_dep.sh
fi

bazel test --test_output=errors --keep_going --jobs=1 tensorflow_text:all