Class: Xcode::Builder::BaseBuilder

Inherits:
Object
  • Object
show all
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

ProjectTargetConfigBuilder, SchemeBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject

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

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/xcode/builder/base_builder.rb', line 9

def config
  @config
end

#identityObject

Returns the value of attribute identity.



8
9
10
# File 'lib/xcode/builder/base_builder.rb', line 8

def identity
  @identity
end

#keychainObject

Returns the value of attribute keychain.



8
9
10
# File 'lib/xcode/builder/base_builder.rb', line 8

def keychain
  @keychain
end

#objrootObject

Returns the value of attribute objroot.



8
9
10
# File 'lib/xcode/builder/base_builder.rb', line 8

def objroot
  @objroot
end

#profileObject

Returns the value of attribute profile.



8
9
10
# File 'lib/xcode/builder/base_builder.rb', line 8

def profile
  @profile
end

#sdkObject

Returns the value of attribute sdk.



8
9
10
# File 'lib/xcode/builder/base_builder.rb', line 8

def sdk
  @sdk
end

#symrootObject

Returns the value of attribute symroot.



8
9
10
# File 'lib/xcode/builder/base_builder.rb', line 8

def symroot
  @symroot
end

#targetObject (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_pathObject



151
152
153
# File 'lib/xcode/builder/base_builder.rb', line 151

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(options = {:sdk => @sdk})    
  cmd = xcodebuild
  cmd << "-sdk #{options[:sdk]}" unless options[:sdk].nil?

  with_keychain do
    cmd.execute
  end
  self
end

#build_environmentObject



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

#cleanObject



90
91
92
93
94
95
96
97
98
99
# File 'lib/xcode/builder/base_builder.rb', line 90

def clean
  cmd = xcodebuild 
  cmd << "-sdk #{@sdk}" unless @sdk.nil?          
  cmd << "clean"
  cmd.execute

  @built = false
  @packaged = false
  self
end

#common_environmentObject



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_pathObject



143
144
145
# File 'lib/xcode/builder/base_builder.rb', line 143

def configuration_build_path
  "#{build_path}/#{@config.name}-#{@sdk}"
end

#dsym_pathObject



165
166
167
# File 'lib/xcode/builder/base_builder.rb', line 165

def dsym_path
  "#{app_path}.dSYM"
end

#dsym_zip_pathObject



169
170
171
# File 'lib/xcode/builder/base_builder.rb', line 169

def dsym_zip_path
  "#{product_version_basename}.dSYM.zip"
end

#entitlements_pathObject



147
148
149
# File 'lib/xcode/builder/base_builder.rb', line 147

def entitlements_path
  "#{build_path}/#{@target.name}.build/#{name}-#{@target.project.sdk}/#{@target.name}.build/#{@config.product_name}.xcent"
end

#ipa_pathObject



161
162
163
# File 'lib/xcode/builder/base_builder.rb', line 161

def ipa_path
  "#{product_version_basename}.ipa"
end

#packageObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/xcode/builder/base_builder.rb', line 114

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_basenameObject



155
156
157
158
159
# File 'lib/xcode/builder/base_builder.rb', line 155

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

#signObject



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/xcode/builder/base_builder.rb', line 101

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(options = {:sdk => 'iphonesimulator'}) #, :parser => :OCUnit })
  cmd = xcodebuild
  cmd << "-sdk #{options[:sdk]}" unless options[: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

Yields:



81
82
83
84
85
86
87
88
# File 'lib/xcode/builder/base_builder.rb', line 81

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 fins #{dsym_zip_path}, do you need to call builder.package?" unless File.exists? dsym_zip_path

  testflight = Xcode::Testflight.new(api_token, team_token)
  yield(testflight) if block_given?
  testflight.upload(ipa_path, dsym_zip_path)
end