Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build an ant target conditionally on Snow Leopard

I have a cross-platform application and we use ant to build different things on different platforms. Now a new requirement came up and I need to do things differently if building on Snow Leopard or later vs Leopard.

I've looked at http://www.devdaily.com/blog/post/java/how-determine-operating-system-os-ant-build-script which shows how to distinguish between Windows and Macintosh etc., and http://www.jajakarta.org/ant/ant-1.6.1/docs/en/manual/api/org/apache/tools/ant/taskdefs/condition/Os.html which shows additional properties for os, like ${os.version}.

What I haven't figured out is how can I compare the os.version value and if it is 10.6 or higher do the Snow Leopard thing. If I could set a variable snow_leopard to 1 when on Snow Leopard I think I would be able to figure the rest of it out.

like image 831
Heikki Toivonen Avatar asked Feb 10 '11 01:02

Heikki Toivonen


2 Answers

You might use the condition task for this. The available conditions, notable for os are here.

It would work in the same way as for 'os family':

<condition property="isSnowLeopard">
    <os family="mac" version="10.6.6" />
</condition>

But that means you have to put in the incremental version number - the version string has to match exactly.

For a 'fuzzier' alternative, you could use a matches condition, something like this perhaps

<condition property="isSnowLeopard">
    <matches string="${os.version}" pattern="^10.6." />
</condition>

When OSX Lion emerges, you may want to extend the pattern like the this:

<condition property="isSnowLeopardOrGreater">
    <matches string="${os.version}" pattern="^10.[67]." />
</condition>

Or introduce a separate check for 10.7.

like image 88
martin clayton Avatar answered Oct 07 '22 01:10

martin clayton


Using the <if> task provided by ant-contrib, you can achieve this to an extent, by making an equals check for the os version.

...
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
        <pathelement location="/location/of/ant-contrib-1.0b3.jar"/>
    </classpath>
</taskdef>
<target name="oscheck">
    <property name="osver" value="${os.version}"/>
    <if>
        <equals arg1="${os.version}" arg2="6.1"/>
        <then>
            <echo message="Windows 7"/>
            ...
        </then>
    </if>
</target>
...
like image 32
Raghuram Avatar answered Oct 07 '22 00:10

Raghuram