diff --git a/.gitignore b/.gitignore index 45170f0..d5c6306 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ pkg website/_site *.gem -*.DS_Store -xcodebuilder.gemspec +*.DS_Store \ No newline at end of file diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index 40f050f..4b4d7f3 100644 --- a/lib/xcode_builder.rb +++ b/lib/xcode_builder.rb @@ -1,6 +1,7 @@ require 'rake/tasklib' require 'ostruct' require 'fileutils' +require 'open3' require 'cfpropertylist' require File.dirname(__FILE__) + '/xcode_builder/configuration' require File.dirname(__FILE__) + '/xcode_builder/build_output_parser' @@ -12,7 +13,7 @@ class XcodeBuilder def initialize(namespace = :xcbuild, &block) @configuration = Configuration.new( :configuration => "Release", - :build_dir => "build", + :build_dir => nil, :project_file_path => nil, :workspace_file_path => nil, :scheme => nil, @@ -23,6 +24,7 @@ def initialize(namespace = :xcbuild, &block) :verbose => false, :info_plist => nil, :scm => nil, + :sdk => "iphoneos", :pod_repo => nil, :podspec_file => nil, :xcodebuild_extra_args => nil, @@ -37,26 +39,56 @@ def initialize(namespace = :xcbuild, &block) @configuration.info_plist = File.expand_path @configuration.info_plist unless @configuration.info_plist == nil end - def xcodebuild(*args) + def xcodebuild(capture, *args) # we're using tee as we still want to see our build output on screen cmd = [] cmd << "xcrun xcodebuild" cmd.concat args puts "Running: #{cmd.join(" ")}" if @configuration.verbose - cmd << "| xcpretty && exit ${PIPESTATUS[0]}" cmd = cmd.join(" ") - system(cmd) + + if capture + Open3.capture3(cmd) + else + cmd += "| xcpretty && exit ${PIPESTATUS[0]}" + system(cmd) + end end # desc "Clean the Build" def clean unless @configuration.skip_clean print "Cleaning Project..." - xcodebuild @configuration.build_arguments, "clean" + xcodebuild(false, @configuration.build_arguments, "clean") puts "Done" end end - + + # desc "Get xcode settings" + def settings + print "Getting Build Settings..." << "\n" + stdout, stderr, status = xcodebuild(true, @configuration.build_arguments, "-showBuildSettings") + + unless stderr.empty? + raise(stderr) + end + + target = nil + stdout.split(/\n/).inject(Hash.new) do |hash, line| + match = line.match(/Build settings for action build and target \"?([^":]+)/) + if match + target = match[1] + hash[target] = Hash.new + elsif target + parts = line.split('=') + unless parts.empty? + hash[target][parts.first.strip!] = parts.last.strip! + end + end + hash + end + end + # desc "Build the beta release of the app" def build clean unless @configuration.skip_clean @@ -65,8 +97,9 @@ def build @configuration.timestamp_plist if @configuration.timestamp_build print "Building Project..." - success = xcodebuild @configuration.build_arguments, "build" - raise "** BUILD FAILED **" unless success + + success = xcodebuild(false, @configuration.build_arguments, "build") + raise "** BUILD FAILED **}" unless success puts "Done" end @@ -81,7 +114,6 @@ def package end # trash and create the dist IPA path if needed - FileUtils.rm_rf @configuration.package_destination_path unless !File.exists? @configuration.package_destination_path FileUtils.mkdir_p @configuration.package_destination_path # Construct the IPA and Sign it diff --git a/lib/xcode_builder/configuration.rb b/lib/xcode_builder/configuration.rb index 7258fef..b120846 100644 --- a/lib/xcode_builder/configuration.rb +++ b/lib/xcode_builder/configuration.rb @@ -21,10 +21,10 @@ def build_arguments args << "-project '#{project_file_path}'" if project_file_path end - args << "-sdk iphoneos" - + args << "-sdk #{sdk}" + args << "-configuration '#{configuration}'" - args << "BUILD_DIR=#{File.expand_path build_dir}" + args << "BUILD_DIR=#{File.expand_path build_dir}" if build_dir if xcodebuild_extra_args args.concat xcodebuild_extra_args if xcodebuild_extra_args.is_a? Array diff --git a/xcodebuilder.gemspec b/xcodebuilder.gemspec new file mode 100644 index 0000000..65ce1c9 --- /dev/null +++ b/xcodebuilder.gemspec @@ -0,0 +1,46 @@ +# -*- encoding: utf-8 -*- +# stub: xcodebuilder 0.1.1 ruby lib + +Gem::Specification.new do |s| + s.name = "xcodebuilder" + s.version = "0.1.1" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.require_paths = ["lib"] + s.authors = ["Olivier Larivain"] + s.date = "2014-10-30" + s.email = ["olarivain@gmail.com"] + s.extra_rdoc_files = ["README.md", "LICENSE", "CHANGES.md"] + s.files = ["CHANGES.md", "LICENSE", "README.md", "lib/xcode_builder", "lib/xcode_builder.rb", "lib/xcode_builder/build_output_parser.rb", "lib/xcode_builder/configuration.rb", "lib/xcode_builder/deployment_strategies", "lib/xcode_builder/deployment_strategies.rb", "lib/xcode_builder/deployment_strategies/testflight.rb", "lib/xcode_builder/release_strategies", "lib/xcode_builder/release_strategies.rb", "lib/xcode_builder/release_strategies/git.rb", "lib/xcodebuilder.rb"] + s.homepage = "http://github.com/olarivain/xcodebuilder" + s.rdoc_options = ["--main", "README.md"] + s.rubygems_version = "2.4.2" + s.summary = "A set of Rake tasks and utilities for building and releasing xcode projects" + + if s.respond_to? :specification_version then + s.specification_version = 4 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 2.0.0"]) + s.add_runtime_dependency(%q, ["~> 2.3.1"]) + s.add_runtime_dependency(%q, ["~> 1.6.1"]) + s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 0"]) + else + s.add_dependency(%q, [">= 2.0.0"]) + s.add_dependency(%q, ["~> 2.3.1"]) + s.add_dependency(%q, ["~> 1.6.1"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + end + else + s.add_dependency(%q, [">= 2.0.0"]) + s.add_dependency(%q, ["~> 2.3.1"]) + s.add_dependency(%q, ["~> 1.6.1"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + end +end