From 73b0114df68b2d8f2a3a3ecafa4793c5ed3f9576 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Fri, 10 Mar 2017 22:15:27 +0100 Subject: [PATCH] Gemfile (#28) --- .gitignore | 12 +++++-- CHANGELOG.md | 4 ++- Gemfile | 5 +++ Gemfile.lock | 77 ++++++++++++++++++++++++++++++++++++++++++ Rakefile | 3 +- circle.yml | 3 +- rakelib/changelog.rake | 3 ++ rakelib/lint.rake | 41 ++++++++++++++-------- rakelib/pod.rake | 15 +++++--- rakelib/spm.rake | 25 ++++++++------ rakelib/utils.rake | 77 ++++++++++++++++++++++++++++++++++++------ rakelib/xcode.rake | 13 ++++--- 12 files changed, 227 insertions(+), 51 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index 918f2a64..89b874c3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ ## Build generated build/ DerivedData/ +Fixtures/stub-env/**/*.swiftmodule ## Various settings *.pbxuser @@ -49,8 +50,7 @@ Packages/ # Carthage # # Add this line if you want to avoid checking in source code from Carthage dependencies. -# Carthage/Checkouts - +Carthage/Checkouts Carthage/Build # fastlane @@ -64,3 +64,11 @@ fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output + +# Other stuff +.apitoken +.DS_Store +.idea/ +bin/ +Frameworks/ +Rome/ diff --git a/CHANGELOG.md b/CHANGELOG.md index f2114cc7..3d1f7bed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,9 @@ _None_ ### Internal Changes -_None_ +* Further refactor the Rakefile into rakelibs, and add a Gemfile for gem dependencies. + [David Jennes](https://github.com/djbe) + [#28](https://github.com/SwiftGen/SwiftGenKit/issues/28) ## 1.0.1 diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..8c13227b --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true +source 'https://rubygems.org' + +gem 'cocoapods', '1.2.0' +gem 'xcpretty' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..d40e2b70 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,77 @@ +GEM + remote: https://rubygems.org/ + specs: + CFPropertyList (2.3.5) + activesupport (4.2.8) + i18n (~> 0.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + claide (1.0.1) + cocoapods (1.2.0) + activesupport (>= 4.0.2, < 5) + claide (>= 1.0.1, < 2.0) + cocoapods-core (= 1.2.0) + cocoapods-deintegrate (>= 1.0.1, < 2.0) + cocoapods-downloader (>= 1.1.3, < 2.0) + cocoapods-plugins (>= 1.0.0, < 2.0) + cocoapods-search (>= 1.0.0, < 2.0) + cocoapods-stats (>= 1.0.0, < 2.0) + cocoapods-trunk (>= 1.1.2, < 2.0) + cocoapods-try (>= 1.1.0, < 2.0) + colored (~> 1.2) + escape (~> 0.0.4) + fourflusher (~> 2.0.1) + gh_inspector (~> 1.0) + molinillo (~> 0.5.5) + nap (~> 1.0) + ruby-macho (~> 0.2.5) + xcodeproj (>= 1.4.1, < 2.0) + cocoapods-core (1.2.0) + activesupport (>= 4.0.2, < 5) + fuzzy_match (~> 2.0.4) + nap (~> 1.0) + cocoapods-deintegrate (1.0.1) + cocoapods-downloader (1.1.3) + cocoapods-plugins (1.0.0) + nap + cocoapods-search (1.0.0) + cocoapods-stats (1.0.0) + cocoapods-trunk (1.1.2) + nap (>= 0.8, < 2.0) + netrc (= 0.7.8) + cocoapods-try (1.1.0) + colored (1.2) + escape (0.0.4) + fourflusher (2.0.1) + fuzzy_match (2.0.4) + gh_inspector (1.0.3) + i18n (0.8.1) + minitest (5.10.1) + molinillo (0.5.6) + nanaimo (0.2.3) + nap (1.1.0) + netrc (0.7.8) + rouge (1.11.1) + ruby-macho (0.2.6) + thread_safe (0.3.6) + tzinfo (1.2.2) + thread_safe (~> 0.1) + xcodeproj (1.4.2) + CFPropertyList (~> 2.3.3) + activesupport (>= 3) + claide (>= 1.0.1, < 2.0) + colored (~> 1.2) + nanaimo (~> 0.2.3) + xcpretty (0.2.4) + rouge (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + cocoapods (= 1.2.0) + xcpretty + +BUNDLED WITH + 1.13.7 diff --git a/Rakefile b/Rakefile index 0373bc99..a62b43b0 100644 --- a/Rakefile +++ b/Rakefile @@ -3,10 +3,9 @@ ## [ Constants ] ############################################################## WORKSPACE = 'StencilSwiftKit' -TARGET_NAME = 'Tests' +SCHEME_NAME = 'Tests' CONFIGURATION = 'Debug' POD_NAME = 'StencilSwiftKit' -TEST_PATH = "Tests/#{POD_NAME}Tests" task :default => 'xcode:test' diff --git a/circle.yml b/circle.yml index ebf5c02d..2c9e0261 100644 --- a/circle.yml +++ b/circle.yml @@ -3,8 +3,7 @@ machine: version: 8.2 dependencies: - pre: - - gem install xcpretty --no-rdoc --no-ri --no-document --quiet + post: - rake lint:install - curl -sS https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash diff --git a/rakelib/changelog.rake b/rakelib/changelog.rake index 0df3283e..ddc630be 100644 --- a/rakelib/changelog.rake +++ b/rakelib/changelog.rake @@ -1,3 +1,6 @@ +# Used constants: +# none + namespace :changelog do desc 'Add the empty CHANGELOG entries after a new release' task :reset do |task| diff --git a/rakelib/lint.rake b/rakelib/lint.rake index c6ac457f..c5aa2c00 100644 --- a/rakelib/lint.rake +++ b/rakelib/lint.rake @@ -1,26 +1,39 @@ +# Used constants: +# - WORKSPACE + namespace :lint do desc 'Install swiftlint' task :install do |task| - if !system('which swiftlint > /dev/null') - url = 'https://github.com/realm/SwiftLint/releases/download/0.16.1/SwiftLint.pkg' - tmppath = '/tmp/SwiftLint.pkg' + next if system('which swiftlint > /dev/null') - Utils.run([ - "curl -Lo #{tmppath} #{url}", - "sudo installer -pkg #{tmppath} -target /" - ], task) - end + url = 'https://github.com/realm/SwiftLint/releases/download/0.16.1/SwiftLint.pkg' + tmppath = '/tmp/SwiftLint.pkg' + + Utils.run([ + "curl -Lo #{tmppath} #{url}", + "sudo installer -pkg #{tmppath} -target /" + ], task) end - desc 'Lint the code' - task :code => :install do |task| - Utils.print_info 'Linting the code' - Utils.run(%Q(swiftlint lint --no-cache --strict --path Sources), task) + if File.directory?('Sources') + desc 'Lint the code' + task :code => :install do |task| + Utils.print_header 'Linting the code' + Utils.run(%Q(swiftlint lint --no-cache --strict --path Sources), task) + end end desc 'Lint the tests' task :tests => :install do |task| - Utils.print_info 'Linting the unit test code' - Utils.run(%Q(swiftlint lint --no-cache --strict --path "#{TEST_PATH}"), task) + Utils.print_header 'Linting the unit test code' + Utils.run(%Q(swiftlint lint --no-cache --strict --path "Tests/#{WORKSPACE}Tests"), task) + end + + if File.directory?('Tests/Expected') + desc 'Lint the output' + task :output => :install do |task| + Utils.print_header 'Linting the template output code' + Utils.run(%Q(swiftlint lint --no-cache --strict --path Tests/Expected), task) + end end end diff --git a/rakelib/pod.rake b/rakelib/pod.rake index a0e32b5b..9a9ecaca 100644 --- a/rakelib/pod.rake +++ b/rakelib/pod.rake @@ -1,7 +1,12 @@ -namespace :pod do - desc 'Lint the Pod' - task :lint do |task| - Utils.print_info 'Linting the pod spec' - Utils.run(%Q(pod lib lint "#{POD_NAME}.podspec" --quick), task) +# Used constants: +# - POD_NAME + +if defined?(POD_NAME) && File.file?("#{POD_NAME}.podspec") + namespace :pod do + desc 'Lint the Pod' + task :lint do |task| + Utils.print_header 'Linting the pod spec' + Utils.run(%Q(bundle exec pod lib lint "#{POD_NAME}.podspec" --quick), task) + end end end diff --git a/rakelib/spm.rake b/rakelib/spm.rake index 3526e1f1..1282ceaa 100644 --- a/rakelib/spm.rake +++ b/rakelib/spm.rake @@ -1,13 +1,18 @@ -namespace :spm do - desc 'Build using SPM' - task :build do |task| - Utils.print_info 'Compile using SPM' - Utils.run("swift build", task, xcrun: true) - end +# Used constants: +# none + +if File.file?('Package.swift') + namespace :spm do + desc 'Build using SPM' + task :build do |task| + Utils.print_header 'Compile using SPM' + Utils.run('swift build', task, xcrun: true) + end - desc 'Run SPM Unit Tests' - task :test => :build do |task| - Utils.print_info 'Run the unit tests using SPM' - Utils.run("swift test", task, xcrun: true) + desc 'Run SPM Unit Tests' + task :test => :build do |task| + Utils.print_header 'Run the unit tests using SPM' + Utils.run('swift test', task, xcrun: true) + end end end diff --git a/rakelib/utils.rake b/rakelib/utils.rake index bb7a1f08..a87ce321 100644 --- a/rakelib/utils.rake +++ b/rakelib/utils.rake @@ -1,24 +1,39 @@ +# Used constants: +# none + class Utils + # formatter types + :xcpretty # pass through xcpretty and store in artifacts + :raw # store in artifacts + :to_string # run using backticks and return output # run a command using xcrun and xcpretty if applicable - def self.run(cmd, task, subtask = '', xcrun: false, xcpretty: false, direct: false) + def self.run(cmd, task, subtask = '', xcrun: false, formatter: :raw) commands = xcrun ? [*cmd].map { |cmd| "#{version_select} xcrun #{cmd}" } : [*cmd] - if xcpretty - xcpretty(commands, task, subtask) - elsif !direct - plain(commands, task, subtask) - else - `#{commands.join(' && ')}` + case formatter + when :xcpretty then xcpretty(commands, task, subtask) + when :raw then plain(commands, task, subtask) + when :to_string then `#{commands.join(' && ')}` + else raise "Unknown formatter '#{formatter}'" end end # print an info header + def self.print_header(str) + puts "== #{str.chomp} ==".format(:yellow, :bold) + end + + # print an info message def self.print_info(str) - (red,clr) = (`tput colors`.chomp.to_i >= 8) ? %W(\e[33m \e[m) : ["", ""] - puts red, "== #{str.chomp} ==", clr + puts str.chomp.format(:green) + end + + # print an error message + def self.print_error(str) + puts str.chomp.format(:red) end ## [ Private helper functions ] ################################################## @@ -29,9 +44,9 @@ class Utils command = [*cmd].join(' && ') 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\"" + Rake.sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | bundle exec 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" + Rake.sh "set -o pipefail && (#{command}) | bundle exec xcpretty -c" else Rake.sh command end @@ -64,5 +79,45 @@ class Utils %Q(DEVELOPER_DIR="#{latest_xcode_version}/Contents/Developer") end private_class_method :version_select +end + + +class String + # colorization + FORMATTING = { + # text styling + :bold => 1, + :faint => 2, + :italic => 3, + :underline => 4, + # foreground colors + :black => 30, + :red => 31, + :green => 32, + :yellow => 33, + :blue => 34, + :magenta => 35, + :cyan => 36, + :white => 37, + # background colors + :bg_black => 40, + :bg_red => 41, + :bg_green => 42, + :bg_yellow => 43, + :bg_blue => 44, + :bg_magenta => 45, + :bg_cyan => 46, + :bg_white => 47 + } + # only enable formatting if terminal supports it + if `tput colors`.chomp.to_i >= 8 + def format(*styles) + styles.reduce("") { |r, s| r << "\e[#{FORMATTING[s]}m" } << "#{self}\e[0m" + end + else + def format(*styles) + self + end + end end diff --git a/rakelib/xcode.rake b/rakelib/xcode.rake index d3c2aa4b..c66f4c14 100644 --- a/rakelib/xcode.rake +++ b/rakelib/xcode.rake @@ -1,13 +1,18 @@ +# Used constants: +# - CONFIGURATION +# - SCHEME_NAME +# - WORKSPACE + namespace :xcode do desc 'Build using Xcode' task :build do |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) + Utils.print_header 'Compile using Xcode' + Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task, xcrun: true, formatter: :xcpretty) end desc 'Run Xcode Unit Tests' task :test => :build do |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) + Utils.print_header 'Run the unit tests using Xcode' + Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, formatter: :xcpretty) end end