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

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

问题描述

我有一个脚本,


  1. 阅读一些配置文件来生成源代码片段

  2. 查找相关的Objective-C源文件和

  3. 使用生成的代码替换源代码的一些部分步骤1。

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

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.

但是,由于该脚本在其e版本中修改了源代码xecution,我需要构建两次以获取最新版本的构建产品。这是我想象的事情:

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运行脚本构建阶段 --->一切都是最新的

  6. 第二次运行:Xcode继续编译

  1. 1st run: Xcode collects dependency information ---> no changes
  2. 1st run: Xcode runs "Run Script Build Phase" ---> source is changed behind Xcode's back
  3. 1st run: Xcode finishes build, thinking nothing needs to be updated
  4. 2nd run: Xcode collects dependency information ---> source has changed, needs rebuild!
  5. 2nd run: Xcode runs Run Script Build Phase" ---> everything is up-to-date
  6. 2nd run: Xcode proceeds to compilation

阅读构建阶段的Xcode文档 ,我尝试添加一个源文件,每次脚本作为运行脚本构建阶段的输出被更新,但没有改变,因为配置文件的数量可能会在我的pro ject,我不想指定每个输入和输出文件。

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天全站免登陆