Created
May 21, 2014 08:59
-
-
Save koenbok/680e76b62ed97e2c3a99 to your computer and use it in GitHub Desktop.
Add to build steps > run script in xcode
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
| #!/usr/bin/env python | |
| # encoding: utf-8 | |
| import sys | |
| import os | |
| import subprocess | |
| import plistlib | |
| def gitVersion(gitPath): | |
| def parse(build): | |
| parts = build.replace('-dirty', '').split('-') | |
| if len(parts) > 1: return "%s.%s" % (parts[0], parts[1]) | |
| if len(parts) > 0: return "%s.0" % parts[0] | |
| raise AssertionError('Could not parse version') | |
| def sub(cmd): | |
| cmd = "cd '%s'; %s" % (gitPath, cmd) | |
| return subprocess.check_output(cmd, shell=True).strip() | |
| return { | |
| "version": parse(sub('git describe --tags').strip('v')), | |
| "hash": sub('git describe --always --dirty'), | |
| "build": sub('git rev-list --all | wc -l'), | |
| } | |
| def writePlist(path, data): | |
| if not os.path.exists(path): | |
| sys.exit("Could not find plist at: %s" % path) | |
| try: | |
| plistData = plistlib.readPlist(path) | |
| plist = plistlib | |
| except Exception, e: | |
| import biplist | |
| plistData = biplist.readPlist(path) | |
| plist = biplist | |
| for k, v in data.iteritems(): | |
| plistData[k] = v | |
| plist.writePlist(plistData, path) | |
| def run(): | |
| applicationInfoListPath = os.path.realpath(os.path.join( | |
| os.environ.get('BUILT_PRODUCTS_DIR'), | |
| os.environ.get('INFOPLIST_PATH'))) | |
| applicationDSYMListPath = os.path.realpath(os.path.join( | |
| os.environ['DWARF_DSYM_FOLDER_PATH'], | |
| os.environ['DWARF_DSYM_FILE_NAME'], | |
| "Contents", "Info.plist")) | |
| version = gitVersion(os.path.dirname(__file__)) | |
| for plistPath in [applicationInfoListPath, applicationDSYMListPath]: | |
| writePlist(plistPath, { | |
| "CFBundleVersion": version["build"], | |
| "CFBundleShortVersionString": version["version"], | |
| }) | |
| run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment