ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Bullington <shockr...@yahoo.com>
Subject Re: Doing both debug and release builds with same targets
Date Fri, 16 Nov 2001 01:31:02 GMT
The way I would do it is the following

<target name="setmode" unless="mode">
    <echo message="mode not set, setting mode to debug"/>
    <property name="mode" value="debug" />
</target>

<target name="compile-proj1" depends="prepare, setmode">
etc.

Hope this helps,
Jim

--- Alan Pearson <AlanP@paramark.com> wrote:
> This must be a relatively common task, so I present the Ant user
> commuity
> with the following question: I am trying to write a build.xml file
> that can
> build in either debug mode or release mode depending on which target
> is
> invoked on the command line (or build them both). The difference
> between the
> two builds will be the settings of the Optimization/Debug flags on
> the javac
> tasks, and also the output directories for classes and other
> generated
> files. My best solution has the following structure:
> 
> <?xml version='1.0' encoding='utf-8'?>
> <project name="test" default="both" basedir=".">
> 
>         <target name="prepare">
>                 <echo message = "Preparing ${mode} directory." />
>         </target>
> 
>         <target name="compile-proj1" depends="prepare">
>                 <echo message = "compiling project 1 in ${mode} mode"
> />
>         </target>
> 
>         <target name="compile-proj2" depends="prepare">
>                 <echo message = "compiling project 2 in ${mode} mode"
> />
>         </target>
> 
>         <target name="build" depends="compile-proj1,compile-proj2" />
> 
>         <target name="debug-build">
>                 <property name="mode" value="debug" />
>                 <antcall target="build" />
>         </target>
> 
>         <target name="release-build">
>                 <property name="mode" value="release" />
>                 <antcall target="build" />
>         </target>
> 
>         <target name="both">
>                 <antcall target="debug-build" />
>                 <antcall target="release-build" />
>         </target>
> 
> </project>
> 
> When I run ant with the "both", the "debug-build" or the
> "release-build"
> target, it does exactly what I want.  The problem with this Is that I
> can
> only do the top-level build targets sucessfully.  If I am working on
> just
> "project1", I'd like to be able to run "ant compile-proj1" and have
> it just
> build that project (preferably in debug-mode).  However if I run ant
> that
> way, the ${mode}does not get set, and I get the output:
> 
> prepare:
>      [echo] Preparing ${mode} directory.
> 
> compile-proj1:
>      [echo] compiling project 1 in ${mode} mode
> 
> 
> So what I tried to do was to insert the statement
> 
>             <property name="mode" value="debug" />
> 
> at the very beginning of the file (right after the <project>
> declaration).
> My hope was that this would provide a "default" value for mode, and
> that
> when I ran "release-build" or when "both" antcall'ed "release-build"
> the
> property statement within that target would override the default
> setting.
> Unfortunately, it didn't happen that way.  After adding the above
> property
> statement, the release-build target started using ${mode}="debug".
> 
> Can I have my cake and eat it too? Is there a way to set the default
> value
> of ${mode} to be "debug" and have it set to "release" only when the
> release-build target is run?
> 
>  
> 
> Thanks,
> 
> Alan Pearson
> 
>  
> 
> 


__________________________________________________
Do You Yahoo!?
Find the one for you at Yahoo! Personals
http://personals.yahoo.com

--
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