Created
March 18, 2016 13:54
-
-
Save kazmiekr/64ce00aa29c2c9078aaf to your computer and use it in GitHub Desktop.
Shell script to run a swift Xcode playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| function error_exit { | |
| echo "$1" | |
| exit 1 | |
| } | |
| function clean_dir { | |
| rm $MAIN_SWIFT_FILE | |
| } | |
| if [ "$1" == "" ]; then | |
| error_exit "Directory is required to run" | |
| fi | |
| MAIN_SWIFT_FILE="$1main.swift" | |
| PLAYGROUND_MAIN_SWIFT_FILE="$1Contents.swift" | |
| PLAYGROUND_SWIFT_SOURCES_DIR="$1Sources" | |
| OUTPUT_EXECUTABLE="$1playground" | |
| SWIFT_COMPILER_ARGS="$MAIN_SWIFT_FILE -o $OUTPUT_EXECUTABLE" | |
| echo "Compiling playground: $1" | |
| cp $PLAYGROUND_MAIN_SWIFT_FILE $MAIN_SWIFT_FILE | |
| # Check to see if we need to include sources | |
| if [ -d "$PLAYGROUND_SWIFT_SOURCES_DIR" ]; then | |
| SWIFT_COMPILER_ARGS="$PLAYGROUND_SWIFT_SOURCES_DIR/**/*.swift $SWIFT_COMPILER_ARGS" | |
| fi | |
| echo "Compiler statement: swiftc $SWIFT_COMPILER_ARGS" | |
| if swiftc $SWIFT_COMPILER_ARGS; then | |
| clean_dir | |
| echo $'Running playground\n\n' | |
| ./$OUTPUT_EXECUTABLE | |
| else | |
| clean_dir | |
| error_exit "Compile failed" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment