1

Antビルドスクリプトを使用して、すでにnmake(Visual Studio)ビルドスクリプトが含まれているプロジェクトをビルドしようとしています。ビルドスクリプト全体をやり直すのではなく、Antに既存のスクリプトを再利用させたいと思います。

だから、私はWindows Mobile 6ARMV4Iビルドで動作するこのようなものを持っています:

<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>

ただし、Win32x86やWindowsCE6x86などの他のプラットフォームでも機能するようにしたいと思います。

ビルドを実行するために実行する必要があるバッチファイルをAntスクリプトで区別するにはどうすればよいですか?

4

1 に答える 1

1

この<os>条件は、オペレーティングシステムとハードウェアアーキテクチャに基づいてプロパティを設定するために使用できます。ターゲットは、ifおよびunless属性を使用して条件付きで実行できます。

<?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>

スペースを含むファイルパスがスクリプトを壊さないように、バッチファイルへのパスは一重引用符と二重引用符の両方です。このスクリプトはWindowsMo​​bile6 ARMV4Iでテストしていないため、以下のAntターゲットを使用して名前を確認することをお勧めします。

<target name="echo-os-name-arch-version">
  <echo message="OS Name is:         ${os.name}" />
  <echo message="OS Architecture is: ${os.arch}" />
  <echo message="OS Version is:      ${os.version}" />
</target> 

関連するスタックオーバーフローの質問:

于 2012-09-07T21:59:00.730 に答える