Create a gist now

Instantly share code, notes, and snippets.

CodeRunner compile.sh script to support Swift
#!/bin/bash
# This is a CodeRunner compilation script. Compilation scripts are used to
# compile code before being run using the run command specified in CodeRunner
# preferences. This script should have the following properties:
#
# Launch directory ($PWD): Will be the same as the file being run
#
# Exit status: Should be 0 on success (will cause CodeRunner
# to continue and execute the run command)
#
# Output (stdout): On success, one line of text which can be accessed
# using the $compiler variable in the run command
#
# Output (stderr): Anything outputted here will be displayed in
# the CodeRunner console
#
# Arguments: $1 Filename of the source file
# $2 Encoding of the source file
# $3 Compilation flags set in CodeRunner preferences
# $4 Path of a temporary directory (without / suffix)
#
# The encoding argument may be used to specify to the compiler which encoding
# the source file uses. It will be one of the integers in the following array:
enc[4]="" # UTF-8
enc[10]="" # UTF-16
enc[5]="" # ISO Latin 1
enc[9]="" # ISO Latin 2
enc[30]="" # Mac OS Roman
enc[12]="" # Windows Latin 1
enc[3]="" # Japanese (EUC)
enc[8]="" # Japanese (Shift JIS)
enc[1]="" # ASCII
compname=`echo "$1" | sed 's/\(.*\)\..*/\1/'`
xcrun swift -sdk $(xcrun --show-sdk-path --sdk macosx) "$1" -o "$compname" $3
status=$?
if [ $status -eq 0 ]
then
echo $compname
exit 0
elif [ $status -eq 127 ]
then
echo -e "\nTo run code in this language, you need to have compilers installed. These are bundled with Xcode 6 or later which can be downloaded through the Mac App Store or Apple's developer site."
fi
exit $status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment