Skip to content

Commit c955c9c

Browse files
brokenrtg0795
authored andcommitted
Fixes prepare_tf_dep.sh for OSX.
PiperOrigin-RevId: 447850354
1 parent ac01c45 commit c955c9c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

oss_scripts/prepare_tf_dep.sh

+16-6
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,31 @@ elif (which python3) | grep -q "python3"; then
77
installed_python="python3"
88
fi
99

10+
ext=""
11+
osname="$(uname -s | tr 'A-Z' 'a-z')"
12+
if [[ "${osname}" == "darwin" ]]; then
13+
ext='""'
14+
fi
15+
1016
# update setup.nightly.py with tf version
1117
tf_version=$($installed_python -c 'import tensorflow as tf; print(tf.__version__)')
1218
echo "$tf_version"
13-
sed -E -i "s/project_version = 'REPLACE_ME'/project_version = '${tf_version}'/" oss_scripts/pip_package/setup.nightly.py
19+
sed -i $ext "s/project_version = 'REPLACE_ME'/project_version = '${tf_version}'/" oss_scripts/pip_package/setup.nightly.py
1420
# update __version__
15-
sed -E -i "s/__version__ = .*\$/__version__ = \"${tf_version}\"/" tensorflow_text/__init__.py
21+
sed -i $ext "s/__version__ = .*\$/__version__ = \"${tf_version}\"/" tensorflow_text/__init__.py
1622

1723
# Get commit sha of installed tensorflow
1824
# For some unknown reason this now needs to be split into two commands on Windows
1925
short_commit_sha=$($installed_python -c 'import tensorflow as tf; print(tf.__git_version__)' | tail -1)
20-
short_commit_sha=$(echo $short_commit_sha | grep -oP '(?<=-g)[0-9a-f]*$')
26+
if [[ "${osname}" == "darwin" ]]; then
27+
short_commit_sha=$(echo $short_commit_sha | perl -nle 'print $& while m{(?<=-g)[0-9a-f]*$}g')
28+
else
29+
short_commit_sha=$(echo $short_commit_sha | grep -oP '(?<=-g)[0-9a-f]*$')
30+
fi
2131
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/')
2232

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

0 commit comments

Comments
 (0)