ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ma, Jian" <Jian...@kmv.com>
Subject RE: Setting envrionment variables from within build.xml
Date Fri, 07 Dec 2001 00:56:38 GMT
there's a target called <antcall> which does that.

Jian"Chuck" Ma
KMV LLC
1620 Montgomery St. Suite 140
San Francisco, CA 94111
415-352-1157(w)




-----Original Message-----
From: Ron Coutts [mailto:RonC@quadrus.com]
Sent: Thursday, December 06, 2001 4:48 PM
To: Ant Users List
Subject: RE: Setting envrionment variables from within build.xml


Thanks Jill, that was helpful.  I had been wondering if there was a way
for a target to call another target, besides using the 'depends'
attribute.  

I did find a trick that uses a target's 'depends' to set properties
before calling the task that executes 'msdev.exe'.  Have a look at the
chunk of build.xml below.  The 'ExecMsdev' task is as per your
suggestion, and puts the setting of the 'CL' environment variable in one
place.  Then I have a few targets designed to set a single property,
(call them 'property setting tasks' if you will).  Next, I have build
targets that are now one-liners.  The key with the build targets is that
the property setting targets are called before the 'ExecMsdev' target is
called.  I think this trick leaves the XML fairly easy to read and
maintain.

Thought I'd just put this out there.  

Thanks again,
Ron


<!-- ******************** MSDEV SUPPORT TARGETS ******************** -->
<target name="ExecMsdev" if="BuildConfig">
  <exec executable="msdev.exe">
    <env key="CL" value="${MsdevDefines}" />
    <arg line="${basedir}/${DswFile} /MAKE '${ProjectName} - Win32
${BuildConfig}'" />
  </exec>
</target>

<!-- dsw file setting targets -->
<target name="SetDswFileToEnvironmentPkg" >
  <property name="DswFile"
value="Code/EnvironmentPkg/EnvironmentPkg.dsw" />
</target>

<!-- project name setting targets -->
<target name="SetProjectNameToEnvironment" >  <property
name="ProjectName" value="Environment" /> </target>
<target name="SetProjectNameToFoo" >          <property
name="ProjectName" value="Foo" />	</target>
<target name="SetProjectNameToBar" >          <property
name="ProjectName" value="Bar" />	</target>

<!-- ******************** BUILD TARGETS ******************** -->
<target name="BuildEnvironment" depends="Init,
SetDswFileToEnvironmentPkg, SetProjectNameToEnvironment, ExecMsdev" />	
<target name="BuildFoo" depends="Init, SetDswFileToEnvironmentPkg,
SetProjectNameToFoo, ExecMsdev" />	
<target name="BuildBar" depends="Init, SetDswFileToEnvironmentPkg,
SetProjectNameToBar, ExecMsdev" />




-----Original Message-----
From: Jill Stephenson [mailto:jill.stephenson@suncorpmetway.com.au]
Sent: Thursday, December 06, 2001 4:19 PM
To: Ant Users List
Subject: Re: Setting envrionment variables from within build.xml


How about looking at the problem another way and extracting out
the common code into a subtarget to which you can pass a parameter
using the antcall task.  Something along the lines of the following ...

<target name="BuildEnvironmentPkg.make" >
   <exec executable="msdev.exe">
     <env key="CL" value="${MsdevDefines}" />
     <arg line="${basedir}/Code/EnvironmentPkg/EnvironmentPkg.dsw /MAKE
'${envName} - Win32 ${BuildConfig}'" />
   </exec>
</target>

<target name="BuildEnvironmentPkg" depends="Init" if="BuildConfig" >
  <antcall target="BuildEnvironmentPkg.make">
    <param name="envName" value="'Environment" />
  </antcall>
  <antcall target="BuildEnvironmentPkg.make">
    <param name="envName" value="'EnvironmentAutoTest" />
  </antcall>
</target>

--
Jill

----- Original Message -----
From: "Ron Coutts" <RonC@quadrus.com>
To: "'Ant Users List' (E-mail)" <ant-user@jakarta.apache.org>
Sent: Friday, December 07, 2001 8:59 AM
Subject: Setting envrionment variables from within build.xml


I was wondering if there's any way in Ant to set an environment variable
once before a series of <exec> tasks.  Consider the snippet of build.xml
below that is used to set the environment variable 'CL' before executing
the command line compiler 'msdev.exe'.  This XML works, but is an error
prone maintenace headache because the nested element <env> must be
repeatedly used.  Is there any way around this, such that I can set  the
environment variable 'CL' once before multiple <exec>'s?

Ron Coutts


<target name="BuildEnvironmentPkg" depends="Init"
if="BuildConfig" >
<exec executable="msdev.exe">
<env key="CL" value="${MsdevDefines}" />
<arg
line="${basedir}/Code/EnvironmentPkg/EnvironmentPkg.dsw /MAKE
'Environment - Win32 ${BuildConfig}'" />
</exec>
<exec executable="msdev.exe">
<env key="CL" value="${MsdevDefines}" />
<arg
line="${basedir}/Code/EnvironmentPkg/EnvironmentPkg.dsw /MAKE
'EnvironmentAutoTest - Win32 ${BuildConfig}'" />
</exec>
</target>

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



------------------------------------------------------------------------
-----------

The contents of this message are the views of the Author and do not
necessarily reflect the views of SUNCORP METWAY LTD  ABN 66 010 831 722.


The content of this e-mail, including attachments is a confidential
communication between the Suncorp Metway Group and the intended
addressee. Any unauthorised use of the contents is expressly prohibited.
If you have received this e-mail in error please contact the sender
immediately and then delete the message and any attachment(s).

http://www.suncorpmetway.com.au


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


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

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