> -----Original Message----- > From: Peter Reilly [mailto:[email protected]] > Sent: 05 May 2010 14:46 > To: Ant Users List > Subject: Re: Better alternative than using foreach, for and > if/then/else? > > You need to use ant 1.8 and the <local> task. > <local> declares that a property is local to the current scope, > as defined by the enclosing <target> or <seqential> > > see: http://ant.apache.org/manual/CoreTasks/local.html > > <for list="${kernel.currver.variants}" param="kernel.variant" > delimiter=" " trim="true"> > <sequential> > <local name="dir.kernel.build"/> > <local name="dir.module.build"/> > <if> > <equals arg1="@{kernel.variant}" arg2='""' /> > <then> > <property name="dir.kernel.build" > location="/lib/modules/${kernel.version}/build" /> > <property name="dir.module.build" > location="${dir.build}/output/${kernel.version}" /> > </then> > <else> > <property name="dir.kernel.build" > location="/lib/modules/${kernel.versi...@{kernel.variant}/build" /> > <property name="dir.module.build" > location="${dir.build}/output/${kernel.versi...@{kernel.variant}" /> > </else> > > ... > > > Peter
Was aware of the local task, but haven't tried switching to Ant 1.8 to be able to use it just yet. My main concerns at the moment are the following: 1) Is for/foreach the only real option for what I'm attempting to accomplish here in building multiple end targets based on the contents of properties? Is looping over the property contents using those two tasks the only way in Ant, or is there another way to allow Ant to see a variable list of sub-targets to be run depending on property contents? In make I had rule patterns and eval to be able to expand to give a list of targets, in Ant I have ??? I spotted a mail from yesterday to another person using for/foreach suggesting using xslt to generate a build file and execute it, "A trick which I have learned and used myself is to generate on the fly a small build file using xslt and invoke it using <ant/>". I've yet to look at this closely. 2) Is there a better way to pass an empty string in and append it to the properties above, rather than requiring an if/then/else construct to set properties? Right now, if I don't use the if/then/else, the directory path that dif.kernel.build gets resolved to is /lib/modules/2.6.18-194.el5""/build, which is clearly wrong. -- Regards, Darragh Bailey Systems Software Engineer Hewlett Packard Galway Ltd. Postal Address: Hewlett Packard Galway Limited, Ballybrit Business Park, Galway Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's Quay Dublin 2 Registered Number: 361933 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
