Search code examples
iosxcodeopen-sourcesoftware-distribution

How do I automate building the source distribution for an iPhone app with Xcode?


I am looking to distribute an open source iPhone app and I have a few questions about making the source distribution:

  1. How can I automate creating the source archive (or diskimage) with XCode? I want something along the lines of a build target which archives the source (cleaning targets first if necessary, but it would be nice if it didn't have to). I also have an external netbeans project with a ruby script that is used to build an SQL database that the program needs (but can make a separate archive of that if necessary).

  2. What's the best way to identify the files that constitute the 'source'? Is it simply anything that's left after cleaning all targets? Any caveats with that approach (I don't quite trust IDEs to clean up all the cruft they seem to make - also is this liable to include any codesigning stuff that it shouldn't)?


Solution

  • You can add a Run Script Build Phase to any target to do postprocessing of the build. The right approach is usually to create an Aggregate Target that first builds your build product target, then runs the script on the output.

    It's hard to identify all the "source" files. It's often everything in $(SRCROOT) but if your project is laid out in the Root -> ( src ) ( projfiles ) manner, the $(SRCROOT) will only contain your project file and not any sources. You may have to encode the knowledge of at least the top-level project layout into the script, and maintain it if it changes.

    Even though it's the default, you probably don't want to place your build folder in the project folder if you're going to archive the sources, because you'll often grab the intermediates, project index, and other ephemera. In your Project's Get Info inspector, General pane, set the Build Products and Intermediates directory to some common location outside the project directory. That will simplify the job of archiving your sources.

    And Xcode has a built-in archiving mechanism, called Snapshots; you might want to use that, though it's not straightforward to automate. But Snapshots does know all about all your sources.