ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ninju Bohra <ninju_bo...@yahoo.com>
Subject Re: Using antcall but not re-running dependent targets
Date Sun, 21 Jan 2007 03:51:13 GMT
Yes, 

The behavior you see is correct...there is an inherent limition of the <antcall> task
becuase it starts a new ANT "cycle" and knowlegde of previous run targets (like your "init"
target) are not retained. 

You can try many different solutions: 

First solution: 
1) Create a "property setting" target like the following 
<target name="determineOS">
    <condition property="isMAC">
        <os name="Mac OS X"/>
    </condition>
</target>
      The key thing is to avoid the usage of the else attribute of the condition task, we
DO NOT want the property to be defined only IF the OS is Mac OS X

2) Now add an "if" to your "two-mac" target --> so that it will only execute if the isMAC
property is set
    <target name="two-mac" if="isMAC" depends="init">
        .
        .
        .
    </target>
        Now unfortunately, the way ANT is written the presence of an "if" attribute only controls
the execution of the tasks within the target NOT the execution of the dependent targets (but
we will fix soon enough)
3) Add an "unless" attribute to your "two-other" target --> so that it will only execute
if the isMAC property is NOT set
    <target name="two-other" unless="isMAC" depends="init">
        .
        .
        .
    </target>
4) Now adjust your "init" target to run the "determineOS" target in its depends list
5) Adjust your main target "one" to run the targets in order
    <target name="one" depends="init, two-mac, two-other">
        .
        .
        .
    </target>
        And now instead of <antcall> off to another target (and incurring the cost of
creating a new ANT "cycle") you are attempting to run both targets and based on the way they
are protected (via the if/unless attributes) only one of them will run.
6) Along the same line, to make sure that the code of the "init" target is run only once you
can add an "unless" attribute in its definition and set the property at the bottom of the
target:
    <target name="init" unless="init_run_already">
        .
        (really delicate stuff that can only be run once)
        .
        <property name="init_run_already" value="yeah!!!"/>
    </target>






----- Original Message ---- 
From: Cameron McCormack <cam@mcc.id.au> 
To: user@ant.apache.org 
Sent: Saturday, January 20, 2007 4:59:26 AM 
Subject: Using antcall but not re-running dependent targets 


Hi. 

I’ve got a build file that’s structured like this: 

<target name="init"> 
<echo message="something"/> 
</target> 

<target name="one" depends="init, something"> 
<condition property="suffix" value="mac" else="other"> 
<os name="Mac OS X"/> 
</condition> 
<antcall target="two-${suffix}"/> 
</target> 

<target name="two-mac" depends="init"> 
</target> 

<target name="two-other" depends="init"> 
</target> 

<target name="something"> 
</target> 

If I run "ant one" I get: 

jet:/tmp $ ant one 
Buildfile: build.xml 

init: 
[echo] something 

something: 

one: 

init: 
[echo] something 

two-other: 

BUILD SUCCESSFUL 

but I want it so that the init target doesn’t get run again, because it 
has already been run. Is that just a limitation of antcall (that it 
forgets which dependencies have already been run)? If so, how I else 
can I get this sort of flow control? 

Thanks, 

Cameron 

-- 
Cameron McCormack, http://mcc.id.au/ 
xmpp:heycam@jabber.org ▪ ICQ 26955922 ▪ MSN cam@mcc.id.au 

--------------------------------------------------------------------- 
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org 
For additional commands, e-mail: user-help@ant.apache.org


 
____________________________________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message