编写 XCode 构建阶段脚本的教程或指南

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7557273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:01:59  来源:igfitidea点击:

Tutorial or Guide for Scripting XCode Build Phases

pythonrubyxcodebuild-automation

提问by Dan Rosenstark

I would like to add some files to the Compile Sources build phase using a script in XCode, which pulls from some folder references. I haven't been able to find much documentation so far.

我想使用 XCode 中的脚本将一些文件添加到编译源构建阶段,该脚本从一些文件夹引用中提取。到目前为止,我还没有找到太多文档。

  1. Where is the general documentation (or a good tutorial) for scripting XCode build phases?
  2. How can I add files to the Compile Sources phase?
  3. How can I discover information about the project and the folder references within it?
  4. Are there any special considerations if I want to script in Ruby or Python vs. bash scripting?
  1. 用于编写 XCode 构建阶段的脚本的一般文档(或好的教程)在哪里?
  2. 如何将文件添加到编译源阶段?
  3. 如何发现有关项目的信息以及其中的文件夹引用?
  4. 如果我想用 Ruby 或 Python 编写脚本与 bash 脚本编写,有什么特别的考虑吗?

回答by prairiedogg

To add files to the Compile Sourcesbuild phase using a script, you will need to manipulate your project's project.pbxprojfile programmatically.

Compile Sources使用脚本将文件添加到构建阶段,您需要以project.pbxproj编程方式操作项目的文件。

Generally speaking, you would accomplish this by parsing the project.pbxprojfile into an in-memory data structure, manipulating that data structure through a programmatic interface, and then writing the data structure out to a new project.pbxprojfile.

一般而言,您可以通过将project.pbxproj文件解析为内存中的数据结构,通过编程接口操作该数据结构,然后将该数据结构写入新project.pbxproj文件来完成此操作。

There are several projects out there that could potentially help you do this, I haven't tried any of them:

有几个项目可以帮助您做到这一点,我还没有尝试过其中的任何一个:

And here is a series of blog posts with great general info on the contents and format of XCode project.pbxprojfiles.

这是一系列博客文章,其中包含有关 XCodeproject.pbxproj文件的内容和格式的一般信息。

Finally, it may be worth noting that for very simple manipulations, particularly if you aren't concerned about the cosmetics of your project.pbxprojfile getting messed up, you can follow the suggestion over at this Stack Overflow answerto parse the project.pbxprojfile on the command line like so:

最后,可能值得注意的是,对于非常简单的操作,特别是如果您不担心project.pbxproj文件的外观被弄乱时,您可以按照此 Stack Overflow 答案中的建议在project.pbxproj命令行上解析文件,例如所以:

plutil -convert xml1 -o - myproj.xcodeproj/project.pbxproj

plutil -convert xml1 -o - myproj.xcodeproj/project.pbxproj

Happy parsing!

快乐解析!