You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Kevin Toomey <to...@yahoo.com> on 2000/09/01 15:52:21 UTC

"depends" gets executed before "if"

Hello,

Given the build.xml statements below, I expected that my input and
output directories would get deleted only if the property cleanAll was
set. That's not the case. The "depends" targets get executed first,
then the "if" is checked. I can get around this easily enough, by
moving the "if" checks to the two delete_* tasks. 
Am I missing something in thinking that "if" and "unless" should be
checked prior to performing depends"?

Thanks,

Kevin.

<!--===================== -->
<!-- Build all packages = -->
<!-- ==================== -->

<target name="all" depends="clean,
			unzip_source_jar,
			build_all">
</target>

<!-- ========================================== -->
<!-- Clean out source and classes directories = --> 
<!-- ========================================== -->

<target name="clean" if="cleanAll" depends="delete_class_files,
				delete_source_files">
</target>

<!-- ============================================ -->
<!-- Delete everything in the classes directory	= -->
<!-- ============================================ -->

<target name="delete_class_files" depends="init">
	<deltree dir="${outDir}" /> 
</target>

<!-- =========================================== -->
<!-- Delete everything in the source directory = -->
<!-- =========================================== -->

<target name="delete_source_files" depends="init">
	<delete dir="${inDir}" /> 
</target>



__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/

Re: "depends" gets executed before "if"

Posted by Jesse Glick <Je...@netbeans.com>.
Kevin Toomey wrote:
> Given the build.xml statements below, I expected that my input and
> output directories would get deleted only if the property cleanAll was
> set. That's not the case. The "depends" targets get executed first,
> then the "if" is checked. I can get around this easily enough, by
> moving the "if" checks to the two delete_* tasks.
> Am I missing something in thinking that "if" and "unless" should be
> checked prior to performing depends"?

Well, they're not...they only apply to the target they are placed on,
and I believe they are checked at runtime when that target is reached.
The "depends" analysis is done statically before any targets are run. I
can see how this would be considered confusing. Anyway, just add the
if-test to the subtargets; or move the subtargets into the body of a
conditional target, thus:

<target name="clean" depends="maybeCleanAll">
  <!-- do light clean tasks -->
</target>
<target name="maybeCleanAll" if="cleanAll">
  <ant dir="." target="reallyCleanAll"/>
</target>
<target name="reallyCleanAll"
depends="delete_class_files,delete_source_files"/>

Clumsy and not very efficient but you can make it work.

-Jesse

-- 
Jesse Glick   <ma...@netbeans.com>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR