Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what order are Ant target's "if" and "depends" evaluated?

Tags:

That is, will calling the following target when testSetupDone evaluates to false, execute the targets in dependency chain?

<target name="-runTestsIfTestSetupDone" if="testSetupDone" depends="-runTests" />
like image 491
Tahir Akhtar Avatar asked Oct 25 '10 11:10

Tahir Akhtar


2 Answers

Yes, the dependencies are executed before the conditions get evaluated.

From the Ant manual:

Important: the if and unless attributes only enable or disable the target to which they are attached. They do not control whether or not targets that a conditional target depends upon get executed. In fact, they do not even get evaluated until the target is about to be executed, and all its predecessors have already run.


Here is an example:

<project>
  <target name="-runTests">
    <property name="testSetupDone" value="foo"/>
  </target>
  <target name="runTestsIfTestSetupDone" if="testSetupDone" depends="-runTests">
    <echo>Test</echo>
  </target>
</project>

The property testSetupDone is set within the target in depends, and the output is:

Buildfile: build.xml

-runTests:

runTestsIfTestSetupDone:
     [echo] Test

BUILD SUCCESSFUL
Total time: 0 seconds

Target -runTests is executed, even though testSetupDone is not set at this moment. runTestsIfTestSetupDone is executed afterwards, so depend is evaluated before if.

like image 131
Peter Lang Avatar answered Oct 21 '22 10:10

Peter Lang


From the docs:

Ant tries to execute the targets in the depends attribute in the order they 
appear (from left to right). Keep in mind that it is possible that a 
target can get executed earlier when an earlier target depends on it:

<target name="A"/>
<target name="B" depends="A"/>
<target name="C" depends="B"/>
<target name="D" depends="C,B,A"/>

Suppose we want to execute target D. From its depends attribute, 
you might think that first target C, then B and then A is executed. 
Wrong! C depends on B, and B depends on A, 
so first A is executed, then B, then C, and finally D.

Call-Graph:  A --> B --> C --> D
like image 45
Brad Parks Avatar answered Oct 21 '22 11:10

Brad Parks