ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject <property allowoverrides="true" />
Date Wed, 15 May 2002 15:48:48 GMT
This subject about property immutability comes often enough that I'm going
to add my $.02 about it ;-) 
(this post is prompted by today's 'Re: Re[4]: The old immutable properties
trick' thread, and my weekend reading)

Over a year ago, when I started playing around with ANT, having written
makefiles only prior, I got frustrated by the immutability of properties,
combined with relative inability of ANT to set properties conditionally. I
also tried to replace my makefile to build a Win32 dll using ant tasks
(superceded by antcontrib's cpp task I'm sure). I succeeded in creating a
custom <dll> task for that, but along the way also installed my custom
property instead of the default ANT property (extended it) to allow for
overrides, and added conditional testing in property itself. This allowed do
define things like the "lib.suffix" easily (see below), without resorting to
calling a bunch of targets. This looked like:

  <property name="lib.suffix" value="" allowoverrides="true" />
  <property name="lib.suffix" value="_g" if="debug" when="%{debug}==true" />
  <property name="lib.suffix" value="_n" if="numega" when="%{numega}==true"
/>

The 'when' attribute condition (not actually implemented... always returns
true) shows my frustration for the if/unless testing for property existence
;-) (behavior I didn't change for my own if/unless attribute).

I also had an 'os' attribute on my <property>, to have allow for:

  <property name="dll.extension" value=".so" allowoverrides="true" />
  <property name="dll.extension" value=".dll" os="Windows NT" />

The conditional functionality of my custom property task was factored in an
AbstractConditionalBaseTask.java, so it wasn't specific to <property>, and
was present for <dll> sub-elements, like <define>/<ccoption>/<ldoption>,
etc...

	  <define name="_DEBUG"     if="debug" />
	  <define name="NDEBUG" unless="debug" />

So where am I leading with all this? Well, only that maybe we could have
property immutability, and some sort of conditional mutability at the same
time. This morning, I read 2 chapters of 'Java and XSLT' from O'Reilly, and
there's an example with an <xsl:variable> conditionally set using a
<xsl:choose> inside it. Why can't we do something similar with <property> in
ANT:

  <property name="dll.extension" defaultvalue=".so">
    <value os="Windows NT">.dll</value>
  </property>

and

  <property name="lib.suffix">
    <value if="debug">_g</value>
    <value if="numega">_n</value>
  </property>

and also:

  <define name="_DEBUG"     if="debug" />
  <define name="NDEBUG" unless="debug" />

The property created is still immutable, but can take different values
depending on other properties. Everything's controlled by properties (user
ones, or builtin ones like 'os'), instead of targets with conditions.

All this is really rough, and more like a brain dump that anything else, but
hopefully that could move the debate farther than 'property are immutable'
and antcontrib's <if> can't make it into the code, etc...

Or at least it demonstrate one *can* have override-able properties if one
rolls once's own ;-) (OK, my impl is over a year old, wasn't tested with
<antcall>, and certainly override-ability wasn't transferred to forked
VMs...)

--DD

PS: Below is the full build.xml that compiled a Windows DLL using Visual
Studio using hacked up custom ant tasks that uses override-able properties,
and properties/tasks with conditions if/unless/os/when conditions.

<?xml version="1.0"?>

<!-- Lmktree's ANT build file -->
<project name="test-dll" default="com.lgc.gocad.lmktree" basedir=".">

  <!-- Custom Task to build a Windows DLL from C++ code -->
  <taskdef name="dll" classname="com.lgc.jax.tools.DllAntTask" />
  <taskdef name="property" classname="com.lgc.jax.tools.PropertyTask" />

  <property name="src.dir" value="src" />
  <property name="bin.dir" value="S:/bin" />
  <!--<property name="obj.dir" value="S:/obj" />-->
  <property name="dst.dir" value="D:/ant/bin/${os.arch}" />
  <property name="obj.dir" value="${dst.dir}" />
  <property name="dirname" value="com/lgc/gocad/lmktree" />
  <property name="libname" value="lgc_gocad_lmktree" />

  <!-- Common version information -->
  <property name="lgc" value="Landmark Graphics Corporation" />
  <property name="jgocad.version.version" value="0,8,%today%,0" />
  <property name="jgocad.version.copyright" value="${lgc} (c) 1999-2001" />
  <property name="jgocad.version.companyname" value="${lgc}" />
  <property name="jgocad.version.productname" value="DecisionSpace" />
  <property name="jgocad.version.productversion" value="1,0,%tomorrow%,0" />
  <property name="jgocad.version.specialbuild" value="Reno Hyphen" />

  <property name="lib.suffix" value="" allowoverrides="true" />
  <property name="lib.suffix" value="_g" if="debug" when="%{debug}==true" />
  <property name="lib.suffix" value="_n" if="numega" when="%{numega}==true"
/>

  <property name="dll.suffix" value="${lib.suffix}" />

  <property name="dll.extension" value=".so" allowoverrides="true" />
  <property name="dll.extension" value=".dll" os="Windows NT" />

  <!-- Lmktree's Target -->
  <target name="com.lgc.gocad.lmktree">
    <mkdir dir="${obj.dir}/${dirname}" />
	<dll name="lgc_gocad_lmktree${dll.suffix}"
	     dlldir="${obj.dir}"
	     flatten="false"
	     parallel="true"
	     objdir="${obj.dir}/${dirname}"
	     debug="${debug}"
		 ldexecutable="cl"
		 ccexecutable="cl">
	     <!--flatten="true"-->
	     <!--todir="S:/obj/lgc/gocad/lmktree"-->

	  <!-- All the C++ files to compile and link -->
	  <!--<fileset dir="${src.dir}/${dirname}">-->
	  <fileset dir="P:/src/${dirname}">
		<patternset>
		  <include name="**/*.cpp" />
		</patternset>
	  </fileset>

	  <!-- DLL versioning -->
	  <!--ref="jgocad.versioninfo"-->
	  <!--parentref="jgocad.versioninfo."-->
      <dllversioninfo
		version="0,8,%today%,0"
		description="Java gOcad Core - gOcad eXtension Library"
		copyright="Landmark Graphics Corporation (c) 1999-2001"
		companyname="Landmark Graphics Corporation"
		productname="DecisionSpace"
		internalname="com_lgc_gocad_lmktree"
		originalfilename="lgc_gocad_lmktree.dll"
		productversion="1.0.%tomorrow%.0"
		specialbuild="Reno Hyphen"
		comments="Designed by PL. Maintained by DD. Contributions by
LD, MG, CC, JD"
	  />
	  <!--
		Designed by PL. Maintained by DD.
		Contributions by LD, MG, CC, JD
	  </versioninfo>
	  -->

	  <!-- Includes for compilation -->
	  <include location="P:/src/com/lgc/gocad" />
	  <include location="P:/src/lgc/gocad/src" />

	  <!-- Defines for compilation -->
	  <define name="_DEBUG"     if="debug" />
	  <define name="NDEBUG" unless="debug" />
	  <define>WIN32 UNICODE _WINDOWS __STDC__ LGC_SERVER</define>
	  <define name="_WIN32_WINNT" value="0x0400" />
	  <define prefix="_LmkTree_" suffix="_make">
	    geobase lines surfaces volumes persistence gapi
	  </define>

	  <!-- Compiler options -->
	  <ccoption>nologo c W3 GX GR Zi Op FD YX</ccoption>
	  <ccoption     if="debug">Gm Od MDd</ccoption>
	  <ccoption unless="debug">GB O2 MD </ccoption>

	  <!-- Linker options -->
	  <ldoption name="nologo" />
	  <ldoption     if="debug">LDd MDd</ldoption>
	  <ldoption unless="debug">LD  MD </ldoption>

	  <!-- Insert the object list here for link command -->
	  <objects />

	  <ldoption name="link" />
	  <ldoption name="DEBUG" if="debug" when="%{debug}==true" />
	  <ldoption name="fixed" value="no" />
	  <ldoption name="incremental" value="no" />
	  <ldoption name="warn" value="0" />
	  <ldoption name="version" value="1.59" />

	  <!-- Libraries to link against -->
	  <libpath location="${bin.dir}" />
	  <library prefix="lgc_gocad_" suffix="${lib.suffix}"
extension=".lib" >
		utils  math  geobase lines surfaces volumes
		tgobjs appli filters ascii archive  gapi
	  </library>
	</dll>
  </target>
</project>

Mime
View raw message