Class: Xcode::Builder::BaseBuilder
- Inherits:
-
Object
- Object
- Xcode::Builder::BaseBuilder
- Defined in:
- lib/xcode/builder/base_builder.rb
Overview
This class tries to pull various bits of Xcoder together to provide a higher-level API for common project build tasks.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#build_path ⇒ Object
Returns the value of attribute build_path.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#identity ⇒ Object
Returns the value of attribute identity.
-
#keychain ⇒ Object
Returns the value of attribute keychain.
-
#objroot ⇒ Object
Returns the value of attribute objroot.
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#sdk ⇒ Object
Returns the value of attribute sdk.
-
#symroot ⇒ Object
Returns the value of attribute symroot.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #app_path ⇒ Object
- #build(options = {:sdk => @sdk}) ⇒ Object
- #build_environment ⇒ Object
- #clean ⇒ Object
- #common_environment ⇒ Object
- #configuration_build_path ⇒ Object
- #dsym_path ⇒ Object
- #dsym_zip_path ⇒ Object
- #entitlements_path ⇒ Object
-
#initialize(target, config) ⇒ BaseBuilder
constructor
A new instance of BaseBuilder.
- #ipa_path ⇒ Object
- #package ⇒ Object
- #product_version_basename ⇒ Object
- #sign ⇒ Object
-
#test(options = {:sdk => 'iphonesimulator'}) ⇒ Object
Invoke the configuration’s test target and parse the resulting output.
-
#testflight(api_token, team_token) {|testflight| ... } ⇒ Object
Upload to testflight.
Constructor Details
#initialize(target, config) ⇒ BaseBuilder
Returns a new instance of BaseBuilder.
11 12 13 14 15 16 17 18 19 |
# File 'lib/xcode/builder/base_builder.rb', line 11 def initialize(target, config) @target = target @config = config @sdk = @target.project.sdk @build_path = "#{File.dirname(@target.project.path)}/build/" @objroot = @build_path @symroot = @build_path end |
Instance Attribute Details
#build_path ⇒ Object
Returns the value of attribute build_path.
8 9 10 |
# File 'lib/xcode/builder/base_builder.rb', line 8 def build_path @build_path end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/xcode/builder/base_builder.rb', line 9 def config @config end |
#identity ⇒ Object
Returns the value of attribute identity.
8 9 10 |
# File 'lib/xcode/builder/base_builder.rb', line 8 def identity @identity end |
#keychain ⇒ Object
Returns the value of attribute keychain.
8 9 10 |
# File 'lib/xcode/builder/base_builder.rb', line 8 def keychain @keychain end |
#objroot ⇒ Object
Returns the value of attribute objroot.
8 9 10 |
# File 'lib/xcode/builder/base_builder.rb', line 8 def objroot @objroot end |
#profile ⇒ Object
Returns the value of attribute profile.
8 9 10 |
# File 'lib/xcode/builder/base_builder.rb', line 8 def profile @profile end |
#sdk ⇒ Object
Returns the value of attribute sdk.
8 9 10 |
# File 'lib/xcode/builder/base_builder.rb', line 8 def sdk @sdk end |
#symroot ⇒ Object
Returns the value of attribute symroot.
8 9 10 |
# File 'lib/xcode/builder/base_builder.rb', line 8 def symroot @symroot end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
9 10 11 |
# File 'lib/xcode/builder/base_builder.rb', line 9 def target @target end |
Instance Method Details
#app_path ⇒ Object
159 160 161 |
# File 'lib/xcode/builder/base_builder.rb', line 159 def app_path "#{configuration_build_path}/#{@config.product_name}.app" end |
#build(options = {:sdk => @sdk}) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/xcode/builder/base_builder.rb', line 38 def build( = {:sdk => @sdk}) cmd = xcodebuild cmd << "-sdk #{options[:sdk]}" unless [:sdk].nil? with_keychain do cmd.execute end self end |
#build_environment ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/xcode/builder/base_builder.rb', line 28 def build_environment profile = install_profile env = common_environment env["OTHER_CODE_SIGN_FLAGS"] = "'--keychain #{@keychain.path}'" unless @keychain.nil? env["CODE_SIGN_IDENTITY"] = "\"#{@identity}\"" unless @identity.nil? env["PROVISIONING_PROFILE"] = "#{profile.uuid}" unless profile.nil? env end |
#clean ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/xcode/builder/base_builder.rb', line 98 def clean cmd = xcodebuild cmd << "-sdk #{@sdk}" unless @sdk.nil? cmd << "clean" cmd.execute @built = false @packaged = false self end |
#common_environment ⇒ Object
21 22 23 24 25 26 |
# File 'lib/xcode/builder/base_builder.rb', line 21 def common_environment env = {} env["OBJROOT"] = "\"#{@objroot}\"" env["SYMROOT"] = "\"#{@symroot}\"" env end |
#configuration_build_path ⇒ Object
151 152 153 |
# File 'lib/xcode/builder/base_builder.rb', line 151 def configuration_build_path "#{build_path}/#{@config.name}-#{@sdk}" end |
#dsym_path ⇒ Object
173 174 175 |
# File 'lib/xcode/builder/base_builder.rb', line 173 def dsym_path "#{app_path}.dSYM" end |
#dsym_zip_path ⇒ Object
177 178 179 |
# File 'lib/xcode/builder/base_builder.rb', line 177 def dsym_zip_path "#{product_version_basename}.dSYM.zip" end |
#entitlements_path ⇒ Object
155 156 157 |
# File 'lib/xcode/builder/base_builder.rb', line 155 def entitlements_path "#{build_path}/#{@target.name}.build/#{name}-#{@target.project.sdk}/#{@target.name}.build/#{@config.product_name}.xcent" end |
#ipa_path ⇒ Object
169 170 171 |
# File 'lib/xcode/builder/base_builder.rb', line 169 def ipa_path "#{product_version_basename}.ipa" end |
#package ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/xcode/builder/base_builder.rb', line 122 def package raise "Can't find #{app_path}, do you need to call builder.build?" unless File.exists? app_path #package IPA cmd = Xcode::Shell::Command.new 'xcrun' cmd << "-sdk #{@sdk}" unless @sdk.nil? cmd << "PackageApplication" cmd << "-v \"#{app_path}\"" cmd << "-o \"#{ipa_path}\"" unless @profile.nil? cmd << "--embed \"#{@profile}\"" end with_keychain do cmd.execute end # package dSYM cmd = Xcode::Shell::Command.new 'zip' cmd << "-r" cmd << "-T" cmd << "-y \"#{dsym_zip_path}\"" cmd << "\"#{dsym_path}\"" cmd.execute self end |
#product_version_basename ⇒ Object
163 164 165 166 167 |
# File 'lib/xcode/builder/base_builder.rb', line 163 def product_version_basename version = @config.info_plist.version version = "SNAPSHOT" if version.nil? or version=="" "#{configuration_build_path}/#{@config.product_name}-#{@config.name}-#{version}" end |
#sign ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/xcode/builder/base_builder.rb', line 109 def sign cmd = Xcode::Shell::Command.new 'codesign' cmd << "--force" cmd << "--sign \"#{@identity}\"" cmd << "--resource-rules=\"#{app_path}/ResourceRules.plist\"" cmd << "--entitlements \"#{entitlements_path}\"" cmd << "\"#{ipa_path}\"" cmd.execute self end |
#test(options = {:sdk => 'iphonesimulator'}) ⇒ Object
Invoke the configuration’s test target and parse the resulting output
If a block is provided, the report is yielded for configuration before the test is run
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/xcode/builder/base_builder.rb', line 53 def test( = {:sdk => 'iphonesimulator'}) #, :parser => :OCUnit }) cmd = xcodebuild cmd << "-sdk #{options[:sdk]}" unless [:sdk].nil? cmd.env["TEST_AFTER_BUILD"]="YES" report = Xcode::Test::Report.new if block_given? yield(report) else report.add_formatter :stdout report.add_formatter :junit, 'test-reports' end parser = Xcode::Test::Parsers::OCUnitParser.new report begin cmd.execute(false) do |line| parser << line end rescue Xcode::Shell::ExecutionError => e puts "Test platform exited: #{e.message}" ensure parser.flush end report end |
#testflight(api_token, team_token) {|testflight| ... } ⇒ Object
Upload to testflight
The testflight object is yielded so further configuration can be performed before uploading
89 90 91 92 93 94 95 96 |
# File 'lib/xcode/builder/base_builder.rb', line 89 def testflight(api_token, team_token) raise "Can't find #{ipa_path}, do you need to call builder.package?" unless File.exists? ipa_path raise "Can't find #{dsym_zip_path}, do you need to call builder.package?" unless File.exists? dsym_zip_path testflight = Xcode::Deploy::Testflight.new(api_token, team_token) yield(testflight) if block_given? testflight.upload(ipa_path, dsym_zip_path) end |