我想简化这个:
<target name="build">
<parallel>
<antcall target="build-A" />
<antcall target="build-B" />
<antcall target="build-C" />
</parallel>
</target>
<target name="build-A">
<exec executable="tool.exe" dir="projects/A">
<arg value="input.xml" />
</exec>
</target>
其中build-B
和build-C
执行相同的操作(分别仅在dirs B
和C
中),类似于此:
<dirset id="projects" dir="." >
<include name="projects/*" />
</dirset>
<apply executable="tool.exe" parallel="true">
<arg value="input.xml" />
<dirset refid="projects" />
</apply>
这不起作用,因为apply
将执行以下操作之一:
如果parallel
设置为true
,
tool.exe input.xml projects/A projects/B projects/C
或parallel
设置为false
,
tool.exe projects/A/input.xml
...waits for tool.exe to complete...
tool.exe projects/B/input.xml
...etc
即使这是不正确的,因为tool.exe
期望在 projects/A
目录中运行。
有没有办法并行化这个,以便我得到的输出相当于:
cd project/A
tool.exe input.xml
cd ../B
tool.exe input.xml
cd ../C
tool.exe input.xml
但并行?
答案 0 :(得分:4)
我会使用ant-contrib的for task来执行此操作。
<for param="dir" parallel="true">
<dirset id="projects" dir="." >
<include name="projects/*" />
</dirset>
<sequential>
<exec executable="tool.exe" dir="@{dir}">
<arg value="input.xml" />
</exec>
</sequential>
</for>