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

查看:19
本文介绍了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 运行运行脚本构建阶段" ---> 源代码在 Xcode 背后更改
  3. 第一次运行:Xcode 完成构建,认为不需要更新任何内容
  4. 第二次运行:Xcode 收集依赖信息 ---> 源已更改,需要重新构建!
  5. 第二次运行:Xcode 运行 Run Script Build Phase" ---> 一切都是最新的
  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天全站免登陆