Created
September 16, 2010 10:27
-
-
Save kompozer/582222 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Source http://jasonfharris.com/blog/2010/05/versioning-your-application-with-the-mercurial-changeset-hash/