ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Wall <>
Subject Re: Conditional target execution based on prerequisite execution
Date Tue, 18 Feb 2003 17:26:06 GMT

On Tuesday, February 18, 2003, at 12:02 PM, Mike Ayers wrote:

>> If B is only run when one or more of its dependencies is run,
>> then the
>> problem seems to be those bootstrap targets which have no "depends";
>> they need to be conditionally run to prevent the entire remainder of
>> the chain from always being run.
> 	Errr - I don't know if you realize it, but you are stating a basic 
> build principle hre.  Am I missing something?

Well, none of the ant examples or sample build scripts make the "init" 
target conditional.  Which means it is always run, which means that 
"compile" and "dist" are always run, whether or not they need to be.  
Since all of the ant documentation provide that as the canonical "init" 
target, it is easily inferred that that is the common or expected 
behavior.  I don't think that it *should* be the common or expected 

"Make" ties targets to the filesystem.  While this becomes a liability 
when you *don't* want a target tied to a file, it does give you good 
default automatic detection of when a target is up to date - does the 
file exist?  ant has no such built-in default behavior.  While the 
functionality is certainly there by way of properties, it's not 
necessarily clear and certainly not extant in any examples.

So the short answer to my question to prevent the whole ball of wax 
being run every time is this:
The init target needs to conditionally execute based on whether its 
tasks have already been done.  Detection of whether its tasks have been 
done must be done by setting properties.

Note that
<target name="init">
	<mkdir dir="name"/>

Will *always* be run, and therefore cause everything else in the 
project to be run.  This is a horrid example to propagate, since it 
results in a failure of the project to scale.  Instead, the examples 
should look like this:

<property-setting-magic name="init-not-done" value=" exists"/>
<target name="init" onlyif="init-not-done">
	<mkdir dir="name"/>

This means, however, that every "bootstrap" target has to have an extra 
bit of logic that's not actually part of the <target> tag, which adds 
to the project file complexity.  This sort of thing should be built in.

>> What is the canonical "Only create this directory if it
>> doesn't exist"
>> rule?
> 	There may not be a canonical form, but this will work:
> <condition property="dir.makeme" >
> 	<available ${} >
> </condition>
> <mkdir dir=${} />
> 	I have a suspicion, however, that just "<mkdir dir=${} />" 
> will also work.
> /|/|ike
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View raw message