Created
June 25, 2018 15:36
-
-
Save Pegolon/05f42bed895e185336ca0f0abf629bcd to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
# This will compile the given Swift script and run it | |
unless ARGV.count == 1 | |
puts "Please provide the path for the Swift source file to compile and run" | |
exit -1 | |
end | |
SOURCE_FILE = ARGV[0] | |
BASE_NAME = File.basename(SOURCE_FILE, ".swift") | |
SWIFT_BINARY = "#{File.dirname(SOURCE_FILE)}/#{BASE_NAME}" | |
if File.exists?(SWIFT_BINARY) && File.mtime(SOURCE_FILE) > File.mtime(SWIFT_BINARY) | |
puts "Source file has been changed, removing outdated file #{SWIFT_BINARY}" | |
File.delete(SWIFT_BINARY) | |
end | |
unless File.exists?(SWIFT_BINARY) | |
`xcrun -sdk macosx swiftc "#{SOURCE_FILE}" -o "#{SWIFT_BINARY}"` | |
end | |
`#{SWIFT_BINARY}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment