Class: XcodeBuilder::XcodeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace = :xcbuild) {|@configuration| ... } ⇒ XcodeBuilder

Returns a new instance of XcodeBuilder.

Yields:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/xcode_builder.rb', line 12

def initialize(namespace = :xcbuild, &block)
  @configuration = Configuration.new(
    :configuration => "Release",
    :build_dir => "build",
    :sdk => "iphoneos",
    :project_file_path => nil,
    :workspace_file_path => nil,
    :scheme => nil,
    :app_name => nil,
    :signing_identity => nil,
    :package_destination_path => "./pkg",
    :skip_clean => false,
    :verbose => false,
    :info_plist => nil,
    :scm => nil,
    :pod_repo => nil,
    :podspec_file => nil,
    :xcodebuild_extra_args => nil,
    :xcrun_extra_args => nil,
    :timestamp_build => nil,
    :target  => nil,
    :pod_repo_sources => nil
  )
  @namespace = namespace
  yield @configuration if block_given?
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



10
11
12
# File 'lib/xcode_builder.rb', line 10

def configuration
  @configuration
end

Instance Method Details

#buildObject

desc “Build the beta release of the app”



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/xcode_builder.rb', line 69

def build
  clean unless @configuration.skip_clean

  # update the long version number with the date
  @configuration.timestamp_plist if @configuration.timestamp_build

  print "Building Project..."
  success = xcodebuild @configuration.build_arguments, "build"
  raise "** BUILD FAILED **" unless success
  puts "Done"
end

#cleanObject

desc “Clean the Build”



60
61
62
63
64
65
66
# File 'lib/xcode_builder.rb', line 60

def clean
  unless @configuration.skip_clean
    print "Cleaning Project..."
    xcodebuild @configuration.build_arguments, "clean"
    puts "Done"
  end
end

#deployObject



158
159
160
161
# File 'lib/xcode_builder.rb', line 158

def deploy
  package
  @configuration.deployment_strategy.deploy
end

#packageObject

desc “Package the release as a distributable archive”



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/xcode_builder.rb', line 82

def package
  build

  print "Packaging and Signing..."
  if (@configuration.signing_identity != nil) then
    puts ""
    print "Signing identity: #{@configuration.signing_identity}"
  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
  cmd = []
  cmd << "/usr/bin/xcrun"
  cmd << "-sdk iphoneos"
  cmd << "PackageApplication"
  cmd << "'#{@configuration.built_app_path}'"
  cmd << "-o '#{@configuration.ipa_path}'"
  cmd << "--sign '#{@configuration.signing_identity}'" unless @configuration.signing_identity == nil

  if @configuration.xcrun_extra_args then
    cmd.concat @configuration.xcrun_extra_args if @configuration.xcrun_extra_args.is_a? Array
    cmd << @configuration.xcrun_extra_args if @configuration.xcrun_extra_args.is_a? String
  end

  puts "Running #{cmd.join(" ")}" if @configuration.verbose
  cmd << "2>&1 /dev/null"
  cmd = cmd.join(" ")
  system(cmd)

  if @configuration.watch_app then
    reinject_wk_stub_in_ipa
  end

  puts ""
  puts "Done."
end

#pod_dry_runObject

runs a pod dry run before tagging



199
200
201
202
203
204
205
# File 'lib/xcode_builder.rb', line 199

def pod_dry_run
  print "Pod dry run..."
  repos = resolved_repos.join ","
  result = system "pod lib lint #{@configuration.podspec_file} --allow-warnings --sources=#{repos}"
  raise "** Pod dry run failed **" if !result
  puts "Done"
end

#pod_releaseObject

desc “For CocoaPod libraries: dry run, tags SCM, pushes to cocoapod and increments build number”



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/xcode_builder.rb', line 176

def pod_release
  raise "CocoaPod repo is not set, aborting cocoapod_release task." unless @configuration.pod_repo != nil
  raise "Spec file is not set, aborting cocoapod_release task." unless @configuration.podspec_file != nil

  # make a dry run first
  pod_dry_run

  # tag source as needed
  if @configuration.release_strategy != nil then
    @configuration.release_strategy.tag_current_version
  end

  # and push pod pod
  push_pod

  # ask release strategy to bump the release number
  if @configuration.release_strategy != nil then
      @configuration.release_strategy.prepare_for_next_pod_release
  end
  puts "Pod successfully released"
end

#push_podObject



207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/xcode_builder.rb', line 207

def push_pod
  cmd = []
  cmd << "pod repo push"
  cmd << @configuration.pod_repo
  cmd << @configuration.podspec_file
  cmd << "--allow-warnings"

  print "Pushing to CocoaPod..."
  result = system(cmd.join " ")
  raise "** Pod push failed **" if !result
  puts "Done."
end

#reinject_wk_stub_in_ipaObject



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
150
151
152
153
154
155
# File 'lib/xcode_builder.rb', line 122

def reinject_wk_stub_in_ipa
  puts ""
  print "Reinject WK support into signed IPA..."
  # create a tmp folder
  tmp_folder = @configuration.package_destination_path + "tmp"
  FileUtils.mkdir_p tmp_folder

  # copy the ipa to it
  FileUtils.cp "#{File.expand_path @configuration.ipa_path}", tmp_folder

  # evaluate this here because this is based on pwd
  full_ipa_path = @configuration.ipa_path
  # keep track of current folder so can cd back to it and cd to tmp folder
  current_folder = `pwd`.gsub("\n", "")
  Dir.chdir tmp_folder

  # unzip ipa and get rid of it
  `unzip '#{@configuration.ipa_name}'`
  FileUtils.rm @configuration.ipa_name

  # now reinject the shiznit in
  FileUtils.mkdir "WatchKitSupport"
  #get the xcode path
  base = `xcode-select --print-path`.gsub("\n", "")
  wk_path = "#{base}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/Library/Application Support/WatchKit/*"
  FileUtils.cp_r Dir.glob(wk_path), "WatchKitSupport"

  # now zip the fucker
  `zip -r '#{full_ipa_path}' *`
  Dir.chdir current_folder
  FileUtils.rm_rf tmp_folder
  print " Done."
  puts ""
end

#releaseObject



163
164
165
166
167
168
169
170
171
172
173
# File 'lib/xcode_builder.rb', line 163

def release
  # deploy or package depending on configuration
  if @configuration.deployment_strategy then
    deploy
  else
    package
  end

  puts ""
  puts "App successfully released"
end

#resolved_reposObject



50
51
52
53
54
55
56
57
# File 'lib/xcode_builder.rb', line 50

def resolved_repos
  master_repo = ["https://github.com/CocoaPods/Specs.git"]
  if @configuration.pod_repo_sources == nil then
    return master_repo
  end

  return master_repo + Array(@configuration.pod_repo_sources)
end

#xcodebuild(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/xcode_builder.rb', line 39

def xcodebuild(*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)
end