Skip to content

Instantly share code, notes, and snippets.

@Pegolon
Created June 25, 2018 15:36
Show Gist options
  • Save Pegolon/05f42bed895e185336ca0f0abf629bcd to your computer and use it in GitHub Desktop.
Save Pegolon/05f42bed895e185336ca0f0abf629bcd to your computer and use it in GitHub Desktop.
#!/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