Subscribe via RSS
administration c# cocoa coding EasyTAG linux Mac OS X opensolaris OpenVPN Time Machine virtualization windows xcode zfs

add subversion and other build information to Xcode projects

If you are developing apps with Xcode that are managed by subversion, it might come handy to get subversion information, like the revision number, into your application. Also other build information can provide useful later, like build date, gcc version and so on. You can e.g show this info in your about dialog, so the and user can inform you what version he is running. And this way your app knows when it was built and what revision it is, so you could probably send this info with bug or crash reports.
To achieve this, you can simply add a costum script to your build phases, which collects this information and writes it in a file. Either a simple text file, or you can choose to put the info in a header file so it’s available as a variable at code compile time. Xcode_addScriptBuildPhase Right Click on Targets -> Add -> New Build Phase -> New Run Script Build Phase
This will add a new Script Build Phase to your target, you can name it the way you want. Double-Click it and an editor window will come up, in which you can add bash code. Xcode_Run Script Phase
This is a part of one of my build scripts and shows an example of how to add the build information to a file :
buildscript.sh
echo -e "Build Info \n" > buildinfo.txt; echo -e -n "Build date\t\t: ">> buildinfo.txt; date "+%Y-%m-%d %H:%M" >> buildinfo.txt; echo -e -n "SVN Revision \t\t: " >> buildinfo.txt; svnversion -n >> buildinfo.txt; echo -e -n "\nXCode Version \t: " >> buildinfo.txt; cat /Developer/Applications/Xcode.app/Contents/Info.plist | grep "Xcode version" | awk '{print $3}' | cut -d "<" -f1 >> buildinfo.txt echo -e -n "GCC Version \t\t: " >> buildinfo.txt; gcc --version | head -1 | awk '{print $1}' >> buildinfo.txt;
Download the script here or better copy and paste directly into xcode

that was it, your information now gets inserted into an file named buildinfo.txt, for which you probably want to add a new “copy files build phase” to your target and copy this file to your ressource folder.
you can then easily display your information via something like
NSString *path = [[NSBundle mainBundle] pathForResource:@"buildinfo" ofType:@"txt"]; NSString *fileText = [NSString stringWithContentsOfFile:path]; [aTextView setString:fileText];

This could then look simliar to this :
synox2_About_Buildinfo
You can also adjust the script to write the gained infos in an .h file as defines, and so use them as regular variables in your program, but be sure to position the build info script before the compile script then !! 🙂


Your comment :
Name *

Email*
(will not be published)

Website