Reputation:
How can I call a target based on the command line argument? For example, I want to have
ant -Dbits=32 test
call <target name="test-32">
and
ant -Dbits=64 test
call <target name="test-64">
I tried this:
<target name="test-32">
...
</target>
<target name="test-64">
...
</target>
<target name="test" depends="test-${bits}">
But when I run the script with:
ant -Dbits=32 test
I get the following error:
Target "test-${bits}" does not exist in the project
Upvotes: 0
Views: 275
Reputation: 122414
You could try a trick like
<target name="test.type">
<property name="run.test${bits}" value="yes"/>
</target>
<target name="test32" if="run.test32">
...
</target>
<target name="test64" if="run.test64">
...
</target>
<target name="test" depends="test.type, test32, test64"/>
Alternatively, if, as you suggest in the comments, the difference between the 32 and 64 bit cases is just a single property value (a compiler flag) then you could set that property with <condition>
, for example
<target name="test">
<!-- value="..." is the value to use if the condition is true,
else="..." is the value to use if the condition is false -->
<condition property="compiler.arch" value="x86_64" else="i386">
<equals arg1="${bits}" args2="64" />
</condition>
<!-- use ${compiler.arch} here -->
</target>
Upvotes: 2
Reputation: 6411
Try the following:
<target name="test">
<antcall target="test-${bits}"/>
</target>
Upvotes: -1