Phing Symlink task


Many projects have shared items across them. For example, Typo3 projects can share the same source, but just sticking it on the include path doesn’t necessarily solve the problem, so you have to symlink it from a shared location into your project.

Since my build tool of choice is Phing and usually I like having a build running just by running “phing” in the project root, I had to get the symlinks created during the build process. The Symlink task does just that.

Using it is pretty straight forward:

Until the next release, you will have to define it using taskdef:

<!-- Load the symlink task -->
<taskdef name="symlink" classname="phing.tasks.ext.SymlinkTask" />

Once defined, you can start symlinking (I’ll use the Typo3 example):

<target name="typo3:symlink" depends="needConfiguration" description="Generates the requried typo3 symlinks">
    <delete file="${build.public_dir}/${typo3.index_file}" />
    <delete file="${build.public_dir}/t3lib" />
    <delete file="${build.public_dir}/typo3" />
    <delete file="${build.public_dir}/typo3src" />
 
    <symlink target="/share/typo3_src-${typo3.source}" link="${build.public_dir}/typo3src" />
    <symlink target="${build.public_dir}/typo3src/index.php" link="${build.public_dir}/${typo3.index_file}" />
    <symlink target="${build.public_dir}/typo3src/t3lib" link="${build.public_dir}/t3lib" />
    <symlink target="${build.public_dir}/typo3src/typo3" link="${build.public_dir}/typo3" />
</target>

The variables used within the target are:

build.public_dir – points to the document root of the build
typo3.source – version of Typo3 we’re using (4.4.4 for example)
typo3.index_file – t3index.php, we usually have a Zend bootstrap as index.php which includes the Typo3 index file

It can also do multiple symlinks at the same time. Consider having a “library” directory somewhere in your project, that contains the sources of some shared libraries (zend, doctrine, etc), to symlink all of those into your build:

<symlink link="${build.path}/library">
    <fileset dir="/share/library">
        <include name="*" />
    </fileset>
</symlink>

If the contents of /share/library were “Zend, Doctrine”, then in your build you’d have:

library/Zend -> /share/library/Zend
library/Doctrine -> /share/library/Doctrine

To install Phing, please follow these instructions.

Topics: Applications, Development, Work Tags:
Comments: none so far

Post a Comment

Your email is never shared. Required fields are marked *

*
*