Skip to content

Instantly share code, notes, and snippets.

@kompozer
Created September 16, 2010 10:27
Show Gist options
  • Save kompozer/582222 to your computer and use it in GitHub Desktop.
Save kompozer/582222 to your computer and use it in GitHub Desktop.
import os, subprocess, re, sys
appname = "yourappname"
hgbin = "/usr/local/bin/hg"
targetBuildDir = os.getenv("TARGET_BUILD_DIR")
getChangeset = subprocess.Popen(hgbin + ' parent --template "{node|short}" --cwd ' + targetBuildDir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
if (getChangeset.stderr.read() != ""):
print "Error in obtaining current changeset of the Mercurial repository. '" + getChangeset.stderr.read() + "'"
sys.exit(0) # if you want the build to fail here since the changeset is malformed change this to sys.exit(1)
changeset = getChangeset.stdout.read()
if (not re.search("^[0-9a-f]{12}$", changeset)):
print "Current changeset of the Mercurial repository is malformed"
sys.exit(0) # if you want the build to fail here since the changeset is malformed change this to sys.exit(1)
infoPlist = os.path.join(targetBuildDir, appname + ".app/Info.plist")
if not os.path.exists(infoPlist):
print "Cannot locate " + appname +".app/Info.plist"
sys.exit(1) # if you want the build to not fail here change this to sys.exit(0)
result = subprocess.Popen('/usr/libexec/PlistBuddy -c "Delete BuildHashKey" ' + infoPlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
result = subprocess.Popen('/usr/libexec/PlistBuddy -c "Add BuildHashKey string '+ changeset + '" ' + infoPlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print appname + " BuildHashKey set to " + changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment