Sep 14, 2008

Debugging symlinied TYPO3 directories with Komodo IDE on Mac

Update (Dec 03, 2011): this is not longer necessary. Just use PhpStorm IDE instead.

As some of the readers know, I recently switched from the Zend Studio to Komodo IDE for PHP programming and debugging. Recent versions of Zend Studio are slow, often hang, sometimes crash, ask stupid questions (for example, to select a file to debug with only one option) and extremely slow when debugging. Komodo IDE does not have any of these problems. It is not perfect, of course (for example, there are issues with autocomplete) but in general it is much better than Zend Studio.

The only problem that bothered me so far was the inability of Komodo IDE to debug symlinked files.

TYPO3 setup for PHP development

I have several TYPO3 versions checked out from the TYPO3 SVN. I often have to change versions to test extensions or patches in different versions. Therefore I set up my development directory as follows:

-rw-r--r-- 1 user _www 46 Jun 18 2006 clear.gif
drwxrwxr-x 37 user _www 1258 Aug 18 17:07 fileadmin
lrwxr-xr-x 1 user _www 22 May 27 14:06 index.php -> typo3_src/index.php
lrwxrwxr-x 82 user _www 2788 Sep 14 17:57 t3lib -> typo3_src/t3lib
-rw-r--r-- 1 user _www 299 Sep 14 18:47 t3test.kpf
lrwxrwxr-x 90 user _www 3060 Sep 14 18:09 typo3 -> typo3_src/typo3
drwxrwxr-x 13 user _www 442 Sep 14 18:15 typo3conf
lrwxr-xr-x 1 user _www 18 Aug 27 21:37 typo3_src -> ../TYPO3/TYPO3-dev
drwxrwxr-x 132 user _www 4488 Sep 13 16:40 typo3temp
drwxrwxr-x 42 user _www 1428 Aug 18 17:07 uploads

When I need to use another TYPO3 version, I simply need to execute one command in the terminal:

rm typo3_src ; ln -s ../TYPO3/TYPO3-4.2

This works very well. However Komodo IDE does not work with symbolic links. It gets the path to the real file from XDebug anduses that file. Therefore if I set a breakpoint in the file inside typo3/ or t3lib/, it is not triggered.

On Linux I would solve it easily: I would either create a hard link instead of symbolic link or use "mount --bind" to connect typo3/ and t3lib/ to the real ones.

The problem is: neither of these methods work on Mac! There is no binding in Leopard and hard links are not supported for directories by "ln".

What do I do?

Simulating bind on Mac

After a long search I found a package on Google code, named bindfs. It allows to use a simple command to bind directories:

bindfs existing_directory empty_directory

As a result empty_directory/ will be bound as existing_directory/. Changing files in one directory means you see the same change in another. There are also options that allow you to do many interesting things (change permissions on the new directory, for example).

bindfs on Mac works on the top of MacFUSE. MacFUSE provides a user-installable file systems on Mac. bindfs in fact creates a file system inside existing directory.

To use bindfs one needs to get and install MacFUSE first. MacFUSE comes with a normal Mac "dmg"-style installer.

Installing bindfs is not that easy. XCode and other Mac developer's tools are necessary to complie bindfs. This is not a problem because they are on the Apple DVD that comes with every Mac. Alternatively readers can get a compled version of bindfs using a link in the end of this article.

Assuming that XCode is installed and we are inside the extracted bindfs directory, we can build bindfs like this:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
sudo make install

Executable file will be placed to /usr/loca/bin.

After compilation I could remove symbolic links, create stub directories and mount TYPO3 directories:

rm t3lib typo3
mkdir t3lib typo3
bindfs ~/Projects/TYPO3/TYPO3-dev/t3lib ~/Projects/t3test/t3lib
bindfs ~/Projects/TYPO3/TYPO3-dev/typo3 ~/Projects/t3test/typo3

Notice that I kept index.php as symlink. It does not change from version to version and it is not important.


All goes fine, I (and you) can debug TYPO3 core files in Komodo IDE perfectly now. But what happens if I reboot?

On Linux I would simply modify /etc/fstab to mount directories. But this does not work on Leopard either!

The simples approach is to create a shell script and add it to startup items in my account. The script could look like:

bindfs ~/Projects/TYPO3/TYPO3-dev/t3lib ~/Projects/t3test/t3lib
bindfs ~/Projects/TYPO3/TYPO3-dev/typo3 ~/Projects/t3test/typo3

So far, so good. But terminal window now flickers at login. Not a big deal but not very elegant. Is there a better way?

AppleScript for bindfs

The final steo is to use AppleScript to create an application that runs as startup item. It will open, perform shell command and quit.

I opened AppleScript editor and created a new script. I wrote the following code:

do shell script "bindfs ~/Projects/TYPO3/TYPO3-dev/typo3 ~/Projects/t3test/typo3"
do shell script "bindfs ~/Projects/TYPO3/TYPO3-dev/t3lib ~/Projects/t3test/t3lib"

Next I save this as source script. Then I save the script again but now choose "Application" as the file type. All done! After adding this application to my startup items (with "Hide" flag) I can enjoy automatic mounting of my TYPO3 directories on reboot.

What about changine to another version? Is it still possible? Sure!

umount ~/Projects/t3test/typo3
umount ~/Projects/t3test/t3lib
bindfs ~/Projects/TYPO3/TYPO3-4.2/t3lib ~/Projects/t3test/t3lib
bindfs ~/Projects/TYPO3/TYPO3-4.2/typo3 ~/Projects/t3test/typo3

This is it. The simple an easy way to debug your multiple versions of TYPO3 using Komodo IDE.

You can download the bindfs complied for Leopard/Intel below. You still need to install MacFUSE.

No comments:

Post a Comment