Xcode and git - Another build script

stompy » 14 August 2008 » In Mac OS X »

Update: Got broke somehow - so I fixed it.

I’ve rewritten the script from Cocoa Is My Girlfriend in ruby to append the git commit hash into an application’s Info.plist file.

This way, it keeps the version string that is added in Xcode, so the default About panel looks like this:

Bonsoir.png

Here is the script

#!/usr/bin/env ruby

# Xcode auto-versioning script for Subversion by Axel Andersson
# Updated for git by Marcus S. Zarra and Matt Long
# Converted to ruby by Abizern
# Appends the git sha to the version number set in Xcode.

# These are the common places where git is installed.
# Change this if your path isn’t here
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
puts sha

info_file = ENV['BUILT_PRODUCTS_DIR'] + “/” + ENV['INFOPLIST_PATH']

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.
open = $1
orig_version = $2
close = $3

# If the git has has not already been injected into the Info.plist, this will set version to nil
version = $2.sub!(/\s\(git sha [\w]+\)/, )
if (!version)
  version = orig_version
end

# Inject the git hash into the bundle’s Info.plist
sub = #{open}#{version} (git sha #{sha})#{close}
puts sub
f.gsub!(re, sub)
File.open(info_file, “w”) { |file| file.write(f) }

Make sure that the shell is set to /usr/bin/ruby

Shell_setting.png

Tags: , , , ,

Trackback URL

One Comment on "Xcode and git - Another build script"

Trackbacks

  1. [...] | user-saved public links | iLinkShare 1 votesXcode and git - Another build script>> saved by rizvani2828 1 ...

Hi Stranger, leave a comment:

ALLOWED XHTML TAGS:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to Comments