Skip to content

Commit

Permalink
Allow using python3 for timestamps on macOS and any BSD
Browse files Browse the repository at this point in the history
Note that macOS 12.3 recently removed python2.

Equivalent change in Skylib is at bazelbuild/bazel-skylib#362

PiperOrigin-RevId: 438140175
  • Loading branch information
tetromino authored and copybara-github committed Mar 29, 2022
1 parent c56c254 commit be21f19
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/test/shell/unittest.bash
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,14 @@ if [[ "$UNAME" == "linux" ]] || [[ "$UNAME" =~ msys_nt* ]]; then
function timestamp() {
echo $(($(date +%s%N)/1000000))
}
elif [[ "$UNAME" = "openbsd" ]]; then
function timestamp() {
# OpenBSD does not have %N, so Python is the best we can do.
python3 -c 'import time; print(int(round(time.time() * 1000)))'
}
else
function timestamp() {
# OS X and FreeBSD do not have %N, so Python is the best we can do.
python -c 'import time; print(int(round(time.time() * 1000)))'
# macOS and BSDs do not have %N, so Python is the best we can do.
# LC_ALL=C works around python 3.8 and 3.9 crash on macOS when the
# filesystem encoding is unspecified (e.g. when LANG=en_US).
local PYTHON=python
command -v python3 &> /dev/null && PYTHON=python3
LC_ALL=C "${PYTHON}" -c 'import time; print(int(round(time.time() * 1000)))'
}
fi

Expand Down

0 comments on commit be21f19

Please sign in to comment.