From 438fca57c48a3002c7902802c8b17946a8568fcf Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Wed, 29 Oct 2014 22:29:59 -0600 Subject: [PATCH 01/10] Make the sdk and arch configurable so we can make builds for the simulator. --- lib/xcode_builder.rb | 2 ++ lib/xcode_builder/configuration.rb | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index 40f050f..d14d0a3 100644 --- a/lib/xcode_builder.rb +++ b/lib/xcode_builder.rb @@ -23,6 +23,8 @@ def initialize(namespace = :xcbuild, &block) :verbose => false, :info_plist => nil, :scm => nil, + :arch => nil, + :sdk => "iphoneos", :pod_repo => nil, :podspec_file => nil, :xcodebuild_extra_args => nil, diff --git a/lib/xcode_builder/configuration.rb b/lib/xcode_builder/configuration.rb index 7258fef..ae67485 100644 --- a/lib/xcode_builder/configuration.rb +++ b/lib/xcode_builder/configuration.rb @@ -21,8 +21,9 @@ def build_arguments args << "-project '#{project_file_path}'" if project_file_path end - args << "-sdk iphoneos" - + args << "-sdk #{sdk}" + args << "-arch #{arch}" if arch + args << "-configuration '#{configuration}'" args << "BUILD_DIR=#{File.expand_path build_dir}" From c96b8b03722f170f248df8b17175d0fb8b211d3d Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Wed, 29 Oct 2014 22:31:52 -0600 Subject: [PATCH 02/10] By default let xcodebuild dir, but allow overriding by setting the build_dir directory. --- lib/xcode_builder.rb | 2 +- lib/xcode_builder/configuration.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index d14d0a3..bde5e50 100644 --- a/lib/xcode_builder.rb +++ b/lib/xcode_builder.rb @@ -12,7 +12,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, diff --git a/lib/xcode_builder/configuration.rb b/lib/xcode_builder/configuration.rb index ae67485..32f8ec2 100644 --- a/lib/xcode_builder/configuration.rb +++ b/lib/xcode_builder/configuration.rb @@ -25,7 +25,7 @@ def build_arguments args << "-arch #{arch}" if arch 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 From 16cd51239a16a30a2dd0ede5d68457528c02f905 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Wed, 29 Oct 2014 22:37:44 -0600 Subject: [PATCH 03/10] Make Xcode build more flexible when running commands - needed for next commit that add support for getting build settings. --- lib/xcode_builder.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index bde5e50..3349286 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' @@ -39,15 +40,20 @@ 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" @@ -67,8 +73,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 From 626393f0e5f0c2593d06234dc29598e092f3cf7e Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Wed, 29 Oct 2014 22:37:59 -0600 Subject: [PATCH 04/10] Add support for getting builds settings from Xcode. --- lib/xcode_builder.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index 3349286..b3fb204 100644 --- a/lib/xcode_builder.rb +++ b/lib/xcode_builder.rb @@ -64,7 +64,28 @@ def clean puts "Done" end end - + + # desc "Get xcode settings" + def settings + print "Getting Settings..." << "\n" + stdout, stderr, status = xcodebuild(true, @configuration.build_arguments, "-showBuildSettings") + + 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 From b290c805be8f01f8cd92e8dd326707c668ced5e6 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Wed, 29 Oct 2014 22:38:52 -0600 Subject: [PATCH 05/10] Don't delete the package directory - that should be left up to code calling this gem. --- lib/xcode_builder.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index b3fb204..defed90 100644 --- a/lib/xcode_builder.rb +++ b/lib/xcode_builder.rb @@ -111,7 +111,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 From c9953397b4db6332ad3121df9600902642f1f324 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Fri, 31 Oct 2014 20:11:32 -0600 Subject: [PATCH 06/10] Remove arch, sdks is good enough to create builds for the simulator. --- lib/xcode_builder.rb | 1 - lib/xcode_builder/configuration.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index defed90..5b2c140 100644 --- a/lib/xcode_builder.rb +++ b/lib/xcode_builder.rb @@ -24,7 +24,6 @@ def initialize(namespace = :xcbuild, &block) :verbose => false, :info_plist => nil, :scm => nil, - :arch => nil, :sdk => "iphoneos", :pod_repo => nil, :podspec_file => nil, diff --git a/lib/xcode_builder/configuration.rb b/lib/xcode_builder/configuration.rb index 32f8ec2..b120846 100644 --- a/lib/xcode_builder/configuration.rb +++ b/lib/xcode_builder/configuration.rb @@ -22,7 +22,6 @@ def build_arguments end args << "-sdk #{sdk}" - args << "-arch #{arch}" if arch args << "-configuration '#{configuration}'" args << "BUILD_DIR=#{File.expand_path build_dir}" if build_dir From 8f1a45d1cd7cd6b3a680aa419c6d81a8213ee62f Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Fri, 31 Oct 2014 20:12:27 -0600 Subject: [PATCH 07/10] Make message slightly more informative. --- lib/xcode_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index 5b2c140..6cb84ed 100644 --- a/lib/xcode_builder.rb +++ b/lib/xcode_builder.rb @@ -66,7 +66,7 @@ def clean # desc "Get xcode settings" def settings - print "Getting Settings..." << "\n" + print "Getting Build Settings..." << "\n" stdout, stderr, status = xcodebuild(true, @configuration.build_arguments, "-showBuildSettings") target = nil From 97bebd778c5b2a30e02613fa0ab267c6f95762ab Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Sun, 2 Nov 2014 10:50:54 -0700 Subject: [PATCH 08/10] Put gem spec in github so we can use it from bundler. --- .gitignore | 3 +-- xcodebuilder.gemspec | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 xcodebuilder.gemspec 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/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 From 6c65965584d1c56f5c14f99918ba0baa6b9af0c5 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Thu, 6 Nov 2014 20:30:48 -0700 Subject: [PATCH 09/10] Print out error to console and return nil. --- lib/xcode_builder.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index 6cb84ed..f090944 100644 --- a/lib/xcode_builder.rb +++ b/lib/xcode_builder.rb @@ -69,6 +69,11 @@ def settings print "Getting Build Settings..." << "\n" stdout, stderr, status = xcodebuild(true, @configuration.build_arguments, "-showBuildSettings") + unless stderr.empty? + STDERR << stderr + return nil + end + target = nil stdout.split(/\n/).inject(Hash.new) do |hash, line| match = line.match(/Build settings for action build and target \"?([^":]+)/) From 8c8eb8d479dddd9462f2a904b6e0edb20adf5f18 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Mon, 15 Dec 2014 11:45:54 -0700 Subject: [PATCH 10/10] Fix clean by adding extra capture parameter. --- lib/xcode_builder.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/xcode_builder.rb b/lib/xcode_builder.rb index f090944..4b4d7f3 100644 --- a/lib/xcode_builder.rb +++ b/lib/xcode_builder.rb @@ -59,7 +59,7 @@ def xcodebuild(capture, *args) def clean unless @configuration.skip_clean print "Cleaning Project..." - xcodebuild @configuration.build_arguments, "clean" + xcodebuild(false, @configuration.build_arguments, "clean") puts "Done" end end @@ -70,8 +70,7 @@ def settings stdout, stderr, status = xcodebuild(true, @configuration.build_arguments, "-showBuildSettings") unless stderr.empty? - STDERR << stderr - return nil + raise(stderr) end target = nil