Skip to content

Commit 15742d2

Browse files
committed
fixup: Minimize duplication in build equivalency script
1 parent dc0f60b commit 15742d2

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

ffi/test-build-equivalency.sh

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,20 @@ 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
4545
# macOS
46-
otool -rv "$NIX_LIB" > "$TMPDIR/nix-relocs.txt"
47-
otool -rv "$CARGO_LIB" > "$TMPDIR/cargo-relocs.txt"
46+
RELOC_CMD="otool -rv"
4847
RELOC_PATTERN='[A-Z_]+_RELOC_[A-Z0-9_]+'
4948
else
5049
# Linux
51-
readelf -r "$NIX_LIB" > "$TMPDIR/nix-relocs.txt"
52-
readelf -r "$CARGO_LIB" > "$TMPDIR/cargo-relocs.txt"
50+
RELOC_CMD="readelf -r"
5351
RELOC_PATTERN='R_[A-Z0-9_]+'
5452
fi
5553

54+
$RELOC_CMD "$NIX_LIB" > "$TMPDIR/nix-relocs.txt"
55+
$RELOC_CMD "$CARGO_LIB" > "$TMPDIR/cargo-relocs.txt"
56+
5657
NIX_RELOCS=$(wc -l < "$TMPDIR/nix-relocs.txt")
5758
CARGO_RELOCS=$(wc -l < "$TMPDIR/cargo-relocs.txt")
5859
echo "Nix build: $NIX_RELOCS relocation entries"
@@ -67,13 +68,8 @@ echo ""
6768
echo "=== Relocation Type Comparison ==="
6869

6970
# 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
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"
7773

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

0 commit comments

Comments
 (0)