#第一种方法 Xcode中直接编写脚步并运行
##1.选中一个target > Build Phase > +
##2.选择New Run Script Phase
##3.得到下图
##4.Run Script 详解
这里我们可以选择新建一个shell script 或者 将一个编写好的脚步拖进器
shell脚本代码如下:
echo "Dump of variables"
echo "PRODUCT_NAME=${PRODUCT_NAME}"
echo "The action being performed on the current target,such as build or clean."
echo "ACTION=${ACTION}"
echo "The variations-debug,profile or normal-that Xcode is creating for the product being built."
echo "BUILD_VARIANTS=${BUILD_VARIANTS}"
echo "The name of the project containing the tartget that is being build."
echo "PROJECT_NAME=$PROJECT_NAME"
echo "The name of the project being built, without any extension or suffix."
echo "PROJECT_NAME=$PROJECT_NAME"
echo "The name of the target being built."
echo "TARGET_NAME=$TARGET_NAME"
echo "The location of the target being built."
echo "TARGET_BUILD_DIR=$TARGET_BUILD_DIR"
echo "The directory that holds the products created by building the tartgets in a project."
echo "BUILD_PRODUCTS_DIR=$TARGET_BUILD_DIR"
echo "The directory that holds intermediate files for a specific target."
echo "TEMP_FILES_DIR=$TARGET_BUILD_DIR"
echo "The directory that holds intermediate source files generated by the Compile Source build phase"
echo "DERIVED_FILES_DIR=$TARGET_BUILD_DIR"
echo "The location of the installed product."
echo "INSTALL_DIR=$TARGET_BUILD_DIR"

##5.项目编译,脚本正常编译,结果如下

#第二种方法 将写好的脚本在Xcode中执行
##1.创建External Build System
创建编译系统作为目标APP的执行依赖.
选择Cross-platform > Other > External Build System
##2.取名为External

##3.创建shell脚本,取名Script.sh,内容如下:
#!/bin/sh
echo "External Build Tool"
echo "Yes, it worked!" >> ./DidItWork.txt
为了确保可以正常的执行,在运行之前添加可执行属性.
chmod +x Script.sh
##4.配置编译工具系统
Targets > External >Info > External Build Tool Configuration
Build Tool填写 ./Script.sh
Directory 填写脚步所在目录

##5.给目标App添加运行依赖
Targets > Demo >Build Phase > Target Dependencies

##6.运行编译
结果如下:

如图所示, External Build System 作为目标App的依赖, 在目标App 编译之前进行编译,可以用于一些文件的配置.
#第三种方法 将以上两种方法结合使用
结合第一种方法和第二种方法
把写好的脚本拖进Run Script框中
执行即可.