Skip to content

Commit

Permalink
Test b3
Browse files Browse the repository at this point in the history
  • Loading branch information
diemogebhardt committed Nov 30, 2024
1 parent 1871cc4 commit 9e6482c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions bin/verify-binary-architecture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,30 @@ BINARY_PATH="$2"
# Parse target architecture
parse_target_architecture() {
local target_triple="$1"
echo "$target_triple" \
| grep -Eo 'x86_64|aarch64' \
|| echo "unknown target architecture"
local parse="x86_64|aarch64"
local error="unknown target architecture"
echo "$target_triple" | grep -Eo "$parse" || echo "$error"
}
TARGET_ARCHITECTURE=$(parse_target_architecture "$TARGET_TRIPLE")

# Parse and normalize binary architecture
parse_and_normalize_binary_architecture() {
local binary_path="$1"
local parse="x86_64|x86-64|arm64|aarch64|Aarch64"
local normalize='s/x86-64/x86_64/;s/(arm64|Aarch64)/aarch64/'
local error="unknown binary architecture"
file -b "$binary_path" \
| grep -Eo "x86_64|x86-64|arm64|aarch64|Aarch64" | head -n1 \
| sed -E 's/x86-64/x86_64/;s/(arm64|Aarch64)/aarch64/' \
|| echo "unknown"
| grep -Eo "$parse" | head -n1 \
| sed -E "$normalize" \
|| echo "$error"
}
BINARY_ARCHITECTURE=$(parse_and_normalize_binary_architecture "${BINARY_PATH}")
BINARY_ARCHITECTURE=$(parse_and_normalize_binary_architecture "$BINARY_PATH")

# Verify that binary architecture matches target architecture
if [ "$BINARY_ARCHITECTURE" != "$TARGET_ARCHITECTURE" ]; then
echo "Architecture mismatch for '${TARGET_TRIPLE}'!"
echo "Expected: '${TARGET_ARCHITECTURE}'"
echo "Got: '${BINARY_ARCHITECTURE}'"
echo "Architecture mismatch for '$TARGET_TRIPLE'!"
echo "Expected: '$TARGET_ARCHITECTURE'"
echo "Got: '$BINARY_ARCHITECTURE'"
exit 1
fi
echo "Architecture match for '$TARGET_TRIPLE'!"

0 comments on commit 9e6482c

Please sign in to comment.