Skip to content

Commit

Permalink
Make webdsl compiler build on 64-bit macOS by using the wrapper scrip…
Browse files Browse the repository at this point in the history
…ts created by Daniel (@Virtlink) from the spoofax repo
  • Loading branch information
Elmervc committed Feb 15, 2023
1 parent b54ff24 commit a4d5f01
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/get-stratego-jar.sh
Expand Up @@ -7,4 +7,25 @@ if [ ! -f strategoxt.jar ]; then
fi
if [ ! -f Java-EBlock.rtg.af ]; then
cp share/strategoxt/java_front/languages/java/Java-EBlock.rtg.af .
fi

# In order to be compatible with recent macOS versions that no longer support running 32-bit binaries:
# Patch the native 32-bit tools `sdf2table` and `implodePT` by renaming the binaries in the macosx folder and
# copying the x64-macosx-docker_{sdf2table,implodePT} scripts. These wrapper scripts will try to invoke the tools
# from the host OS or, when this fails, invoke the tools from a docker container with linux that is able to run
# 32 bit binaries.
# Credits to https://github.com/Virtlink for creating the wrapper scripts. These are copied from:
# https://github.com/metaborg/spoofax/tree/31ea48889ab10104e8729aed7bc8842d45096f7b/org.metaborg.spoofax.nativebundle/src/main/resources/org/metaborg/spoofax/nativebundle/native/macosx
#
if [ ! -f share/strategoxt/macosx/sdf2table-macosx ]; then
mv share/strategoxt/macosx/sdf2table share/strategoxt/macosx/sdf2table-macosx
cp share/strategoxt/linux/sdf2table share/strategoxt/macosx/sdf2table-linux
cp ./x64-macosx-docker_sdf2table share/strategoxt/macosx/sdf2table
chmod +x share/strategoxt/macosx/sdf2table
fi
if [ ! -f share/strategoxt/macosx/implodePT-macosx ]; then
mv share/strategoxt/macosx/implodePT share/strategoxt/macosx/implodePT-macosx
cp share/strategoxt/linux/implodePT share/strategoxt/macosx/implodePT-linux
cp ./x64-macosx-docker_implodePT share/strategoxt/macosx/implodePT
chmod +x share/strategoxt/macosx/implodePT
fi
128 changes: 128 additions & 0 deletions src/x64-macosx-docker_implodePT
@@ -0,0 +1,128 @@
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o noclobber
set -o nounset
#set -o xtrace

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
[ ! -z "$DIR" ] # Ensure the directory is not empty
[ -d "$DIR" ] # Ensure the directory exists

BIN="implodePT"

usage() { echo "implodePT in Docker
Usage: $0 [aAbchi:lOo:pPtvILVqX]
Options:
-a keep annotations (default yes)
-A interpret alternatives
-b output terms in BAF format (default)
-c interpret 'cons' attributes
-h display help information (usage)
-i filename input from file (default stdin)
-l remove layout
-o filename output to file (default stdout)
-O interpret optionals
-p remove parsetree
-P interpret layout-place-holder annotation
-t output terms in plaintext format
-v verbose mode
-I remove injections
-L remove literals
-V reveal program version (i.e. 1.1)
-q interpret sequences
-X implode lexicals
Note that if none of the [AclopILqX] switches are given,
they are all activated by default. If you give any of them,
the others are off by default until you switch them on.
" 1>&2; exit 1; }

# Read the command-line options,
# appending them to $newopts
newopts=""
declare -a vols=()
while getopts "aAbchi:lOo:pPtvILVqX" o; do
case "${o}" in
a) newopts+=" -a" ;;
A) newopts+=" -A" ;;
b) newopts+=" -b" ;;
c) newopts+=" -c" ;;
h) newopts+=" -h" ;;
i)
abspath=$(realpath -s $(dirname "${OPTARG}"))
absfile=$(realpath -s "${OPTARG}")
newopts+=" -i ${absfile}"
vols+=($abspath)
;;
l) newopts+=" -l" ;;
O) newopts+=" -O" ;;
o)
abspath=$(realpath -s $(dirname "${OPTARG}"))
absfile=$(realpath -s "${OPTARG}")
newopts+=" -o ${absfile}"
vols+=($abspath)
;;
p) newopts+=" -p" ;;
P) newopts+=" -P" ;;
t) newopts+=" -t" ;;
v) newopts+=" -v" ;;
I) newopts+=" -I" ;;
L) newopts+=" -L" ;;
V) newopts+=" -V" ;;
q) newopts+=" -q" ;;
X) newopts+=" -X" ;;
*) usage ;;
esac
done
shift $((OPTIND-1))

# Attempt to run the native command
set +o errexit
"$DIR/$BIN-macosx" ${newopts}
retVal=$?
set -o errexit
if [[ $retVal -ne 126 ]]; then
# It ran but succeeded or failed
exit $retVal
fi
# The command didn't run, attempt run using Docker
echo "$BIN failed to run natively, attemping using Docker"

# Gather the volumes to mount (basically, every directory mentioned in -i, or -o)
volumes=""
for i in "${vols[@]}"
do
echo "VOLUME: ${i}"
volumes+=" -v ${i}:${i}"
mkdir -p "${i}"
done
echo $volumes

# Create the docker container with the volumes mounted
container_id=$(docker container create \
--mount type=bind,source="$DIR",target=/bundle \
${volumes} \
ubuntu:focal \
/bin/bash -c "/bundle/$BIN-linux ${newopts}")

# Start the container
docker container start $container_id

# Show container output
docker container logs --since 0 -f $container_id

# Wait for the container to finish, and get exit code
retVal=$(docker container wait $container_id)

# Always remove the container
docker container rm $container_id

if [[ $retVal -ne 0 ]]; then
# It ran but failed
echo "Error $retVal, exit"
exit $retVal
fi

echo "Done"
133 changes: 133 additions & 0 deletions src/x64-macosx-docker_sdf2table
@@ -0,0 +1,133 @@
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o noclobber
set -o nounset
#set -o xtrace

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
[ ! -z "$DIR" ] # Ensure the directory is not empty
[ -d "$DIR" ] # Ensure the directory exists

BIN="sdf2table"

usage() { echo "sdf2table in Docker
Use this program to generate a parse table from an SDF definition.
It can generate tables from full SDF definition files, parse trees
of full SDF definition files, or search for modules itself starting
from a top module name and using a search path.
Common usage patterns:
$0 -c -m <topModule> -o <file>.tbl
$0 -c -m <topModule> -p <searchPath> -o <file>.tbl
$0 -m <topModule> -i <definitionFile>.def -o <file>.tbl
$0 -m <topModule> -i <definitionTree>.def.pt -o <file>.tbl
$0 -c -d -m <topModule> -o <definitionFile>.def.pt
Usage: $0 [options]
Options:
-b output terms in BAF format (default)
-c collect SDF modules from the search path
-d only collect an SDF definition
-g take kernel sdf as input and generate table
-h display help information (usage)
-i filename input from file (default stdin, can be repeated)
-l filename log statistic information
-m modulename name of top module (default Main)
-n only normalization of grammar
-o filename output to file (default stdout)
-p path colon separated search path for SDF modules (default '.', not supported)
-t output terms in plaintext format
-v verbose mode
-V reveal program version (i.e. 5.0)
" 1>&2; exit 1; }

# Read the command-line options,
# appending them to $newopts
newopts=""
declare -a vols=()
while getopts "bcdghi:l:m:no:p:tvV" o; do
case "${o}" in
b) newopts+=" -b" ;;
c) newopts+=" -c" ;;
d) newopts+=" -d" ;;
g) newopts+=" -g" ;;
h) newopts+=" -h" ;;
i)
abspath=$(realpath -s $(dirname "${OPTARG}"))
absfile=$(realpath -s "${OPTARG}")
newopts+=" -i ${absfile}"
vols+=($abspath)
;;
l)
abspath=$(realpath -s $(dirname "${OPTARG}"))
absfile=$(realpath -s "${OPTARG}")
newopts+=" -l ${absfile}"
vols+=($abspath)
;;
m) newopts+=" -m ${OPTARG}" ;;
n) newopts+=" -n" ;;
o)
abspath=$(realpath -s $(dirname "${OPTARG}"))
absfile=$(realpath -s "${OPTARG}")
newopts+=" -o ${absfile}"
vols+=($abspath)
;;
#p) newopts+=" -p ${OPTARG}" ;; # Not supported
t) newopts+=" -t" ;;
v) newopts+=" -v" ;;
V) newopts+=" -V" ;;
*) usage ;;
esac
done
shift $((OPTIND-1))

# Attempt to run the native command
set +o errexit
"$DIR/$BIN-macosx" ${newopts}
retVal=$?
set -o errexit
if [[ $retVal -ne 126 ]]; then
# It ran but succeeded or failed
exit $retVal
fi
# The command didn't run, attempt run using Docker
echo "$BIN failed to run natively, attemping using Docker"

# Gather the volumes to mount (basically, every directory mentioned in -i, -l, or -o)
volumes=""
for i in "${vols[@]}"
do
echo "VOLUME: ${i}"
volumes+=" -v ${i}:${i}"
mkdir -p "${i}"
done
echo $volumes

# Create the docker container with the volumes mounted
container_id=$(docker container create \
--mount type=bind,source="$DIR",target=/bundle \
${volumes} \
ubuntu:focal \
/bin/bash -c "/bundle/$BIN-linux ${newopts}")

# Start the container
docker container start $container_id

# Show container output
docker container logs --since 0 -f $container_id

# Wait for the container to finish, and get exit code
retVal=$(docker container wait $container_id)

# Always remove the container
docker container rm $container_id

if [[ $retVal -ne 0 ]]; then
# It ran but failed
echo "Error $retVal, exit"
exit $retVal
fi

echo "Done"

0 comments on commit a4d5f01

Please sign in to comment.