gpt4 book ai didi

iphone - Xcode 目标阶段 Python 脚本

转载 作者:太空狗 更新时间:2023-10-30 01:17:42 25 4
gpt4 key购买 nike

我正在尝试将 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", 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)

显然,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 代码从运行脚本构建阶段剥离到 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 .

关于iphone - Xcode 目标阶段 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1698494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com