Search code examples
antosx-snow-leopard

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.


Solution

  • 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.