require 'rake/tasklib' require 'rubygems' require 'xcodebuild' require 'cucumber/rake/task' require 'core_data' require 'erb' require 'xcodeproj' require 'fwtoolkit/tasks/helper' module XcodeBuild def self.run(args = "", output_buffer = STDOUT) command = "xcodebuild #{args} DSTROOT=/tmp/artifacts 2>&1" #puts command IO.popen(command) do |io| begin while line = io.readline begin output_buffer << line rescue StandardError => e puts "Error from output buffer: #{e.inspect}" puts e.backtrace end end rescue EOFError end end $?.exitstatus end end module FWToolkit module Tasks class BuildTask < ::Rake::TaskLib TEMPLATES_DIR = File.expand_path('../../../templates/', File.dirname(__FILE__)) include Rake::DSL if defined?(Rake::DSL) attr_accessor :workspace attr_accessor :scheme attr_accessor :project attr_accessor :certificate attr_accessor :provisioning_profile def initialize(&block) yield self if block_given? define end private def define namespace :xcode do XcodeBuild::Tasks::BuildTask.new :debug_simulator do |t| t.invoke_from_within = '.' t.configuration = "Debug" t.sdk = "iphonesimulator" t.workspace = @workspace t.scheme = @scheme t.formatter = XcodeBuild::Formatters::ProgressFormatter.new end XcodeBuild::Tasks::BuildTask.new :release_iphoneos do |t| t.invoke_from_within = '.' t.configuration = "Release" t.sdk = "iphoneos" t.workspace = @workspace t.scheme = @scheme #t.formatter = XcodeBuild::Formatters::ProgressFormatter.new t.output_to = FWToolkit::Tasks.cc_artifacts_dir end task :ipa do configuration = 'Release' # update the project file to use the correct cert/provisioning signature_settings = { "CODE_SIGN_IDENTITY"=> self.certificate, "PROVISIONING_PROFILE"=> self.provisioning_profile } p = Xcodeproj::Project.new self.project p.targets[0].build_settings(configuration).merge!(signature_settings) p.save_as self.project artifacts_dir = FWToolkit::Tasks.cc_artifacts_dir sh %{bundle exec ipa build -s #{self.scheme} -c #{configuration} --clean} end task :validate_auth_token do unless ENV['HOCKEY_APP_TOKEN'] abort 'Please set HOCKEY_APP_TOKEN environment variable in ~/.bashrc (HOCKEY_APP_TOKEN=; export HOCKEY_APP_TOKEN)' end end task :upload do token = ENV['HOCKEY_APP_TOKEN'] artifacts_dir = FWToolkit::Tasks.cc_artifacts_dir sh %{bundle exec ipa distribute:hockeyapp --token #{token} -m ""} end desc 'Build and Upload IPA' task :build_upload => [:validate_auth_token, :ipa, :upload] end namespace :frank do desc 'Build the frankified App' task :build do sh "frank build --workspace #{@workspace} --scheme #{@scheme}" end end end end end end