The Importance of dot-slash
Sometimes it’s the little things. Often it’s the little things, I guess. I like to write cross-platform software. The less I need to worry about whether I’m building on Mac OS X, Win 32 or Linux, the happier I am. mozCC was one of the first projects I developed that had to run on all three platforms, and as such, I wrote a set of scripts and tools for building and testing the code base.
During the development of 0.8.0 I transitioned from my original build script, make_jar to a more generic version I developed for DemoExt , build.sh , which was generally a “good thing.” Around the same time I noticed that building mozCC on Mac OS X didn’t work quite right. OK, it didn’t work at all. It would appear to build, but installing that build just didn’t work. Nothing. Nada. No acknowledgment that mozCC was installed at all. Of course, I was in a hurry to get 0.8.0 out the door, so I turned my chair, turned on my Linux box, and proceeded to build there. And funny thing, the builds from Linux worked just fine on Mac OS X.
Today I’m working on fixing a serious bug in mozCC. I’m at OSCON, and only have my iBook. And I had completely forgotten about the build problems from 0.8.0. After beating my head against the wall for an hour yesterday and about an hour this morning, I finally figured it out: it’s all about the ./ (dot-slash).
Build.sh is a simple shell script that assembles the necessary files for a Mozilla extension in the appropriate relative locations for the JAR. To pull out the list of files to zip up into the JAR, it uses the UNIX utility find
. In particular,
find ./content -path './*CVS*' -prune -o -type f -print | grep -v ~
What I found was that on Linux, find returns a list of files with relative paths and no leading dot-slash. For example,
1926 06-25-104 12:47 content/mozcc/prefs.xul 1560 06-25-104 08:25 content/mozcc/prefsOverlay.xul 2708 06-25-104 12:47 content/mozcc/seamonkey-prefs.xul . . .
Mac OS X (and maybe BSD, I don’t know how deep this goes), on the other hand, returns files with a leading dot-slash:
1926 06-25-104 12:47 ./content/mozcc/prefs.xul 1560 06-25-104 08:25 ./content/mozcc/prefsOverlay.xul 2708 06-25-104 12:47 ./content/mozcc/seamonkey-prefs.xul . . .
And this breaks Mozilla and the extension. A subtle change to the find
command, namely removing the dot-slash, fixes the problem (at least on Mac OS X). I’ll have to test it on Linux to make sure it works in a cross-platform manner, and then I’ll update DemoExt.
Success: the sweet taste of frustration.