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

Commit

Permalink
copy changes from stencilswiftkit
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe committed Feb 28, 2017
1 parent 4f22d0c commit 99121eb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 67 deletions.
14 changes: 6 additions & 8 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
namespace :lint do
desc 'Install swiftlint'
task :install do |task|
swiftlint = `which swiftlint`

if !(swiftlint && $?.success?)
if !system('which swiftlint > /dev/null')
url = 'https://github.com/realm/SwiftLint/releases/download/0.16.1/SwiftLint.pkg'
tmppath = '/tmp/SwiftLint.pkg'

plain([
Utils.run([
"curl -Lo #{tmppath} #{url}",
"sudo installer -pkg #{tmppath} -target /"
], task)
Expand All @@ -16,13 +14,13 @@ namespace :lint do

desc 'Lint the tests'
task :tests => :install do |task|
print_info 'Linting the unit test code'
plain(%Q(swiftlint lint --no-cache --strict --path Tests/TestSuites), task)
Utils.print_info 'Linting the unit test code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path "Tests/TestSuites"), task)
end

desc 'Lint the output'
task :output => :install do |task|
print_info 'Linting the template output code'
plain(%Q(swiftlint lint --no-cache --strict --path Tests/Expected), task)
Utils.print_info 'Linting the template output code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path Tests/Expected), task)
end
end
14 changes: 7 additions & 7 deletions rakelib/output.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ TOOLCHAINS = {
namespace :output do
desc 'Compile modules'
task :modules do |task|
print_info 'Compile output modules'
Utils.print_info 'Compile output modules'

# macOS
modules = ['PrefsWindowController']
modules.each do |m|
print "Compiling module #{m}… (macos)\n"
puts "Compiling module #{m}… (macos)"
compile_module(m, :macosx, task)
end

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

Expand All @@ -42,10 +42,10 @@ namespace :output do

desc 'Compile output'
task :compile => :modules do |task|
print_info 'Compiling template output files'
Utils.print_info 'Compiling template output files'

exit Dir.glob('Tests/Expected/**/*.swift').map { |f|
print "Compiling #{f}\n"
puts "Compiling #{f}\n"
compile_file(f, task)
}.reduce(true) { |result, status|
result && status
Expand All @@ -59,7 +59,7 @@ namespace :output do
%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}")
end

xcrun(commands, task, subtask)
Utils.run(commands, task, subtask, xcrun: true)
end

def compile_file(f, task)
Expand All @@ -83,7 +83,7 @@ namespace :output do
subtask = File.basename(f, '.*')

begin
xcrun(commands, task, subtask)
Utils.run(commands, task, subtask, xcrun: true)
return true
rescue
return false
Expand Down
106 changes: 58 additions & 48 deletions rakelib/utils.rake
Original file line number Diff line number Diff line change
@@ -1,58 +1,68 @@
# run a command, pipe output through 'xcpretty' and store the output in CI artifacts
def xcpretty(cmd, task, subtask = '')
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_")
command = [*cmd].join(' && ')
xcpretty = `which xcpretty`

if ENV['CI']
sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | xcpretty --color --report junit --output \"#{ENV['CIRCLE_TEST_REPORTS']}/xcode/#{name}.xml\""
elsif xcpretty && $?.success?
sh "set -o pipefail && (#{command}) | xcpretty -c"
else
sh command
end
end
class Utils

# run a command and store the output in CI artifacts
def plain(cmd, task, subtask = '')
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_")
command = [*cmd].join(' && ')
# run a command using xcrun and xcpretty if applicable
def self.run(cmd, task, subtask = '', xcrun: false, xcpretty: false, direct: false)
commands = xcrun ? [*cmd].map { |cmd|
"#{version_select} xcrun #{cmd}"
} : [*cmd]

if ENV['CI']
sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\""
else
sh command
if xcpretty
xcpretty(commands, task, subtask)
elsif !direct
plain(commands, task, subtask)
else
`#{commands.join(' && ')}`
end
end
end

# select the xcode version we want/support
def version_select
xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '8.*'"`.chomp.split("\n")
if xcodes.empty?
raise "\n[!!!] You need to have Xcode 8.x to compile SwiftGen.\n\n"
# print an info header
def self.print_info(str)
(red,clr) = (`tput colors`.chomp.to_i >= 8) ? %W(\e[33m \e[m) : ["", ""]
puts red, "== #{str.chomp} ==", clr
end

# 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")
end

# run a command using xcrun and xcpretty if applicable
def xcrun(cmd, task, subtask = '')
commands = [*cmd].map { |cmd|
"#{version_select} xcrun #{cmd}"
}
## [ Private helper functions ] ##################################################

# run a command, pipe output through 'xcpretty' and store the output in CI artifacts
def self.xcpretty(cmd, task, subtask)
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_")
command = [*cmd].join(' && ')

if commands.join.match('xcodebuild')
xcpretty(commands, task, subtask)
else
plain(commands, task, subtask)
if ENV['CI']
Rake.sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | xcpretty --color --report junit --output \"#{ENV['CIRCLE_TEST_REPORTS']}/xcode/#{name}.xml\""
elsif system('which xcpretty > /dev/null')
Rake.sh "set -o pipefail && (#{command}) | xcpretty -c"
else
Rake.sh command
end
end
end
private_class_method :xcpretty

# run a command and store the output in CI artifacts
def self.plain(cmd, task, subtask)
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_")
command = [*cmd].join(' && ')

if ENV['CI']
Rake.sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\""
else
Rake.sh command
end
end
private_class_method :plain

# select the xcode version we want/support
def self.version_select
xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '8.*'"`.chomp.split("\n")
if xcodes.empty?
raise "\n[!!!] You need to have Xcode 8.x to compile SwiftGen.\n\n"
end

# 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")
end
private_class_method :version_select

# print an info header
def print_info(str)
(red,clr) = (`tput colors`.chomp.to_i >= 8) ? %W(\e[33m \e[m) : ["", ""]
puts red, "== #{str.chomp} ==", clr
end
8 changes: 4 additions & 4 deletions rakelib/xcode.rake
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace :xcode do
desc 'Build using Xcode'
task :build do |task|
print_info 'Compile using Xcode'
xcrun(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task)
Utils.print_info 'Compile using Xcode'
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task, xcrun: true, xcpretty: true)
end

desc 'Run Xcode Unit Tests'
task :test => :build do |task|
print_info 'Run the unit tests using Xcode'
xcrun(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task)
Utils.print_info 'Run the unit tests using Xcode'
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, xcpretty: true)
end
end

0 comments on commit 99121eb

Please sign in to comment.