From 2fba79d214463d7b123e744f2f303680559b5280 Mon Sep 17 00:00:00 2001 From: Guido Marucci Blas Date: Wed, 7 Jan 2015 17:57:27 -0300 Subject: [PATCH] Uses xbuild gem to build the project. --- .travis.yml | 2 +- Example/.xbuild.yml | 4 ++ Example/Rakefile | 25 --------- Example/lib/xbuild.rb | 124 ------------------------------------------ Gemfile | 1 + Gemfile.lock | 3 + 6 files changed, 9 insertions(+), 150 deletions(-) create mode 100644 Example/.xbuild.yml delete mode 100644 Example/Rakefile delete mode 100644 Example/lib/xbuild.rb diff --git a/.travis.yml b/.travis.yml index ce6c2c8..f5a2735 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,6 @@ before_install: - brew update - brew outdated xctool || brew upgrade xctool script: - - cd Example && rake xbuild:clean xbuild:test + - cd Example && xbuild clean && xbuild test after_success: - cd .. && slather diff --git a/Example/.xbuild.yml b/Example/.xbuild.yml new file mode 100644 index 0000000..951be18 --- /dev/null +++ b/Example/.xbuild.yml @@ -0,0 +1,4 @@ +verbose: true +scheme: WLXBluetoothDeviceShared +workspace: WLXBluetoothDevice.xcworkspace +xctool: true diff --git a/Example/Rakefile b/Example/Rakefile deleted file mode 100644 index 4e0d607..0000000 --- a/Example/Rakefile +++ /dev/null @@ -1,25 +0,0 @@ -require './lib/xbuild' - -PROJECT = 'WLXBluetoothDevice' -WORKSPACE = "#{PROJECT}.xcworkspace" -SCHEME = "#{PROJECT}Shared" - -namespace :xbuild do - XBuild::ACTIONS.each do |action| - desc "Runs the #{action} action" - task action do - exit(1) unless xcodebuild.run(action) - end - end -end - -task default: 'xbuild:test' - -def xcodebuild - @xcodebuild ||= XBuild.new(WORKSPACE, SCHEME, { - dry_run: ENV['DRY_RUN'] == 'true', - verbose: ENV['VERBOSE'] == 'true', - pretty: !(ENV['DISABLE_XCPRETTY'] == 'true'), - xctool: !(ENV['USE_XCODEBUILD'] == 'true') - }) -end diff --git a/Example/lib/xbuild.rb b/Example/lib/xbuild.rb deleted file mode 100644 index 6c4dc85..0000000 --- a/Example/lib/xbuild.rb +++ /dev/null @@ -1,124 +0,0 @@ -class XBuild - - ACTIONS = %w( - clean - build - test - archive - analyze - install - ) - - DEFAULT_ACTION_ARGUMENTS = { - 'test' => { - 'sdk' => 'iphonesimulator' - } - } - - class << self - - def to_action_method_name(action) - if ACTIONS.include?(action) - action.downcase.gsub("-", "_") - end - end - - end - - attr_reader :workspace, :scheme - - def initialize(workspace, scheme, opts = {}) - @workspace = workspace - @scheme = scheme - opts = {verbose: false, dry_run: false, pretty: true, xctool: false}.merge(opts) - @pretty = opts[:pretty] - @verbose = opts[:verbose] - @dry_run = opts[:dry_run] - @xctool = opts[:xctool] - end - - def xctool? - @xctool - end - - def pretty? - !xctool? && @pretty - end - - def run(action, arguments = {}, options = {}) - success = false - if valid_action?(action) - options = default_base_options.merge(options) - arguments = DEFAULT_ACTION_ARGUMENTS.fetch(action, {}).merge(arguments) - command = build_command(action, arguments, options) - success = execute(command) - else - raise "Invalid action #{action}" - end - success - end - - def dry_run? - @dry_run - end - - def verbose? - @verbose - end - - ACTIONS.each do |action| - define_method(to_action_method_name(action)) do |*args| - run(action, *args) - end - end - - private - - def build_command(action, arguments, options) - options = to_options_string(options) - arguments = to_options_string(arguments) - cmd = "#{build_tool} #{options} #{action} #{arguments}".strip - cmd = pipe_xcpretty(cmd) if pretty? - cmd - end - - def build_tool - if xctool? - "xctool" - else - "xcodebuild" - end - end - - def execute(command) - log("Executing command '#{command}'") - system(command) unless dry_run? - end - - def valid_action?(action) - ACTIONS.include?(action) - end - - def log(message) - puts "#{self.class}: #{message}" if verbose? - end - - def default_base_options - @default_base_options ||= { workspace: workspace, scheme: scheme } - end - - def pipe_xcpretty(cmd) - "set -o pipefail && #{cmd} | xcpretty -c" - end - - def to_options_string(options = {}) - options.reduce("") do |options_string, (key, value)| - if value - options_string + " -#{key} #{value}" - else - options_string + " -#{key}" - end - end - end - -end diff --git a/Gemfile b/Gemfile index 52163b2..33f1e21 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,4 @@ gem 'rake' gem 'xcpretty' gem 'cocoapods', '~>0.35.0' gem 'slather' +gem 'xbuild' diff --git a/Gemfile.lock b/Gemfile.lock index 10ec5f8..2c200d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,6 +55,8 @@ GEM thread_safe (0.3.4) tzinfo (1.2.2) thread_safe (~> 0.1) + xbuild (0.1.0) + clamp (~> 0.6.3) xcodeproj (0.20.2) activesupport (>= 3) colored (~> 1.2) @@ -67,4 +69,5 @@ DEPENDENCIES cocoapods (~> 0.35.0) rake slather + xbuild xcpretty