Search code examples
javaeclipseantcygwin

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" default="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.


Solution

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