ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cyril Sagan <Cyril.Sa...@sas.com>
Subject How can I "conditionall chooise" a target implementation?
Date Wed, 28 May 2008 22:26:40 GMT
PROBLEM:  I'm trying to develop a general build framework.   In so doing,
          I need some mechanism for to provide a "conditional implementation"
          for a target.  We cannot solve this problem using <antcall/>.
          Can anyone suggest an implementation?


Here's a couple ways that I tried, that almost work,... but do not.

All use this simple build.xml:
  <?xml version="1.0"?>
  <project name="generic_build" default="all">
      <property file="config.properties" />
      <import file="common.xml"/>
  </project>


Failing attempt #1:  This almost works, but doesn't because <import/>
cannot be embedded inside a target!!  arg!

common.xml:
  <?xml version="1.0"?>
  <project name="generic_build" default="all">
      <target name="use_lib_A" if="use.A">
          <!-- sorry, cannot <import/> in a target! -->
          <import file="lib_A.xml" />  <!-- target "all_impl" defined inside -->
      </target>

      <target name="use_lib_B" if="use.B">
          <!-- sorry, cannot <import/> in a target! -->
          <import file="lib_B.xml" />  <!-- target "all_impl" defined inside -->
      </target>

      <target name="all"
              depends="init, use_lib_A, use_lib_B, all_impl" />
  </project>



Failing attempt #2:  This would work, if Ant supported property expansion
in the targets's depends attribute.

common.xml:
  <?xml version="1.0"?>
  <project name="generic_build" default="all">
      <import file="lib_A.xml" />
      <import file="lib_B.xml" />

      <target name="use_lib_A" if="use.A">
          <property name="use.library" value="lib_A" />
      </target>

      <target name="use_lib_B" if="use.B">
          <property name="use.library" value="lib_B" />
      </target>

      <target name="use_lib_B" if="use.B">
          <import file="lib_B.xml" />  <!-- target "all_impl" defined inside -->
      </target>

      <!-- sorry, no property expansion inside attributes! -->
      <target name="all"
              depends="init, use_lib_A, use_lib_B, ${use.library}.all_impl" />
  </project>



Failing attempt #3:  Almost works, except the depends targets
always excute...

common.xml:
  <?xml version="1.0"?>
  <project name="generic_build" default="all">
      <import file="lib_A.xml" />
      <import file="lib_B.xml" />

      <!-- sorry, depends called regardless of if/unless -->
      <target name="use_lib_A" if="use.A" depends="implementation_A" />
      <target name="use_lib_A" if="use.B" depends="implementation_B" />

      <target name="all"  depends="init, use_lib_A, use_lib_B"
  </project>

This gets us closest to what we want, and would suffice if we could
tolerate the <antcall/>:
      <target name="use_lib_A" if="use.A">
          <antcall target="implementation_A" />
      </target>

...but we can't use antcall because it re-reads the *entire* build
file.  There's some fairly complicated init (that we don't have
control of) that doesn't tolerate being called multiple times.

I'd appreciate any suggestions from the experts!

Thanks.

--Cyril

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


Mime
View raw message