views:

762

answers:

4

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)?

A: 

Well, I've had no answers on this so far so I'm going to approach it from the other direction, using make and the command line. I'm going to use the answer to this question:

http://stackoverflow.com/questions/377992/building-xcode-projects-from-the-command-line

...and then use a standard 'make' approach to build the app and the source distribution archive.

frankodwyer
+4  A: 

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.

Thank you, that is very helpful
frankodwyer
A: 

Try an aggregate target as suggested calling the following script:

#!/bin/bash -x

cd "$BUILT_PRODUCTS_DIR"

APPFILE="$PROJECT_NAME.app"

IPAFILE="$PROJECT_NAME.ipa"

if [ "$BUILD_STYLE" = "Distribution" ]; then

rm -f "$APPFILE.zip" && zip -ry "$APPFILE.zip" "$APPFILE" && open .

elif [ "$BUILD_STYLE" = "BetaTesting" ]; then

rm -rf "$IPAFILE" iTunesArtwork Payload && \
cp ../../Apple/iTunesArtwork . && \
mkdir Payload && cp -Rp "$APPFILE" Payload && \
zip -r "$IPAFILE" iTunesArtwork Payload && open .

fi

Err, perhaps this is the answer to a different question though...

Wanderer
+2  A: 

Set the SRCROOT environment variable to the location that you want the source archived, cd to the project directory, and execute

xcodebuild installsrc build -configuration <configname> -target <targetname>

The "installsrc" build action copies the project source to ${SRCROOT}.

cdespinosa