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.
- Where is the general documentation (or a good tutorial) for scripting Xcode build phases?
- How can I add files to the Compile Sources phase?
- How can I discover information about the project and the folder references within it?
- Are there any special considerations if I want to script in Ruby or Python vs. bash scripting?
To add files to the
Compile Sourcesbuild phase using a script, you will need to manipulate your project’sproject.pbxprojfile programmatically.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 newproject.pbxprojfile.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.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 answer to parse theproject.pbxprojfile on the command line like so:plutil -convert xml1 -o - myproj.xcodeproj/project.pbxprojHappy parsing!