On 7/2/05, Stephen Touset <[EMAIL PROTECTED]> wrote:
> Is it possible to have a depends clause in a target that uses a
> property? In other words,
> 
> <target name="A"/>
> <target name="B"/>
> <property name="target" value="B"/>
> <target name="C" depends="${target}"/>
> 
> Whenever I do this, any attempt to build results in an error saying the
> property ${target} had not been set. However, it's set to a default in
> the top level of the build file (other targets change it).
> 
> The reason I want to do this is because I want a release and debug
> target to both depend on the same build target, but modify the build
> parameters slightly. The build target can't execute unless one of those
> has been run, and other targets depend on the build target.
> 
> Right now I'm just putting a <call> at the beginning of the build
> target, but this is sort of a dirty hack, and messes with the order of
> output when nant runs.
> 
> --
> Stephen Touset <[EMAIL PROTECTED]>

Stephen,

The normal way (AFAIK) to achieve this is to have your target 'C'
depend on _both_ targets, and then use conditionals on those targets
to determine which is supposed to run.  To rearrange your example
above:

<target name="A" if="${target == 'A'}" />
<target name="B" if="${target == 'B'}" />
<property name="target" value="B" />
<target name="C" depends="A,B" />

If you need to protect against invalid targets, then you could use a
slightly more complicated construct...

<target name="A" if="${target.name == 'A'}>
  <do-things />
  <property name="target.ran" value="true" />
</target>
<target name="B" if="${target.name == 'B'}>
  <do-things />
  <property name="target.ran value="true" />
</target>
<target name="AorB" depends="A,B">
  <fail message="Invalid target specified, must be 'A' or 'B', was
'${target.name}'" unless="${target.ran}" />
</target>

<property name="target.name" value="B" />
<property name="target.ran" value="false" />
<target name="C" depends="AorB" />


A third alternative that requires the least change to your existing
scripts is simply to pull your <call> task into its own target, for
example:

<target name="C.prepare">
  <call target="${target}" />
</target>
<target name="C" depends="C.prepare" />

Your build script is simpler, and invalid targets are somewhat dealt
with, but your log output is still in the order you want.


Hope one of those is useful to you,

-- 
Troy


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Nant-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to