Skip to content

Commit bb69bfb

Browse files
committed
fix(ci): prefer GNU getopt from PATH over hardcoded Homebrew paths
Check if GNU getopt is available in PATH before falling back to Homebrew-specific paths. This supports nix-darwin and other package managers that install GNU getopt outside of Homebrew. Also updates DYLD_LIBRARY_PATH discovery to check standard locations before assuming Homebrew. Signed-off-by: markoburcul <[email protected]>
1 parent cbc53b5 commit bb69bfb

8 files changed

Lines changed: 44 additions & 40 deletions

File tree

ci/Jenkinsfile.macos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pipeline {
2929
disableRestartFromStage()
3030
timestamps()
3131
ansiColor('xterm')
32-
/* This also includes wait time in the queue.*/
32+
/* This also includes wait time in the queue. */
3333
timeout(time: 24, unit: 'HOURS')
3434
/* Limit builds retained. */
3535
buildDiscarder(logRotator(

nix/shell.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ in pkgs.mkShell {
3636
# will erase `-march=native` because this introduces impurity in the build.
3737
# For the purposes of compiling Nimbus, this behavior is not desired:
3838
export NIX_ENFORCE_NO_NATIVE=0
39-
export USE_SYSTEM_GETOPT=1
4039
export MAKEFLAGS="-j$NIX_BUILD_CORES"
4140
4241
figlet "Welcome to Nimbus-eth2"

scripts/getopt-wrapper.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# scripts/getopt-wrapper.sh - exec GNU getopt on any platform.
3+
set -eu
4+
5+
if [ "$(uname)" != "Darwin" ]; then
6+
exec getopt "$@"
7+
fi
8+
9+
# macOS: prefer getopt in PATH if it's GNU (exit 4 from --test), else Homebrew.
10+
getopt --test > /dev/null 2>&1 && rc=0 || rc=$?
11+
if [ "$rc" -eq 4 ]; then
12+
exec getopt "$@"
13+
fi
14+
15+
for c in /opt/homebrew/opt/gnu-getopt/bin/getopt /usr/local/opt/gnu-getopt/bin/getopt; do
16+
[ -x "$c" ] && exec "$c" "$@"
17+
done
18+
19+
echo "GNU getopt not installed. Install via 'brew install gnu-getopt'." >&2
20+
exit 1

scripts/launch_local_testnet.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ PIDS_TO_WAIT=""
3030
# argument parsing #
3131
####################
3232

33-
USE_SYSTEM_GETOPT="${USE_SYSTEM_GETOPT:-0}"
34-
GETOPT_BINARY="getopt"
35-
if [[ "${OS}" == "macos" && "$USE_SYSTEM_GETOPT" != "1" ]]; then
36-
# Without the head -n1 constraint, it gets confused by multiple matches
37-
GETOPT_BINARY=$(find /opt/homebrew/opt/gnu-getopt/bin/getopt /usr/local/opt/gnu-getopt/bin/getopt 2> /dev/null | head -n1 || true)
38-
[[ -f "$GETOPT_BINARY" ]] || { echo "GNU getopt not installed. Please run 'brew install gnu-getopt'. Aborting."; exit 1; }
39-
fi
33+
GETOPT_BINARY="${SCRIPTS_DIR}/getopt-wrapper.sh"
4034

4135
! ${GETOPT_BINARY} --test > /dev/null
4236
if [[ ${PIPESTATUS[0]} != 4 ]]; then

scripts/make_packages.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99

1010
set -e
1111

12+
SCRIPTS_DIR="$(dirname "${BASH_SOURCE[0]}")"
13+
1214
####################
1315
# argument parsing #
1416
####################
1517

16-
GETOPT_BINARY="getopt"
17-
if uname | grep -qi darwin; then
18-
# macOS
19-
GETOPT_BINARY=$(find /opt/homebrew/opt/gnu-getopt/bin/getopt /usr/local/opt/gnu-getopt/bin/getopt 2> /dev/null || true)
20-
[[ -f "$GETOPT_BINARY" ]] || { echo "GNU getopt not installed. Please run 'brew install gnu-getopt'. Aborting."; exit 1; }
21-
fi
18+
GETOPT_BINARY="${SCRIPTS_DIR}/getopt-wrapper.sh"
2219

2320
! ${GETOPT_BINARY} --test > /dev/null
2421
if [ ${PIPESTATUS[0]} != 4 ]; then

scripts/make_prometheus_config.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,18 @@
99

1010
set -e
1111

12+
SCRIPTS_DIR="$(dirname "${BASH_SOURCE[0]}")"
13+
1214
####################
1315
# argument parsing #
1416
####################
1517

16-
GETOPT_BINARY="getopt"
17-
if uname | grep -qi darwin; then
18-
# macOS
19-
# Without the head -n1 constraint, it gets confused by multiple matches
20-
GETOPT_BINARY=$(find /opt/homebrew/opt/gnu-getopt/bin/getopt /usr/local/opt/gnu-getopt/bin/getopt 2> /dev/null | head -n1 || true)
21-
[[ -f "$GETOPT_BINARY" ]] || { echo "GNU getopt not installed. Please run 'brew install gnu-getopt'. Aborting."; exit 1; }
22-
fi
18+
GETOPT_BINARY="${SCRIPTS_DIR}/getopt-wrapper.sh"
2319

2420
! ${GETOPT_BINARY} --test > /dev/null
2521
if [ ${PIPESTATUS[0]} != 4 ]; then
26-
echo '`getopt --test` failed in this environment.'
27-
exit 1
22+
echo '`getopt --test` failed in this environment.'
23+
exit 1
2824
fi
2925

3026
OPTS="h"

scripts/start_nimbus_el_nodes.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ wait_for_port() {
2525
done
2626
}
2727

28-
if [ -d /opt/homebrew/lib ]; then
29-
# BEWARE
30-
# The recent versions of homebrew/macOS can't add the libraries
31-
# installed by Homebrew in the system's library search path, so
32-
# Nimbus will fail to load RocksDB on start-up. THe new rules in
33-
# macOS make it very difficult for the user to solve the problem
34-
# in their profile, so we add an override here as the lessed evil:
35-
export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH:-}:/opt/homebrew/lib"
36-
# See https://github.com/Homebrew/brew/issues/13481 for more details
28+
if uname | grep -qi darwin; then
29+
# Ensure dynamically linked libraries (e.g. RocksDB) can be found at runtime.
30+
# Check Nix paths first, then fall back to Homebrew.
31+
# See https://github.com/Homebrew/brew/issues/13481 for more details.
32+
for libdir in /run/current-system/sw/lib /opt/homebrew/lib /usr/local/lib; do
33+
if [ -d "$libdir" ]; then
34+
DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH:+$DYLD_LIBRARY_PATH:}$libdir"
35+
fi
36+
done
37+
export DYLD_LIBRARY_PATH
3738
fi
3839

3940
for NIMBUS_ETH1_NODE_IDX in $(seq 0 $NIMBUS_ETH1_LAST_NODE_IDX); do

tests/simulation/restapi.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ RESTTEST_DELAY="30"
1717
TEST_DIRNAME="resttest0_data"
1818
KILL_OLD_PROCESSES="0"
1919

20+
REPO_ROOT="$(git rev-parse --show-toplevel)"
21+
SCRIPTS_DIR="${REPO_ROOT}/scripts"
22+
2023
####################
2124
# argument parsing #
2225
####################
2326

24-
GETOPT_BINARY="getopt"
25-
if uname | grep -qi darwin; then
26-
# macOS
27-
# Without the head -n1 constraint, it gets confused by multiple matches
28-
GETOPT_BINARY=$(find /opt/homebrew/opt/gnu-getopt/bin/getopt /usr/local/opt/gnu-getopt/bin/getopt 2> /dev/null | head -n1 || true)
29-
[[ -f "$GETOPT_BINARY" ]] || { echo "GNU getopt not installed. Please run 'brew install gnu-getopt'. Aborting."; exit 1; }
30-
fi
27+
GETOPT_BINARY="${SCRIPTS_DIR}/getopt-wrapper.sh"
3128

3229
! ${GETOPT_BINARY} --test > /dev/null
3330
if [ ${PIPESTATUS[0]} != 4 ]; then

0 commit comments

Comments
 (0)