开发者

Trouble Executing Bash.exe From an Ant Buildfile in Eclipse

I've created an Ant buildfile and an associated Ant builder in my Eclipse project. The builder is executing correctly but I can't seem to pass the correct information to bash. I'm running cygwin on an XP Professional SP3 machine. I know the command works and have verified it from a cygwin terminal. I created a custom builder earlier with this command so I also know that it works from Eclipse.

Here is my build xml:

   <?xml version="1.0" encoding="UTF-8"?>
    <project name="BlazeLibrary.makejar" defaul开发者_C百科t="makejar" basedir=".">
    <property name="bash" location="e:\cygwin\bin\bash.exe" />
    <property name="workingdir" location="e:\cygwin\bin" />
    <property name="cmdline" value="--login -c \&quot;cd /cygdrive/c/dev/projects/droid/NDKTestApp &amp;&amp; /cygdrive/c/dev/tools/droid/android-ndk-r4b/ndk-build&quot;" />
    <target name="nativeBuild" description="Build the native binaries using the Android NDK">
        <exec dir="${workingdir}" executable="${bash}">
            <arg value="${cmdline}" />
        </exec>
    </target>
    </project>

The task runs fine but the output I indicates that the command line parameters are incorrect. Even though they are listed exactly as they should be (and verified by running from cmd prompt as well as the custom builder mentioned previously).

Here is the relevant part of the error message (the rest just vomits the help and is of no relevancy for this question):

nativeBuild:
[exec] /usr/bin/bash: --login -c "cd /cygdrive/c/dev/projects/droid/NDKTestApp && /cygdrive/c/dev/tools/droid/android-ndk-r4b/ndk-build": invalid option
[exec] Usage:   /usr/bin/bash [GNU long option] [option] ... blah blah blah

I'll be the first to admit that I am an Ant noob so I'm probably missing something very obvious. I've searched but nothing really jumps out at me and the task seems to run correctly, just something funky about the command line. Thanks for any help in advance.


The immediate problem is that the ${cmdline} property is being passed to bash as a single argument - hence the very long 'invalid option'.

You could pass the command as an arg line instead:

<exec dir="${workingdir}" executable="${bash}">
    <arg line="${cmdline}" />
</exec>

Or perhaps break it up into separate values. Note that you don't need the quots around the -c arg in that case:

<property name="cmdline" value="cd /cygdrive/ ..etc.. ndk-build" />

 <exec dir="${workingdir}" executable="${bash}">
     <arg value="--login" />
     <arg value="-c" />
     <arg value="${cmdline}" />
 </exec>

More here.


You can still use the format in your initial post, just change your quotes around a bit, like this:

<!-- These properties hold the location of the android-ndk, for us to build our antive libs -->
<property name="bash" location="c:\cygwin\bin\bash.exe" />
<property name="workingdir" location="c:\cygwin\bin" />
<property name="cmdline" value="--login -c 'cd /path/to/project/files;/path/to/ndk_build/ndk-build;exit'" />
<target name="NDKBUILD" description="Build the native binaries using the Android NDK">
     <exec dir="${workingdir}" executable="${bash}">
        <arg line="${cmdline}" />
     </exec>
 </target>

Note the usage of " " to denote the XML string, but ' ' to denote command lines passed to cygwin/bash.

Also, when using this script in my android builder (heavily customised ant script with extensive source preprocessing) I ran into issues where the ant build was "Already In Progress".

To this end, I added an exit command to the end of the bash script, so the cygin bash process is always closed after being called.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜