加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – Xcode目标阶段Python脚本

发布时间:2020-12-14 19:21:17 所属栏目:百科 来源:网络整理
导读:我正在尝试将 Python脚本添加到我的项目中,以直接从Git获取构建和营销编号. 我创建了一个新的目标阶段,并运行脚本,如下所述: http://yeahrightkeller.com/2008/10/19/xcode-run-script-build-phase-tip/ 我编写了一个Python脚本,用于解析程序Info.plist fro
我正在尝试将 Python脚本添加到我的项目中,以直接从Git获取构建和营销编号.

我创建了一个新的目标阶段,并运行脚本,如下所述:
http://yeahrightkeller.com/2008/10/19/xcode-run-script-build-phase-tip/

我编写了一个Python脚本,用于解析程序Info.plist

from Foundation import NSMutableDictionary

但是,编译时脚本失败并向构建结果报告以下错误:

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",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)

很明显,distutils以某种方式硬编码它是为版本10.6(Snow Leopard,我正在使用的那个)编译的,但该项目将MacOSX部署目标设置为10.5.

如果我尝试将项目中的此变量设置为10.6,那么我得到:

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

关于如何解决这个问题的任何想法?提前致谢.

解决方法

我有同样的问题,我想保留python版本,因为通过NSMutableDictionary处理plist比在Info.plist上使用正则表达要好得多.

基于Maxence的答案,解决方案是将python代码从Run 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)

然后用shell脚本替换原始的Run Script:

env MACOSX_DEPLOYMENT_TARGET=10.6 python gitversion.py

请务必记住将Shell设置更改为/ bin / sh.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读