Skip to content

Commit

Permalink
Merge pull request #20 from mlocati/check-bits
Browse files Browse the repository at this point in the history
Check bitness of generated binaries
  • Loading branch information
mlocati authored Sep 27, 2024
2 parents c8805b3 + 0bd06d3 commit 4f56b6a
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ jobs:
-Link ${{ matrix.link }}
-OutputPath C:\cygwin\output
-MinGWPath C:\cygwin\usr\${{ steps.vars.outputs.mingw-host }}
-
name: Check bitness
run: ./build-exe/check-bits.sh ${{ matrix.bits }} /output
-
name: Delete install directory
run: rm -rf /installed
Expand Down Expand Up @@ -309,6 +312,9 @@ jobs:
-Link ${{ matrix.link }}
-SourceDirectory C:\cygwin\output
-OutputDirectory C:\
-
name: Check bitness
run: ./build-exe/check-bits.sh 32 /cygdrive/c/gettext${{ env.GETTEXT_VERSION }}-iconv${{ env.ICONV_VERSION }}-${{ matrix.link }}-${{ matrix.bits }}.exe
-
name: Upload installer
uses: actions/upload-artifact@v4
Expand Down
117 changes: 117 additions & 0 deletions build-exe/check-bits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash
#
# Script that checks if the binary files in a directory (and its sub-directoroes)
# have the correct bitness
#
# Arguments:
# $1: the number of bits (32, 64)
# $2: the directory to be checked, or the path to a file
#

set -o errexit
set -o nounset
set -o pipefail

BITS="${1:-}"
case "$BITS" in
32 | 64)
;;
'')
echo 'Missing bitness'
exit 1
;;
*)
printf 'Invalid bitness: %s\n' "$BITS"
exit 1
;;
esac

CHECK_ME="${2:-}"
if [ -z "$CHECK_ME" ]; then
echo 'Missing file/directory to be checked'
exit 1
fi

# Arguments:
# $1: the file
checkBits()
{
local checkMe="$1"
printf 'Checking %s... ' "$checkMe"
local info="$(file -bEh -- "$checkMe" | head -n1)"
case "$info" in
PE32\ executable\ \(console\)\ Intel\ 80386*)
printf '32-bit exe (console): '
if [ $BITS -ne 32 ]; then
echo 'INVALID'
return 1
fi
echo 'OK'
;;
PE32\ executable\ \(GUI\)\ Intel\ 80386*)
printf '32-bit exe (GUI): '
if [ $BITS -ne 32 ]; then
echo 'INVALID'
return 1
fi
echo 'OK'
;;
PE32\ executable\ \(DLL\)\ \(console\)\ Intel\ 80386*)
printf '32-bit dll: '
if [ $BITS -ne 32 ]; then
echo 'INVALID'
return 1
fi
echo 'OK'
;;
PE32\+\ executable\ \(console\)\ x86-64*)
printf '64-bit exe (console): '
if [ $BITS -ne 64 ]; then
echo 'INVALID'
return 1
fi
echo 'OK'
;;
PE32\+\ executable\ \(GUI\)\ x86-64*)
printf '64-bit exe (GUI): '
if [ $BITS -ne 64 ]; then
echo 'INVALID'
return 1
fi
echo 'OK'
;;
PE32+\ executable\ \(DLL\)\ \(console\)\ x86-64*)
printf '64-bit dll: '
if [ $BITS -ne 64 ]; then
echo 'INVALID'
return 1
fi
echo 'OK'
;;
*)
printf 'UNRECOGNISED INFO: %s\n' "$info"
return 1
;;
esac
}

if [ -d "$CHECK_ME" ]; then
allOk=1
for f in $(find "$CHECK_ME" -type f -name *.dll -o -name *.exe); do
if ! checkBits "$f"; then
allOk=0
fi
done
if [ $allOk -ne 1 ]; then
echo 'FAILURE!'
exit 1
fi
elif [ -f "$CHECK_ME" ]; then
if ! checkBits "$CHECK_ME"; then
echo 'FAILURE!'
exit 1
fi
else
printf 'Unable to find the file or directory %s\n' "$CHECK_ME"
exit 1
fi
8 changes: 7 additions & 1 deletion build-exe/create-output.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash

#
# Script that creates the "output" directory starting from the directory created by
# "make install" calls
#
# Arguments:
# $1: the directory created by the "make install calls
# $2: the directory where the files should be copied to
# $3: the MinGW-w64 host (i686-w64-mingw32, x86_64-w64-mingw32)
#

set -o errexit
set -o nounset
Expand Down
2 changes: 1 addition & 1 deletion build-exe/vars.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ switch ($Bits) {
}
}

$cygwinPackages = "make,unzip,perl,mingw64-$architecture-gcc-core,mingw64-$architecture-gcc-g++,mingw64-$architecture-headers,mingw64-$architecture-runtime"
$cygwinPackages = "file,make,unzip,perl,mingw64-$architecture-gcc-core,mingw64-$architecture-gcc-g++,mingw64-$architecture-headers,mingw64-$architecture-runtime"

$mingwHost = "$architecture-w64-mingw32"

Expand Down

0 comments on commit 4f56b6a

Please sign in to comment.