代码之家  ›  专栏  ›  技术社区  ›  Tahir Akhtar

蚂蚁目标的“如果”和“依赖”的评估顺序是什么?

ant
  •  20
  • Tahir Akhtar  · 技术社区  · 15 年前

    也就是说,当testSetupDone的计算结果为false时调用下面的目标,是否执行依赖链中的目标?

    <target name="-runTestsIfTestSetupDone" if="testSetupDone" depends="-runTests" />
    
    2 回复  |  直到 15 年前
        1
  •  20
  •   Peter Lang    12 年前

    是的,依赖关系在条件得到评估之前执行。


    从 Ant manual :

    重要: if和除非属性只启用或禁用它们附加到的目标。它们不控制条件目标所依赖的目标是否被执行。事实上,在目标即将执行并且其所有前辈都已运行之前,它们甚至都不会得到计算。


    你也可以自己试试:

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

    我正在设置属性 testSetupDone

    Buildfile: build.xml
    
    -runTests:
    
    runTestsIfTestSetupDone:
         [echo] Test
    
    BUILD SUCCESSFUL
    Total time: 0 seconds
    

    目标 -runTests 被处决了,尽管 现在还没有设定,而且 runTestsIfTestSetupDone depend 被评估 if

        2
  •  5
  •   Brad Parks    13 年前

    从 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
    
    推荐文章