ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <k...@panix.com>
Subject Re: Conditional compilation
Date Thu, 13 Jun 2002 12:21:22 GMT


   From: "Erik Hatcher" <jakarta-ant@ehatchersolutions.com>
   To: "Ant Users List" <ant-user@jakarta.apache.org>
   Subject: Re: Conditional compilation

   You're bound to get a flood of replies to this:

   <property name="build.debug" value="true"/>
   <javac debug="${build.debug}">

   then run with: ant -Dbuild.debug=false to turn it off.

Thanks, Erik!

I have two follow-up questions; they are both about useful things I
used to accomplish with command-line flags when I used make, but I
can't figure out how to do it with ant.

With make, to conditionally include source files in the distribution
jar, I would do something like:

  ifdef WITH_SOURCE
  SOURCE_TO_JAR = ${SourceFiles}
  else
  SOURCE_TO_JAR =
  endif

The ${SOURCE_TO_JAR} would be one of the arguments to the jar command
in the Jar target; it would be an empty string unless WITH_SOURCE was
set via

  make -WITH_SOURCE=1

Now with ant I would like to have a command-line flag
-Dwithsource=true that similarly causes source code to be included in
the distribution jar.  The problem is that I can't figure out where to
make that set variable act, since the obvious place, namely the
fileset data type, doesn't accept the if/unless attributes.

The best I can come up with in this case is something like this:

  <target name="jar" depends="init,compile">
    <jar jarfile="MyProject-${DSTAMP}.jar" manifest="Manifest">
      <!-- basedir="${build}" -->
      <fileset dir="${build}"/>
      <fileset dir="${sourcedir}"
               includes="${withsource}"/>
    </jar>
  </target>

and run with

  % ant -Dwithsource='**/*.java'

To my surprise, this actually seems to work without major mishaps, but
this way of setting the withsource flag is difficult to remember, and
it is not suitable for cases where the fileset specification for the
source files to include is more complicated.  The approach I describe
above with make as far cleaner and easier to use.  Is there a way to
do this with ant?

The second question relates to my other questions so far.  It has to
do with making a command-line flag imply another.  Again, in the case
of make, if I wanted the flag DEBUG to imply the WITH_SOURCE flag, I
would simply add this to my makefile:

  ifdef DEBUG
  WITH_SOURCE = 1
  endif

  ifdef WITH_SOURCE
  #
  # etc., etc.
  # 
  endif

How can I do a similar thing with ant?

Again, thanks for your help!

kynn

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


Mime
View raw message