使用Xcode的“新构建系统”进行编写以构建目录info.plist

时间:2018-10-02 17:00:04

标签: ios xcode info.plist xcode10 build-script

在使用“ New Build System”之前,我们有一个如下的构建阶段脚本:

infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
builddate=`date`
/usr/libexec/PlistBuddy -c "Set :BuildDateString $builddate" "${infoplist}"

在运行时写入plist的这种方式的要点是,不会弄脏项目,也不必存储更改。当使用“旧版构建系统”时,这仍然可以正常工作。

在“新建系统”上,此脚本不起作用。目录变量和写入plist都可以,但是更改会以某种方式被覆盖。

是否可以通过构建阶段脚本写入已构建的plist?如果没有,是否有一种方法可以实现仅在应用程序运行时编写信息而不弄脏本地存储库的目的。

2 个答案:

答案 0 :(得分:0)

enter image description here

有时候,在“新构建系统”下,Process Info.plist步骤毕竟是Run custom scripts步骤之后。

所以我使用脚本在捆绑包中生成另一个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)

答案 1 :(得分:0)

@rpstw指出,所有自定义构建步骤都将在新构建系统的const locale = { formats: { ... monthsShort: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'), months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'), weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'), weekdaysShort: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_') } }; 步骤之前 运行。

  • 要在Xcode完成构建后运行Shell脚本,可以将其作为构建后操作添加到方案中:

Process .../Info.plist

enter image description here

  • 如果要引用任何构建系统环境变量(例如Product > Scheme > Edit Scheme... > Build > Post-actionsBUILT_PRODUCTS_DIR),请确保更改了从以下位置提供构建设置

  • 添加您的Shell脚本,但请记住,如果您在应用程序捆绑包中编辑任何文件(即INFOPLIST_PATH),则需要重新签名该应用程序。将此添加到您的帖子构建步骤中:

Info.plist