iPhone Application Post Build Script

I composed a script. Add it into the Run Script Build Phase and it can help you to package the binary and dSYM into:

  • [application].app.[version].zip
  • [application].app.dSYM.[version].[git hash].zip

after a “Distribution” build.

Here’s the script:

#!/usr/bin/env ruby
if ENV["BUILD_STYLE"] == "Distribution" && ENV["ARCHS"] == 'armv6'
  common_git_paths = %w[/usr/local/bin/git /usr/local/git/bin/git /opt/local/bin/git]
  git_path = ""
 
  common_git_paths.each do |p|
    if File.exist?(p)
      git_path = p
      break
    end
  end
 
  if git_path == ""
    puts "Path to git not found"
    exit
  end
 
  command_line = git_path + " rev-parse --short HEAD"
  sha = `#{command_line}`.chomp
 
  info_file = ENV['INFOPLIST_FILE']
 
  f = File.open(info_file, "r").read
  re = /([\t ]+<key>CFBundleVersion<\/key>\n[\t ]+<string>)(.*?)(<\/string>)/
  f =~ re
 
  # Get the version info from the source Info.plist file
  # If the script has already been run we need to remove the git sha
  # from the bundle’s Info.plist.
  version = $2.sub(/ \([\w]+\)/, "")
 
  cmdline = "cd #{ENV['BUILT_PRODUCTS_DIR']};zip -r #{ENV['CONTENTS_FOLDER_PATH']}.#{version}.zip #{ENV['CONTENTS_FOLDER_PATH']};zip -r #{ENV['CONTENTS_FOLDER_PATH']}.dSYM.#{version}.#{sha}.zip #{ENV['CONTENTS_FOLDER_PATH']}.dSYM"
  `#{cmdline}`
end

If you are using some source control system other than git, you have to modify the script to make it work.

1 response to “iPhone Application Post Build Script”

  1. #1. Tom on October 25th, 2009 at 6:20 pm

    Hi,

    I’m looking for a script that would allow me to do the following on my Iphone 3G:

    1. open an application
    2. execute some menu items in the application

    I would like to have it run automated every 1 hour.

    Do you know of any tools or method to do this?

    Thanks for any help you can provide.

Leave a Reply