[英]Writing to build directory info.plist using Xcode's "New Build System"
Before using the "New Build System", we had a build phase script like this:在使用“新构建系统”之前,我们有一个像这样的构建阶段脚本:
infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
builddate=`date`
/usr/libexec/PlistBuddy -c "Set :BuildDateString $builddate" "${infoplist}"
The point of this way to write to the plist at runtime without dirtying the project and having to stash the changes.这种在运行时写入 plist 的方式的要点,而不会弄脏项目并且不必隐藏更改。 This still works well and perfectly when using the "Legacy Build System".
在使用“旧版构建系统”时,这仍然可以很好地工作。
On the "New Build System", this script does not work.在“新构建系统”上,此脚本不起作用。 The directory variables and writing to the plist will works but the changes are somehow overwritten.
目录变量和写入 plist 将起作用,但更改以某种方式被覆盖。
Is there a way to write to a built plist via the build phase script?有没有办法通过构建阶段脚本写入构建的 plist? If not, is there a way to achieve the goal of writing information only when the application runs without dirtying the local repo.
如果没有,有没有办法实现仅在应用程序运行时写入信息而不弄脏本地存储库的目标。
As @rpstw points out, any custom build steps will run before the New Build System's Process .../Info.plist
step.正如@rpstw 指出的那样,任何自定义构建步骤都将在新构建系统的
Process .../Info.plist
步骤之前运行。
Product > Scheme > Edit Scheme... > Build > Post-actions
If you're going to reference any build system environment variables (eg BUILT_PRODUCTS_DIR
or INFOPLIST_PATH
), make sure you change the Provide build settings from selection.如果您要引用任何构建系统环境变量(例如
BUILT_PRODUCTS_DIR
或INFOPLIST_PATH
),请确保从选择中更改提供构建设置。
Add your shell script, but remember that if you edit any file in the app bundle (ie Info.plist
), you'll need to re-sign the app.添加您的 shell 脚本,但请记住,如果您编辑应用程序包中的任何文件(即
Info.plist
),您将需要重新签署应用程序。 Add this to your post build step:将此添加到您的后期构建步骤:
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
/usr/bin/codesign --force --sign - --entitlements "${TARGET_TEMP_DIR}/${FULL_PRODUCT_NAME}.xcent" --timestamp=none "${CODESIGNING_FOLDER_PATH}"
It looks like that sometimes, under the "New Build System", the Process Info.plist
step is after all the Run custom scripts
step.看起来有时,在“新构建系统”下,
Process Info.plist
步骤毕竟是Run custom scripts
步骤。
So I use script to generate another custom.plist
at the bundle所以我使用脚本在包中生成另一个
custom.plist
#!/usr/bin/env ruby
require 'cfpropertylist'
require 'pathname'
build_info = {
'Time' => Time.now.to_s,
'CommitHash' => `git log --pretty="%h" | head -n1`.rstrip
}
plist = CFPropertyList::List.new
plist.value = CFPropertyList.guess(build_info)
plist_path = Pathname.new(ENV['BUILT_PRODUCTS_DIR']) / ENV['CONTENTS_FOLDER_PATH'] / 'build_info.plist'
plist.save(plist_path, CFPropertyList::List::FORMAT_XML)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.