更好的增量构建号的方法? [英] Better way of incrementing build number?

查看:212
本文介绍了更好的增量构建号的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用shell脚本作为我的Xcode构建过程的一部分,在 plist 文件中增加构建号,但是它使Xcode 4.2.1频繁崩溃(有关目标的错误不属于一个项目;我想改变的 plist 文件是混乱的Xcode以某种方式)。



shell脚本这样,当文件比 plist 文件更新时,内部版本号只会增加 agvtool ):

 如果[-n \`find ProjDir -newer ProjDir / Project-Info.plist`\] ;然后agvtool -noscm next-version -all; else echo \Version not incremented\; fi 

有一种方法来增加内部版本号(在 plist 文件或任何其他地方)不破坏Xcode?

编辑:这是我的最终解决方案,基于@Monolo 。我在 $ {PROJECT_DIR} / tools (同步到 .xcodeproj 目录)中创建了以下脚本:

 #!/ bin / sh 

if [$#-ne 1];那么
echo用法:$ 0 plist-file
exit 1
fi

plist =$ 1
dir =$(dirname$ plist )

#如果源文件已更改,只需递增构建号
如果[-n$(找到$ dir\!-path* xcuserdata *\! -path* .git-newer$ plist)];那么
buildnum = $(/ usr / libexec / Plistbuddy -c打印CFBundleVersion$ plist)
如果[-z$ buildnum];然后
echo在$ plist中没有构建号
退出2
fi
buildnum = $(expr $ buildnum + 1)
/ usr / libexec / Plistbuddy - c设置CFBundleVersion $ buildnum$ plist
echo增量构建号为$ buildnum
else
echo不更改构建号,因为源文件没有更改
fi

EDIT 2 :我已修改脚本以合并@Milliways建议。



然后我从Xcode目标'Build Phases'部分调用脚本:



编辑3 :根据@ massimobio的答案,



编辑4 :只是为了更新我的首选方法来调用这个构建脚本现在以创建单独的目标,并使应用目标依赖于此 Bump Build Number 目标。这确保它在应用程序目标使用plist之前调用任何(我注意到它喜欢在构建开始时处理plist)。我也切换到一个纯Python解决方案,保持版本号在一个单独的文件,并写入版本源文件,因为这是更有用的跨平台产品(即Visual Studio在Windows下可以调用脚本,显然cmake / make-type builds也可以这样做)。这样做的好处是,即使在不同的平台下,构建号也总是相同,并且还可以使用当前版本/构建更新Visual Studio Resource.rc 文件



这里是我目前使用的python脚本更新Xcode项目中的 Info.plist 文件。

你的问题正确,你想修改 Project-Info.plist 文件,这是Xcode的标准项目模板的一部分?



我问这是因为 Project-Info.plist 通常是在版本控制下,它将被标记为,很好,修改。



如果没有问题,那么以下代码段将更新内部版本号并将文件标记为已修改的文件,其中 get_build_number 是一些脚本,以获取您可以使用的(可能递增)内部版本号:

 #! / bin / sh 

#get_build_number是脚本的占位符,用于获取最新版本号
build_number =`get_build_number`

/ usr / libexec / PlistBuddy - cSet:CFBundleVersion $ {build_number}ProjDir / Project-Info.plist

PlistBuddy允许您在plist文件中设置任何键,而不仅仅是版本号。您可以创建所需的所有plist文件,如果需要,将它们包括在资源中。



至于您需要在关于窗格和其他地方显示版本,您还可以查看设置 CFBundleGetInfoString CFBundleShortVersionString


I have been using a shell script as part of my Xcode build process to increment the build number within the plist file, however it's making Xcode 4.2.1 crash frequently (with an error about the target not belonging to a project; I'm guessing the changing of the plist file is confusing Xcode in some way).

The shell script did this so that the build number is only incremented by agvtool when a file is newer than the plist file (so just building didn't increment the value):

if [ -n \"`find ProjDir -newer ProjDir/Project-Info.plist`\" ]; then agvtool -noscm next-version -all; else echo \"Version not incremented\"; fi

Is there a way to increment the build number (in the plist file, or anywhere else) that doesn't break Xcode?

EDIT: Here is my final solution, based on the suggestion of @Monolo. I created the following script in ${PROJECT_DIR}/tools (sibling to the .xcodeproj directory):

#!/bin/sh

if [ $# -ne 1 ]; then
    echo usage: $0 plist-file
    exit 1
fi

plist="$1"
dir="$(dirname "$plist")"

# Only increment the build number if source files have changed
if [ -n "$(find "$dir" \! -path "*xcuserdata*" \! -path "*.git" -newer "$plist")" ]; then
    buildnum=$(/usr/libexec/Plistbuddy -c "Print CFBundleVersion" "$plist")
    if [ -z "$buildnum" ]; then
        echo "No build number in $plist"
        exit 2
    fi
    buildnum=$(expr $buildnum + 1)
    /usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "$plist"
    echo "Incremented build number to $buildnum"
else
    echo "Not incrementing build number as source files have not changed"
fi

EDIT 2: I have modified the script to incorporate @Milliways suggestion.

I then invoked the script from Xcode target 'Build Phases' section:

EDIT 3: As per @massimobio's answer, you'll need to add quotes around the plist argument if it contains spaces.

EDIT 4: Just to update that my preferred method of invoking this build script is now to create a separate target and make the app target dependant upon this Bump Build Number target. This ensures that it is invoked before the app target does anything with the plist (I've noticed that it likes to process the plist at the start of the build). I've also switched to a purely python-based solution that keeps the version number in a separate file, and writes version source files, as this is more useful for cross-platform products (i.e. Visual Studio under Windows can invoke the script, and obviously cmake/make-type builds can do so also). This has the benefit that the build number is always the same even under different platforms, and it's also possible to update the Visual Studio Resource.rc file with the current version/build as well.

Here is the python script I currently use to update Info.plist files within Xcode project.

解决方案

If I understand your question correctly, you want to modify the Project-Info.plist file, which is a part of the standard project template of Xcode?

The reason I ask this is that Project-Info.plist normally is under version control, and modifying it means that it will be marked as, well, modified.

If that is fine with you, then the following snippet will update the build number and mark the file as modified in the process, where get_build_number is some script to get the (possibly incremented) build number that you want to use:

#!/bin/sh

# get_build_number is a placeholder for your script to get the latest build number
build_number = `get_build_number`

/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${build_number}" ProjDir/Project-Info.plist

PlistBuddy allows you to set any key in a plist file, not just the version number. You can create all the plist files you want, and include them in the resources if needed. They can then be read in from the bundle.

As to your need to show the version in the about pane and other places, you can also look into setting CFBundleGetInfoString and CFBundleShortVersionString.

这篇关于更好的增量构建号的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆