Skip to content

Commit 0cf4a26

Browse files
committed
fixup: Minimize duplication in build equivalency script
1 parent dc0f60b commit 0cf4a26

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

ffi/test-build-equivalency.sh

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ fi
4040
echo ""
4141
echo "=== Relocation Count Comparison ==="
4242

43-
# Detect OS and use appropriate tool
43+
# Determine os-specific reloc config
4444
if [[ "$OSTYPE" == "darwin"* ]]; then
45-
# macOS
46-
otool -rv "$NIX_LIB" > "$TMPDIR/nix-relocs.txt"
47-
otool -rv "$CARGO_LIB" > "$TMPDIR/cargo-relocs.txt"
45+
RELOC_CMD="otool -rv"
4846
RELOC_PATTERN='[A-Z_]+_RELOC_[A-Z0-9_]+'
4947
else
50-
# Linux
51-
readelf -r "$NIX_LIB" > "$TMPDIR/nix-relocs.txt"
52-
readelf -r "$CARGO_LIB" > "$TMPDIR/cargo-relocs.txt"
48+
RELOC_CMD="readelf -r"
5349
RELOC_PATTERN='R_[A-Z0-9_]+'
5450
fi
5551

52+
$RELOC_CMD "$NIX_LIB" > "$TMPDIR/nix-relocs.txt"
53+
$RELOC_CMD "$CARGO_LIB" > "$TMPDIR/cargo-relocs.txt"
54+
5655
NIX_RELOCS=$(wc -l < "$TMPDIR/nix-relocs.txt")
5756
CARGO_RELOCS=$(wc -l < "$TMPDIR/cargo-relocs.txt")
5857
echo "Nix build: $NIX_RELOCS relocation entries"
@@ -67,13 +66,8 @@ echo ""
6766
echo "=== Relocation Type Comparison ==="
6867

6968
# Use grep with -E for better portability (avoid -P which isn't available on macOS)
70-
if [[ "$OSTYPE" == "darwin"* ]]; then
71-
grep -Eo "$RELOC_PATTERN" "$TMPDIR/nix-relocs.txt" | sort | uniq -c > "$TMPDIR/nix-reloc-types.txt"
72-
grep -Eo "$RELOC_PATTERN" "$TMPDIR/cargo-relocs.txt" | sort | uniq -c > "$TMPDIR/cargo-reloc-types.txt"
73-
else
74-
grep -oP "$RELOC_PATTERN" "$TMPDIR/nix-relocs.txt" | sort | uniq -c > "$TMPDIR/nix-reloc-types.txt"
75-
grep -oP "$RELOC_PATTERN" "$TMPDIR/cargo-relocs.txt" | sort | uniq -c > "$TMPDIR/cargo-reloc-types.txt"
76-
fi
69+
grep -Eo "$RELOC_PATTERN" "$TMPDIR/nix-relocs.txt" | sort | uniq -c > "$TMPDIR/nix-reloc-types.txt"
70+
grep -Eo "$RELOC_PATTERN" "$TMPDIR/cargo-relocs.txt" | sort | uniq -c > "$TMPDIR/cargo-reloc-types.txt"
7771

7872
if diff "$TMPDIR/nix-reloc-types.txt" "$TMPDIR/cargo-reloc-types.txt" > /dev/null; then
7973
echo "✅ Relocation types match"

0 commit comments

Comments
 (0)