如何使用Ant有条件地执行不同平台的批处理脚本?
我试图使用Ant构建脚本来构建一个已经有nmake(VisualStudio)构建脚本的项目。我希望Ant重用现有的脚本,而不是重做整个构建脚本 因此,我有类似的东西,适用于Windows Mobile 6 ARMV4I版本:如何使用Ant有条件地执行不同平台的批处理脚本?,ant,Ant,我试图使用Ant构建脚本来构建一个已经有nmake(VisualStudio)构建脚本的项目。我希望Ant重用现有的脚本,而不是重做整个构建脚本 因此,我有类似的东西,适用于Windows Mobile 6 ARMV4I版本: <project ...> <target name="-BUILD.XML-COMPILE" depends="-init, -pre-compile"> <exec executable="cmd"> <
<project ...>
<target name="-BUILD.XML-COMPILE" depends="-init, -pre-compile">
<exec executable="cmd">
<arg value="/c"/>
<arg line='"${g.path.project}\build-wm6-armv4i.bat"'/>
</exec>
<antcall target="-post-compile" inheritall="true" inheritrefs="true" />
</target>
</project>
但我也希望它能适用于其他平台,如Win32 x86和Windows CE6 x86
如何让Ant脚本区分它应该执行哪个批处理文件来执行构建?该条件可用于根据操作系统和硬件体系结构设置属性。可以使用if
和除非属性有条件地执行目标
<?xml version="1.0" encoding="UTF-8"?>
<project name="build" basedir="." default="BUILD.XML-COMPILE">
<condition property="Win32-x86">
<and>
<os family="windows" />
<or>
<os arch="i386" />
<os arch="x86" />
</or>
</and>
</condition>
<condition property="Win-ARMv4">
<os family="windows" arch="armv4" />
</condition>
<target name="-BUILD.XML-COMPILE_Win-ARMv4" if="Win-ARMv4"
depends="-init, -pre-compile">
<exec executable="cmd">
<arg value="/c"/>
<arg line='"${g.path.project}\build-wm6-armv4i.bat"'/>
</exec>
<antcall target="-post-compile" inheritall="true" inheritrefs="true" />
</target>
<target name="-BUILD.XML-COMPILE_Win32-x86" if="Win32-x86"
depends="-init, -pre-compile">
<exec executable="cmd">
<arg value="/c"/>
<arg line='"${g.path.project}\build-win32-x86.bat"'/>
</exec>
<antcall target="-post-compile" inheritall="true" inheritrefs="true" />
</target>
<!-- Execute the correct target automatically based on current platform. -->
<target name="BUILD.XML-COMPILE"
depends="-BUILD.XML-COMPILE_Win-ARMv4,
-BUILD.XML-COMPILE_Win32-x86" />
</project>
该条件可用于根据操作系统和硬件体系结构设置属性。可以使用if
和除非属性有条件地执行目标
<?xml version="1.0" encoding="UTF-8"?>
<project name="build" basedir="." default="BUILD.XML-COMPILE">
<condition property="Win32-x86">
<and>
<os family="windows" />
<or>
<os arch="i386" />
<os arch="x86" />
</or>
</and>
</condition>
<condition property="Win-ARMv4">
<os family="windows" arch="armv4" />
</condition>
<target name="-BUILD.XML-COMPILE_Win-ARMv4" if="Win-ARMv4"
depends="-init, -pre-compile">
<exec executable="cmd">
<arg value="/c"/>
<arg line='"${g.path.project}\build-wm6-armv4i.bat"'/>
</exec>
<antcall target="-post-compile" inheritall="true" inheritrefs="true" />
</target>
<target name="-BUILD.XML-COMPILE_Win32-x86" if="Win32-x86"
depends="-init, -pre-compile">
<exec executable="cmd">
<arg value="/c"/>
<arg line='"${g.path.project}\build-win32-x86.bat"'/>
</exec>
<antcall target="-post-compile" inheritall="true" inheritrefs="true" />
</target>
<!-- Execute the correct target automatically based on current platform. -->
<target name="BUILD.XML-COMPILE"
depends="-BUILD.XML-COMPILE_Win-ARMv4,
-BUILD.XML-COMPILE_Win32-x86" />
</project>
是否希望生成检测其运行的环境,并根据该检测选择nmake生成脚本,还是只想将nmake文件名作为参数传入?如果指定了不同的目标,我想调用不同的批处理文件。是否希望生成检测其运行的环境,并根据该结果选择nmake生成脚本,还是只想将nmake文件名作为参数传入?如果指定了不同的目标,我想调用不同的批处理文件。