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 495bb5c commit 4714161
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 62 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 code'
task :code => :install do |task|
print_info 'Linting the code'
plain(%Q(swiftlint lint --no-cache --strict --path Sources), task)
Utils.print_info 'Linting the code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path Sources), task)
end

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/#{POD_NAME}Tests"), task)
Utils.print_info 'Linting the unit test code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path "Tests/#{POD_NAME}Tests"), task)
end
end
4 changes: 2 additions & 2 deletions rakelib/pod.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace :pod do
desc 'Lint the Pod'
task :lint do |task|
print_info 'Linting the pod spec'
plain(%Q(pod lib lint "#{POD_NAME}.podspec" --quick), task)
Utils.print_info 'Linting the pod spec'
Utils.run(%Q(pod lib lint "#{POD_NAME}.podspec" --quick), task)
end
end
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 4714161

Please sign in to comment.