用于编辑 PROJECT-Info.plist 文件的 CFBundleVersion 字段的 Bash 脚本

发布于 2024-10-21 13:54:07 字数 1134 浏览 6 评论 0原文

为了建立持续集成系统 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恋竹姑娘 2024-10-28 13:54:07

使用 PlistBuddy:

# cf. http://davedelong.com/blog/2009/04/15/incrementing-build-numbers-xcode
/usr/libexec/PlistBuddy -h
/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" test.plist
myversion=1.0.5
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion '${myversion}'" test.plist

Use PlistBuddy:

# cf. http://davedelong.com/blog/2009/04/15/incrementing-build-numbers-xcode
/usr/libexec/PlistBuddy -h
/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" test.plist
myversion=1.0.5
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion '${myversion}'" test.plist
眼泪也成诗 2024-10-28 13:54:07

在这种特定情况下,您还可以使用 Xcode 的 agvtool。您甚至不需要提供 PROJECT-Info.plist 文件的路径。在您的项目目录中运行:

agvtool new-version -all "$BUILD_NUMBER" # sets CFBundleVersion
agvtool new-marketing-version "$BUNDLE_VERSION" # sets CFBundleShortVersionString

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:

agvtool new-version -all "$BUILD_NUMBER" # sets CFBundleVersion
agvtool new-marketing-version "$BUNDLE_VERSION" # sets CFBundleShortVersionString
旧故 2024-10-28 13:54:07
$ myversion=1.0.3
$ perl -O777 -i.bak -pe 's|<key>CFBundleVersion</key>\\s*<string>[\d.]*</string>|<key>CFBundleVersion</key></key>'"$myversion"'<string>|' bundle

将文件 bundle 移动到 bundle.bak,并在新的 1.0.6.9 中替换为 1.0.3代码>捆绑文件。

$ myversion=1.0.3
$ perl -O777 -i.bak -pe 's|<key>CFBundleVersion</key>\\s*<string>[\d.]*</string>|<key>CFBundleVersion</key></key>'"$myversion"'<string>|' bundle

Moves the file bundle to bundle.bak, and replaces 1.0.6.9 with 1.0.3 in the new bundle file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文