Xcode:在每次直接修改源代码的构建之前运行脚本 [英] Xcode: Running a script before every build that modifies source code directly

查看:61
本文介绍了Xcode:在每次直接修改源代码的构建之前运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本

  1. 阅读一些配置文件以生成源代码片段
  2. 查找相关的 Objective-C 源文件并
  3. 用步骤 1 中生成的代码替换源代码的某些部分.

和一个 Makefile,它有一个特殊的时间戳文件作为 make 目标和配置文件作为目标源:

and a Makefile that has a special timestamp file as a make target and the configuration files as target sources:

SRC = $(shell find ../config -iname "*.txt")
STAMP = $(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME).stamp
$(STAMP): $(SRC)
    python inject.py
    touch $(STAMP)

我将此 Makefile 添加为项目目标的构建阶段堆栈顶部的运行脚本构建阶段".

I added this Makefile as a "Run Script Build Phase" on top of the stack of build phases for the project target.

在编译源代码之前运行脚本构建阶段.

The script build phase was run before compiling the source.

但是,由于脚本在执行期间修改了源代码,我需要构建两次才能获得构建产品的最新版本.这是我想象中发生的事情:

However, since the script modifies source code during its execution, I needed to build twice to get the most recent version of the build product. Here is what I imagine to be happening:

  1. 第一次运行:Xcode 收集依赖信息 ---> 没有变化
  2. 第一次运行:Xcode 运行Run Script Build Phase"---> 在 Xcode 后面更改源代码
  3. 第一次运行:Xcode 完成构建,认为没有什么需要更新
  4. 第二次运行:Xcode 收集依赖信息 ---> 源已更改,需要重建!
  5. 第二次运行:Xcode 运行运行脚本构建阶段"---> 一切都是最新的
  6. 第二次运行:Xcode 进行编译

阅读Xcode 构建阶段文档后,我尝试添加一个源文件,该文件在每次脚本作为运行脚本构建阶段"的输出运行时都会更新,但没有任何改变.由于我的项目中配置文件的数量可能会有所不同,我不想指定每个输入和输出文件.

After reading Xcode documentation on Build Phases, I tried adding a source file which is known to be updated every time the script is run as the output of "Run Script Build Phases", but nothing changed. Since the number of configuration files may vary in my project, I don't want to specify every input and output file.

如何让 Xcode 知道在运行脚本构建阶段"期间所做的源文件更改?

How do I make Xcode aware of source file changes made during "Run Script Build Phase"?

  • 补充说我将脚本构建阶段置于其他构建阶段之前

推荐答案

到目前为止提到的每一种技术都是一种矫枉过正.复制 steve kim 的评论以提高知名度:

Every technique mentioned so far is an overkill. Reproducing steve kim's comment for visibility:

在构建阶段选项卡中,只需拖动运行脚本"选项卡即可.步到更高的位置(例如在编译源"之前).

In the build phases tab, simply drag the "Run Script" step to a higher location (e.g. before "Compile Sources").

在 Xcode 6 上测试

Tested on Xcode 6

这篇关于Xcode:在每次直接修改源代码的构建之前运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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