Monday, April 09, 2007

XCode custom build rules can give you a headache

On a Cocoa project I've been working on I am using Ragel to generate a parser by transforming the ragel source file into an intermediate Objective-C file that contains the parser class. The idea then is to use a custom build rule in XCode to handle updating the Objective-C when the ragel source changes and also compiling the derived source file.

I tried following the instructions Alan West posted about integrating Ragel with XCode but it just wouldn't work properly. I could see my derived source file getting created but the linker reported that the parser class was an unknown symbol. After digging around a bit with the command line xcodebuild I could see that my source was created, but never compiled. Instead it was being copied into the bundle resources.

I read all about custom build rules and configurations, experimented with build scripts instead (couldn't get those to work either), and googled until I came across the author Fritz Anderson's online chapter from his book 'Step into XCode'. He's using Lemon instead of Ragel but was observing the exact same issue.

As I reflected on this it was also starting to bug me that my source would end up in the bundled resources. Why the hell would I want that? That's when the penny dropped. I noticed that my custom source file (DiffParser.ml.rl) was in the "Copy bundle resources" build phase but not in the "Compile sources" build phase. Once I moved it across everything worked properly and I was able to build my executable.

I guess XCodes behaviour makes sense. It didn't know anything about .m.rl files when they were added to the project and so it's a reasonable assumption that they were resources. However if XCode had been really smart it should have noticed me defining a new build rule for *.m.rl files and checked to see if any files that were previously considered to be resources should now considered source files and offer to move them to the correct phase for me.

09/04/2007 13:07 by Matt Mower | Permalink | comments:
More about:

Pain can be a great motivator (to finish your first Mac application!)

Not the best weekend on record as I seem to have developed an ear infection which is both very painful and very uncomfortable (my jaw isn't working properly). I decided that, rather than spending the day waiting in casualty to be seen by a doctor, I would take my mind off it by debugging the problem with my first MacOSX app that has been preventing me from releasing it these last few (okay 8) weeks.

So I'm quite pleased to be able to announce Diffly my first real MacOSX application written in Objective-C using the beautiful Cocoa framework.

Diffly in action

If you're a developer, use MacOSX, and use Subversion you might want to take a look.

I originally started writing Diffly because I found myself getting frustrated paging through the output svn diff | more and tabbing backwards and forwards to another tool when I was writing check-in messages. I wanted something that would give me an integrated overview of my working copy and offer me a smoother check-in workflow. Diffly is the product of that.

It's quite usable (I use it every day) and, as of today, seems to be stable on both Intel and PPC macs. I wrote it to scratch my own itch, but of course I am very pleased if others find it useful too. Let me know what you think.

Anyway I can go to bed happy for, today, I am a MacOSX software author! :-)

09/04/2007 23:10 by Matt Mower | Permalink | comments:
More about: