You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Antoine Levy Lambert <an...@gmx.de> on 2009/12/14 15:16:43 UTC

deep-if/deep-unless

Hi,

the current discussion about target groups reminds me that there is 
something else that I would need in ant.

Currently, when a build file contains this :

<target name="foo" depends="bar" if="someproperty"/>

When executing foo, bar will get executed regardless of whether 
someproperty is set or not.

I would often see the need for another variation of if, which would 
remove bar from the dependency tree if someproperty is not set.

Since obviously, it is something else, maybe this should have another 
attribute name such as "deep-if"

<target name="foo" depends="bar" deep-if="someproperty"/>


I have never thought about how this could be implemented and how much 
work it is. It is probably a non-trivial addition because it means that 
the list of targets to execute and their order will change dynamically 
during the build depending upon how properties evaluate at run time.

Regards,

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


Re: deep-if/deep-unless

Posted by Gilles Scokart <gs...@gmail.com>.
2009/12/16 Dominique Devienne <dd...@gmail.com>

>
>    ant deploy /block:war
>
>
Sounds very cool !

I often tried to implement such things into my ant script, but I never found
the right ideom to do that.  But this gave me an idea I might give a try :

<project>

    <target name="/block:war" depends="/block:compile">
        <property name="skip.war"/>
    </target>
    <target name="war" depends="compile" unless="skip.war">
       ...
    </target>

    <target name="deploy" depends="war" unless="skip.deploy">
       ...
    </target>

</project>


$> ant /block:war deploy

Re: deep-if/deep-unless

Posted by Dominique Devienne <dd...@gmail.com>.
On Wed, Dec 16, 2009 at 9:32 AM, Antoine Levy Lambert <an...@gmx.de> wrote:
> is a sequence of tasks. If the process is highly configurable, there can be
> several blocks of tasks which are optionally executed.

Maybe a custom executor that blocks some targets would work for you?
Depends how these properties that prevent a target from executing
(including their dependencies) are set or computed, but from the
command line you could say

    ant deploy /block:war

to launch the deploy target, completely forcing the removal of the war
target from the target dependency graph. I guess the issue with your
proposed deep if/unless is when that condition is evaluated. IMHO,
once the DAG has been resolved and targets start running, it's too
late. If you decide to block from the command line, that's OK, because
you in effect "edit" the script on the fly before it started, to
remove a dependency occurring anywhere in the DAG, overriding the
build author's intention on purpose. But once it's started, the effect
of removing a dependency in the middle could reorder the build in such
a way that it's now incompatible with the targets already executed so
far, and this to me makes it brittle and undesirable. My $0.02. --DD

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


Re: deep-if/deep-unless

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hello Stefan,

Stefan Bodewig wrote:
> On 2009-12-16, Antoine Levy Lambert <an...@gmx.de> wrote:
>
>   
>> Bruce Atherton wrote:
>>     
>>> I think that would be very confusing at this point.
>>>       
>
>   
>> If most people in the ant community, especially committers, think that
>> this idea breaks the philosophy of ant, then it should not be
>> developed.
>>     
>
> It may be confusing to have similarly named attributes for the two
> different approaches.  I'd prefer to toy with the executor approach
> suggested by Dominique and see where it leads - and certainly defer it
> until after the 1.8.0 release.
>   
Sounds good.

Antoine
> Stefan
>
>   


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


Re: deep-if/deep-unless

Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-12-16, Antoine Levy Lambert <an...@gmx.de> wrote:

> Bruce Atherton wrote:
>> I think that would be very confusing at this point.

> If most people in the ant community, especially committers, think that
> this idea breaks the philosophy of ant, then it should not be
> developed.

It may be confusing to have similarly named attributes for the two
different approaches.  I'd prefer to toy with the executor approach
suggested by Dominique and see where it leads - and certainly defer it
until after the 1.8.0 release.

Stefan

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


Re: deep-if/deep-unless

Posted by Antoine Levy Lambert <an...@gmx.de>.
Bruce Atherton wrote:
> I think that would be very confusing at this point. 
If most people in the ant community, especially committers, think that 
this idea breaks the philosophy of ant, then it should not be developed. 
Maybe this kind of needs will be better addressed using the new groovy 
front-end. What I have in mind is the use of ant to drive deployments. I 
think that although we state on the home page of ant that ant is a build 
tool, because all batch processes, such as cooking or chemistry or 
assembling a robot are also build processes in essence, ant can be used 
to drive any process which is a sequence of tasks. If the process is 
highly configurable, there can be several blocks of tasks which are 
optionally executed.
> For better or worse, Ant was designed from the beginning to build its 
> dependencies through backwards chaining. It is often (usually) 
> surprising behaviour to the first time user, but once learned quickly 
> becomes second nature. Introducing a new construct that does the 
> reverse seems likely only to cause massive confusion, especially one 
> with such a similar name.
What I propose does not set backward chaining in question. Another name 
could be found. Instead of using a different attribute name "deep-if" 
"deep-unless" one could use another element name such as <block, 
<target-block, ..., for instance <block name="foo" depends="bar" 
if="someproperty"/>.
>
>
> The fact that often an init method is the lowest level dependency and 
> sets many of the properties used in "if" and "unless" attributes 
> higher in the dependency tree is, I think, a good way to introduce 
> people to the Ant way of designing builds as lists of target 
> dependencies.
>
> Besides, as Jesse points out, there is a very simple workaround.
>
Using <ant/> or <antcall/> is not a perfect workaround.

ant and antcall create an ant subcontext.  Properties and references set 
by targets invoked through ant and antcall do not return to the calling 
context.

also, targets which have already been executed when you reach <ant/> can 
be executed a second time, and the targets which are executed during the 
<ant/> invocation can be reexecuted later by the calling context.

Regards,

Antoine


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


Re: deep-if/deep-unless

Posted by Bruce Atherton <br...@callenish.com>.
I think that would be very confusing at this point. For better or worse, 
Ant was designed from the beginning to build its dependencies through 
backwards chaining. It is often (usually) surprising behaviour to the 
first time user, but once learned quickly becomes second nature. 
Introducing a new construct that does the reverse seems likely only to 
cause massive confusion, especially one with such a similar name.

The fact that often an init method is the lowest level dependency and 
sets many of the properties used in "if" and "unless" attributes higher 
in the dependency tree is, I think, a good way to introduce people to 
the Ant way of designing builds as lists of target dependencies.

Besides, as Jesse points out, there is a very simple workaround.

Antoine Levy Lambert wrote:
> Hi,
>
> the current discussion about target groups reminds me that there is 
> something else that I would need in ant.
>
> Currently, when a build file contains this :
>
> <target name="foo" depends="bar" if="someproperty"/>
>
> When executing foo, bar will get executed regardless of whether 
> someproperty is set or not.
>
> I would often see the need for another variation of if, which would 
> remove bar from the dependency tree if someproperty is not set.
>
> Since obviously, it is something else, maybe this should have another 
> attribute name such as "deep-if"
>
> <target name="foo" depends="bar" deep-if="someproperty"/>
>
>
> I have never thought about how this could be implemented and how much 
> work it is. It is probably a non-trivial addition because it means 
> that the list of targets to execute and their order will change 
> dynamically during the build depending upon how properties evaluate at 
> run time.
>
> Regards,
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>


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


Re: deep-if/deep-unless

Posted by Antoine Levy Lambert <an...@gmx.de>.
Stefan Bodewig wrote:
> On 2009-12-14, Antoine Levy Lambert <an...@gmx.de> wrote:
>
>   
>> I have never thought about how this could be implemented and how much
>> work it is. It is probably a non-trivial addition because it means
>> that the list of targets to execute and their order will change
>> dynamically during the build depending upon how properties evaluate at
>> run time.
>>     
>
> If you made it fully dynamic, yes, and there are probably a lot of edge
> cases to consider.  In your construct
>
>   
>> <target name="foo" depends="bar" deep-if="someproperty"/>
>>     
>
> when would you evaluate someproperty?  Before bar is scheduled?  
Yes, I was thinking of evaluating someproperty before bar is scheduled.
> If you
> evaluate it when foo is about to execute it will be too late since bar
> has already been run.
>
> If we restricted deep-if to properties/conditions that can be evaluated
> at parser time, then the dependency tree wouldn't change at runtime and
> such a change wouldn't have as big an impact as a truely dynamic
> solution.
>   
I would go for the fully dynamic solution. This would work for 
situations like
<project name="get-all-from-oven" default="get-all-from-oven">
<target name="get-bread-from-oven" 
depends="get-oven-gloves,open-oven-door" 
deep-unless="bread-already-onthetable"/>
<target name="get-cake-from-oven" 
depends="get-oven-gloves,open-oven-door" 
deep-unless="cake-already-onthetable"/>
<target name="get-all-from-oven" 
depends="check-what-is-on-thetable,get-bread-from-oven,get-cake-from-oven,close-oven-door,remove-oven-gloves"/>
.... various subtargets go here
</project>


Antoine


> Stefan
>   


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


Re: deep-if/deep-unless

Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-12-14, Antoine Levy Lambert <an...@gmx.de> wrote:

> I have never thought about how this could be implemented and how much
> work it is. It is probably a non-trivial addition because it means
> that the list of targets to execute and their order will change
> dynamically during the build depending upon how properties evaluate at
> run time.

If you made it fully dynamic, yes, and there are probably a lot of edge
cases to consider.  In your construct

> <target name="foo" depends="bar" deep-if="someproperty"/>

when would you evaluate someproperty?  Before bar is scheduled?  If you
evaluate it when foo is about to execute it will be too late since bar
has already been run.

If we restricted deep-if to properties/conditions that can be evaluated
at parser time, then the dependency tree wouldn't change at runtime and
such a change wouldn't have as big an impact as a truely dynamic
solution.

Stefan

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


Re: deep-if/deep-unless

Posted by Jesse Glick <je...@sun.com>.
Antoine Levy Lambert wrote:
> <target name="foo" depends="bar" if="someproperty"/>
> 
> When executing foo, bar will get executed regardless of whether 
> someproperty is set or not.
> 
> I would often see the need for another variation of if, which would 
> remove bar from the dependency tree if someproperty is not set.

<target name="foo" if="someproperty">
   <antcall target="bar"/>
</target>


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