Xcode Python Script Target Phase

I am trying to add a Python script to my project in order to get build and marketing numbers directly from Git.

I created a new target phase and run the script as described in:
http://yeahrightkeller.com/2008/10/19/xcode-run-script-build-phase-tip/

And I wrote a Python script that parses the Info.plist program using

from Foundation import NSMutableDictionary

However, the script crashes during compilation and reports the following error for the build results:

Running a custom build phase script: gitversion.py  
Traceback (most recent call last):  
File "/Users/jorge/Documents/Programming iPod/Pruebas/RowOrder/Scripts/gitversion.py", line 9, in <module>  
from Foundation import NSMutableDictionary  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/Foundation/__init__.py", line 8, in <module>  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/objc/__init__.py", line 26, in <module>  
from _bridgesupport import *  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/objc/_bridgesupport.py", line 9, in <module>  
import pkg_resources  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 651, in <module>  
class Environment(object):  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 654, in Environment  
def __init__(self, search_path=None, platform=get_supported_platform(), python=PY_MAJOR):  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 55, in get_supported_platform  
plat = get_build_platform(); m = macosVersionString.match(plat)  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 181, in get_build_platform  
plat = get_platform()  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/util.py", line 97, in get_platform  
cfgvars = get_config_vars()  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 525, in get_config_vars  
func()  
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 408, in _init_posix  
raise DistutilsPlatformError(my_msg)  
distutils.errors.DistutilsPlatformError: $MACOSX_DEPLOYMENT_TARGET mismatch: now "10.5" but "10.6" during configure  
Finished running custom build phase script: gitversion.py (exit status = 1)

Obviously, distutils is somehow hardcoded to compile for version 10.6 (Snow Leopard is the one I use), but the project has a MacOSX deployment target of 10.5.

If I try to set this variable in the project to 10.6, I get:

ld: library not found for -lcrt1.10.6.o

, ? .

+5
4

, python, plist NSMutableDictionary , regex Info.plist.

Maxence, , python Script gitversion.py:

#!/usr/bin/env python
import os
from Foundation import NSMutableDictionary
from subprocess import Popen, PIPE

p = Popen(
        "/sw/bin/git rev-parse --short HEAD", 
        stdout=PIPE, 
        close_fds=True,
        shell=True)

version = p.stdout.read()
print version
info = os.environ['INFOPLIST_FILE']
print info
plist = NSMutableDictionary.dictionaryWithContentsOfFile_(info)
print plist
plist['revision'] = version[:-1]
plist.writeToFile_atomically_(info, 1)

Run Script script:

env MACOSX_DEPLOYMENT_TARGET=10.6 python gitversion.py

Shell /bin/sh.

+2

Apple Python 2.5 2.6 Snow Leopard (10.6), 10.6. 10,5, Apple Python 10.6 10.5.

Python 2.6 python.org. Python 10.3+, 10.5, 10.6. , , Python , .

py2app python.org 2.6 . py2app. , .

EDIT: , , . 10.6, (1), 10.5 (2), 10.5. , Xcode, 10,5, Xcode 10.5 Xcode 10.6. , , , , Active SDK 10,5 10,6 ( ) . crt library not found; , - .

, 10.6 10.5, , gitversion.py python 2.6 ( traceback), 10.5. python 2.6, , python 2.5, Apple 10.5 10.6. , , , , , python script /usr/bin/python 2.5, python.

+1

For the purposes of this script, you can simply temporarily set the MACOSX_DEPLOYMENT_TARGET value to 10.6. Thus, your team will:

env MACOSX_DEPLOYMENT_TARGET=10.6 gitversion.py
+1
source

All Articles