用于编辑 PROJECT-Info.plist 文件的 CFBundleVersion 字段的 Bash 脚本
为了建立持续集成系统 Hudson,我编写了一个 bash 脚本来自动构建 Xcode 项目。 此外,在调试配置中,要求我将项目的 svn 修订号插入 PROJECT-Info.plist 文件的 CFBundleRevision 字段中,作为 ${BUNDLE_VERSION}.r${SVN_REVISION} 。
您将在下面找到 PROJECT-Info.plist 文件的源代码:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
[...]
<key>CFBundleVersion</key>
<string>1.0</string>
[...]
</dict>
</plist>
我尝试了下面的 bash 脚本:
sed 'N;s_^.*<key>CFBundleVersion</key>.*<string>[0-9][0-9]*\.[0-9][0-9]*</string>$_<key>CFBundleVersion</key>\
<string>'"$BUNDLE_VERSION"'\.r'"$SVN_REVISION"'</string>_' $PROJECT-Info.plist
该脚本应将“1.0”字符串替换为 ${BUNDLE_VERSION}.r${SVN_REVISION} (当前仅在标准输出中) 。 但是,替换可以在没有“N”选项的情况下进行,该选项包括 sed 进程中的下一行,并且一次一行。但是 PROJECT-Info.plist 文件中有很多行带有“
”字符串...
我认为这是我处理未知数的方式两行之间的字符(“N”选项和“.*”对于任何字符)是错误的。
有什么想法吗?
预先感谢,并对我的英语水平不好表示歉意。
In order to put in place a continuous integration system, Hudson, I wrote a bash script to build Xcode project automatically.
Moreover, in Debug configuration, It was asked to me, to insert the svn revision number of the project in the CFBundleRevision field of the PROJECT-Info.plist file as ${BUNDLE_VERSION}.r${SVN_REVISION}.
You'll find the source code of PROJECT-Info.plist file below :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
[...]
<key>CFBundleVersion</key>
<string>1.0</string>
[...]
</dict>
</plist>
I tried this bash script below :
sed 'N;s_^.*<key>CFBundleVersion</key>.*<string>[0-9][0-9]*\.[0-9][0-9]*</string>$_<key>CFBundleVersion</key>\
<string>'"$BUNDLE_VERSION"'\.r'"$SVN_REVISION"'</string>_' $PROJECT-Info.plist
This script should replace the "1.0" string with ${BUNDLE_VERSION}.r${SVN_REVISION} (just in standard output currently).
However, the replacement works without the 'N' option which includes the next line in the sed process and for one line at a time. But there is many line with "<string>[...]</string>
" string in the PROJECT-Info.plist file...
I think it's my way of processing the unknown characters between the two lines ('N' option and ".*" for any characters) is wrong.
Any idea ?
Thanks in advance and sorry for my bad level in English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 PlistBuddy:
Use PlistBuddy:
在这种特定情况下,您还可以使用 Xcode 的
agvtool
。您甚至不需要提供 PROJECT-Info.plist 文件的路径。在您的项目目录中运行:In this specific case you can also use Xcode's
agvtool
. You do not even need to provide the path to the PROJECT-Info.plist file. Inside your project dir run:将文件
bundle
移动到bundle.bak
,并在新的1.0.6.9
中替换为1.0.3
代码>捆绑文件。Moves the file
bundle
tobundle.bak
, and replaces1.0.6.9
with1.0.3
in the newbundle
file.