Skip to content

Commit 862a2df

Browse files
authored
build-gnu.sh: fix for /usr/bin/timeout on MacOS (#5194)
* build-gnu.sh: `/usr/bin/timeout` should not be hardcoded to /usr/bin location Fixes #5193
1 parent a9b2e67 commit 862a2df

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

util/build-gnu.sh

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,30 @@ path_GNU="$(readlink -fm -- "${path_GNU:-${path_UUTILS}/../gnu}")"
1818

1919
###
2020

21+
# On MacOS there is no system /usr/bin/timeout
22+
# and trying to add it to /usr/bin (with symlink of copy binary) will fail unless system integrity protection is disabled (not ideal)
23+
# ref: https://support.apple.com/en-us/102149
24+
# On MacOS the Homebrew coreutils could be installed and then "sudo ln -s /opt/homebrew/bin/timeout /usr/local/bin/timeout"
25+
# Set to /usr/local/bin/timeout instead if /usr/bin/timeout is not found
26+
SYSTEM_TIMEOUT="timeout"
27+
if [ -x /usr/bin/timeout ] ; then
28+
SYSTEM_TIMEOUT="/usr/bin/timeout"
29+
elif [ -x /usr/local/bin/timeout ] ; then
30+
SYSTEM_TIMEOUT="/usr/local/bin/timeout"
31+
fi
32+
33+
###
34+
35+
release_tag_GNU="v9.4"
36+
2137
if test ! -d "${path_GNU}"; then
2238
echo "Could not find GNU coreutils (expected at '${path_GNU}')"
2339
echo "Run the following to download into the expected path:"
2440
echo "git clone --recurse-submodules https://github.com/coreutils/coreutils.git \"${path_GNU}\""
41+
echo "After downloading GNU coreutils to \"${path_GNU}\" run the following commands to checkout latest release tag"
42+
echo "cd \"${path_GNU}\""
43+
echo "git fetch --all --tags"
44+
echo "git checkout tags/${release_tag_GNU}"
2545
exit 1
2646
fi
2747

@@ -82,7 +102,7 @@ else
82102
./bootstrap --skip-po
83103
./configure --quiet --disable-gcc-warnings
84104
#Add timeout to to protect against hangs
85-
sed -i 's|^"\$@|/usr/bin/timeout 600 "\$@|' build-aux/test-driver
105+
sed -i 's|^"\$@|'"${SYSTEM_TIMEOUT}"' 600 "\$@|' build-aux/test-driver
86106
# Change the PATH in the Makefile to test the uutils coreutils instead of the GNU coreutils
87107
sed -i "s/^[[:blank:]]*PATH=.*/ PATH='${UU_BUILD_DIR//\//\\/}\$(PATH_SEPARATOR)'\"\$\$PATH\" \\\/" Makefile
88108
sed -i 's| tr | /usr/bin/tr |' tests/init.sh
@@ -153,13 +173,14 @@ sed -i 's|touch |/usr/bin/touch |' tests/cp/reflink-perm.sh tests/ls/block-size.
153173
sed -i 's|ln -|/usr/bin/ln -|' tests/cp/link-deref.sh
154174
sed -i 's|cp |/usr/bin/cp |' tests/mv/hard-2.sh
155175
sed -i 's|paste |/usr/bin/paste |' tests/od/od-endian.sh
156-
sed -i 's|timeout |/usr/bin/timeout |' tests/tail/follow-stdin.sh
176+
sed -i 's|timeout |'"${SYSTEM_TIMEOUT}"' |' tests/tail/follow-stdin.sh
157177

158178
# Add specific timeout to tests that currently hang to limit time spent waiting
159-
sed -i 's|\(^\s*\)seq \$|\1/usr/bin/timeout 0.1 seq \$|' tests/seq/seq-precision.sh tests/seq/seq-long-double.sh
179+
sed -i 's|\(^\s*\)seq \$|\1'"${SYSTEM_TIMEOUT}"' 0.1 seq \$|' tests/seq/seq-precision.sh tests/seq/seq-long-double.sh
160180

161-
# Remove dup of /usr/bin/ when executed several times
181+
# Remove dup of /usr/bin/ and /usr/local/bin/ when executed several times
162182
grep -rlE '/usr/bin/\s?/usr/bin' init.cfg tests/* | xargs --no-run-if-empty sed -Ei 's|/usr/bin/\s?/usr/bin/|/usr/bin/|g'
183+
grep -rlE '/usr/local/bin/\s?/usr/local/bin' init.cfg tests/* | xargs --no-run-if-empty sed -Ei 's|/usr/local/bin/\s?/usr/local/bin/|/usr/local/bin/|g'
163184

164185
#### Adjust tests to make them work with Rust/coreutils
165186
# in some cases, what we are doing in rust/coreutils is good (or better)

0 commit comments

Comments
 (0)