Skip to content

Commit

Permalink
Fixes prepare_tf_dep.sh for OSX.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 447850354
  • Loading branch information
broken authored and rtg0795 committed May 17, 2022
1 parent ac01c45 commit c955c9c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions oss_scripts/prepare_tf_dep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,31 @@ elif (which python3) | grep -q "python3"; then
installed_python="python3"
fi

ext=""
osname="$(uname -s | tr 'A-Z' 'a-z')"
if [[ "${osname}" == "darwin" ]]; then
ext='""'
fi

# update setup.nightly.py with tf version
tf_version=$($installed_python -c 'import tensorflow as tf; print(tf.__version__)')
echo "$tf_version"
sed -E -i "s/project_version = 'REPLACE_ME'/project_version = '${tf_version}'/" oss_scripts/pip_package/setup.nightly.py
sed -i $ext "s/project_version = 'REPLACE_ME'/project_version = '${tf_version}'/" oss_scripts/pip_package/setup.nightly.py
# update __version__
sed -E -i "s/__version__ = .*\$/__version__ = \"${tf_version}\"/" tensorflow_text/__init__.py
sed -i $ext "s/__version__ = .*\$/__version__ = \"${tf_version}\"/" tensorflow_text/__init__.py

# Get commit sha of installed tensorflow
# For some unknown reason this now needs to be split into two commands on Windows
short_commit_sha=$($installed_python -c 'import tensorflow as tf; print(tf.__git_version__)' | tail -1)
short_commit_sha=$(echo $short_commit_sha | grep -oP '(?<=-g)[0-9a-f]*$')
if [[ "${osname}" == "darwin" ]]; then
short_commit_sha=$(echo $short_commit_sha | perl -nle 'print $& while m{(?<=-g)[0-9a-f]*$}g')
else
short_commit_sha=$(echo $short_commit_sha | grep -oP '(?<=-g)[0-9a-f]*$')
fi
commit_sha=$(curl -SsL https://github.com/tensorflow/tensorflow/commit/${short_commit_sha} | grep sha-block | grep commit | sed -e 's/.*\([a-f0-9]\{40\}\).*/\1/')

# Update TF dependency to installed tensorflow
sed -E -i "s/strip_prefix = \"tensorflow-2.\+\",/strip_prefix = \"tensorflow-${commit_sha}\",/" WORKSPACE
sed -E -i "s|\"https://github.com/tensorflow/tensorflow/archive/.\+\.zip\"|\"https://github.com/tensorflow/tensorflow/archive/${commit_sha}.zip\"|" WORKSPACE
sed -E -i $ext "s/strip_prefix = \"tensorflow-2.+\",/strip_prefix = \"tensorflow-${commit_sha}\",/" WORKSPACE
sed -E -i $ext "s|\"https://github.com/tensorflow/tensorflow/archive/v.+\.zip\"|\"https://github.com/tensorflow/tensorflow/archive/${commit_sha}.zip\"|" WORKSPACE
prev_shasum=$(grep -A 1 -e "strip_prefix.*tensorflow-" WORKSPACE | tail -1 | awk -F '"' '{print $2}')
sed -i "s/sha256 = \"${prev_shasum}\",//" WORKSPACE
sed -i $ext "s/sha256 = \"${prev_shasum}\",//" WORKSPACE

0 comments on commit c955c9c

Please sign in to comment.