b-log – betriebsraum weblog

Software Development, Human-Computer Interaction, Projects…

Faster parallel MXMLC compilation using Ant

February 9, 2010

Whenever you have a Flex project consisting of several modules, you can take advantage of compiling those modules in parallel – provided that they don’t depend on each other – using Ant and the Ant-Contrib tasks. In a project with five modules, I’ve seen a speed increase of about 30% compared to normal sequential compilation. I haven’t tested yet how this setup performs with more modules but I guess you could run into memory problems when compiling too many of them in parallel (you could still compile them in batches then). Below is part of an Ant script which does the job…here a few notes:

Of course, you can also run this script on a CI-Server but if you want to use the IDE for parallel compilation: IntelliJ, for example, will support parallel compilation in the next update. Another way to speed things up is the HFCD compiler which I haven’t tried yet…

Here’s the Ant snippet (left out the property definitions):

<taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
        <pathelement location="libs/ant/ant-contrib-1.0b3.jar"/>
    </classpath>
</taskdef>
 
<fileset id="flex.source.files" dir="${flex.source.dir}">
    <include name="**/*.as"/>
    <include name="**/*.mxml"/>
    <include name="**/*.css"/>
</fileset>
 
<macrodef name="compile-app">
    <attribute name="debug" default="true"/>
    <attribute name="appName"/>
    <sequential>
        <outofdate>
            <sourcefiles>
                <fileset refid="flex.source.files"/>
            </sourcefiles>
            <targetfiles path="${flex.release.dir}/@{appName}.swf"/>
            <sequential>
                <java jar="${flex.sdk.dir}/lib/mxmlc.jar" fork="true" failonerror="true">
                    <arg value="-debug=@{debug}"/>
                    <arg value="-incremental=@{debug}"/>
                    <!-- rest of mxmlc options -->
                </java>
            </sequential>
        </outofdate>
    </sequential>
</macrodef>
 
<macrodef name="compile-all">
    <attribute name="debug" default="true"/>
    <sequential>
        <compile-app appName="main" debug="@{debug}"/>
        <for list="${flex.modules}" param="module.name" parallel="true">
            <sequential>
                <compile-app appName="@{module.name}" debug="@{debug}"/>
            </sequential>
        </for>
    </sequential>
</macrodef>
 
<target name="compile-all-debug">
    <compile-all debug="true"/>
</target>

Filed under: Flex/AS3, Software Development

2 Responses to “Faster parallel MXMLC compilation using Ant”

  1. flo says:

    Hi,

    could you post the properties section as well, please?

    Thanx, flo;

  2. felix says:

    Hi Flo,

    the properties and values depend on your project setup but for the simplified example above they could be:

    <property name="flex.sdk.dir" value="${basedir}/tools/flex-sdk"/>
    <property name="flex.source.dir" value="${basedir}/src/flex"/>
    <property name="flex.release.dir" value="${basedir}/web/swf"/>
    <property name="flex.modules" value="module1,module2,module3"/>

Add a comment

Follow comments to this post by subscribing to the comment feed.