Skip to content
Open
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pkg
website/_site
*.gem
*.DS_Store
xcodebuilder.gemspec
*.DS_Store
50 changes: 41 additions & 9 deletions lib/xcode_builder.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does capture give you here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its to support getting xcode settings, the results are provided on STDOUT.

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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this meant to be used? For purely informative purposes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More than that. By default xcode will create builds under ~/Library/Developer/Xcode/DerivedData/etc. This method allows calling code to figure out exactly where that is (its the TARGET_DIR key in the resulting hash table). This is an alternative to specifying build_dir. In our case, we prefer to stick with the xcode defaults thus this is needed.

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
Expand All @@ -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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/xcode_builder/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions xcodebuilder.gemspec
Original file line number Diff line number Diff line change
@@ -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 = ["[email protected]"]
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<CFPropertyList>, [">= 2.0.0"])
s.add_runtime_dependency(%q<uuid>, ["~> 2.3.1"])
s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.1"])
s.add_runtime_dependency(%q<json>, [">= 0"])
s.add_runtime_dependency(%q<cocoapods>, [">= 0"])
s.add_runtime_dependency(%q<xcpretty>, [">= 0"])
else
s.add_dependency(%q<CFPropertyList>, [">= 2.0.0"])
s.add_dependency(%q<uuid>, ["~> 2.3.1"])
s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<cocoapods>, [">= 0"])
s.add_dependency(%q<xcpretty>, [">= 0"])
end
else
s.add_dependency(%q<CFPropertyList>, [">= 2.0.0"])
s.add_dependency(%q<uuid>, ["~> 2.3.1"])
s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<cocoapods>, [">= 0"])
s.add_dependency(%q<xcpretty>, [">= 0"])
end
end