Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
convert output compile scripts to ruby, also compile universal output…
Browse files Browse the repository at this point in the history
… files on both macos and ios SDKs
  • Loading branch information
djbe committed Feb 25, 2017
1 parent 85b1611 commit d0b8bab
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 68 deletions.
37 changes: 0 additions & 37 deletions Scripts/compile-modules.sh

This file was deleted.

28 changes: 0 additions & 28 deletions Scripts/compile-output.sh

This file was deleted.

68 changes: 66 additions & 2 deletions rakelib/output.rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,75 @@
MODULE_INPUT_PATH = 'Fixtures/stub-env/Modules'
MODULE_OUTPUT_PATH = 'Fixtures/stub-env'
SDKS = {
:macosx => 'x86_64-apple-macosx10.12',
:iphoneos => 'armv7s-apple-ios10.0'
}
TOOLCHAINS = {
:swift2 => {
:module_path => "#{MODULE_OUTPUT_PATH}/swift2.3",
:toolchain => 'com.apple.dt.toolchain.Swift_2_3'
},
:swift3 => {
:module_path => "#{MODULE_OUTPUT_PATH}/swift3",
:toolchain => 'com.apple.dt.toolchain.XcodeDefault'
}
}

namespace :output do
desc 'Compile modules'
task :modules do |task|
plain("./Scripts/compile-modules.sh", task)
# macOS
modules = ['PrefsWindowController']
modules.each do |m|
print "Compiling module #{m}… (macos)\n"
compile_module(m, :macosx, task)
end

# iOS
modules = ['CustomSegue', 'LocationPicker', 'SlackTextViewController']
modules.each do |m|
print "Compiling module #{m}… (ios)\n"
compile_module(m, :iphoneos, task)
end

# delete swiftdoc
Dir.glob("#{MODULE_OUTPUT_PATH}/*.swiftdoc").each do |f|
FileUtils.rm_rf(f)
end
end

desc 'Compile output'
task :compile => :modules do |task|
plain("./Scripts/compile-output.sh", task)
Dir.glob('Tests/Expected/**/*.swift').each do |f|
compile_file(f, task)
end
end

def compile_module(m, sdk, task)
target = SDKS[sdk]

TOOLCHAINS.each_pair do |key, toolchain|
xcrun(%Q(--toolchain #{toolchain[:toolchain]} -sdk #{sdk} swiftc -emit-module "#{MODULE_INPUT_PATH}/#{m}.swift" -module-name "#{m}" -emit-module-path "#{toolchain[:module_path]}" -target "#{target}"), task)
end
end

def compile_file(f, task)
if f.match('swift3')
toolchain = TOOLCHAINS[:swift3]
else
toolchain = TOOLCHAINS[:swift2]
end

if f.match('iphoneos')
sdks = [:macosx]
elsif f.match('macOS')
sdks = [:iphoneos]
else
sdks = [:iphoneos, :macosx]
end

sdks.each do |sdk|
xcrun(%Q(--toolchain #{toolchain[:toolchain]} -sdk #{sdk} swiftc -parse -target #{SDKS[sdk]} -I #{toolchain[:module_path]} "#{MODULE_OUTPUT_PATH}/Definitions.swift"), task)
end
end
end
2 changes: 1 addition & 1 deletion rakelib/utils.rake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def version_select
# Order by version and get the latest one
vers = lambda { |path| `mdls -name kMDItemVersion -raw "#{path}"` }
latest_xcode_version = xcodes.sort { |p1, p2| vers.call(p1) <=> vers.call(p2) }.last
%Q(DEVELOPER_DIR="#{latest_xcode_version}/Contents/Developer" TOOLCHAINS=com.apple.dt.toolchain.XcodeDefault.xctoolchain)
%Q(DEVELOPER_DIR="#{latest_xcode_version}/Contents/Developer")
end

def xcrun(cmd, task, pretty=true)
Expand Down

0 comments on commit d0b8bab

Please sign in to comment.