Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

python - Tutorial or Guide for Scripting Xcode Build Phases

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.

  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?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To add files to the Compile Sources build phase using a script, you will need to manipulate your project's project.pbxproj file programmatically.

Generally speaking, you would accomplish this by parsing the project.pbxproj file 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.pbxproj file.

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.pbxproj files.

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

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

Happy parsing!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...