Skip to content

Instantly share code, notes, and snippets.

@mttrb
Created June 11, 2014 06:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mttrb/60d9f62633cf9e585504 to your computer and use it in GitHub Desktop.
Save mttrb/60d9f62633cf9e585504 to your computer and use it in GitHub Desktop.
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