开发者

Ant macrodef compilation task

开发者 https://www.devze.com 2023-02-06 17:33 出处:网络
I have a compiler (and language) I am building that is normally invoked thus: java -jar nc.jar \\ -p some/referenced/package.nc \\

I have a compiler (and language) I am building that is normally invoked thus:

java -jar nc.jar \
    -p some/referenced/package.nc \ 
    -p framework.nc \ 
    s开发者_JS百科ource1.ns source2.ns sourceN.ns \ 
    -o output/package.nc

I'd like to include a task in my ANT build file that invokes the compiler to compile the standard library and all test cases, but specifying each separate compiler invocation as a <java> task is painful:

<target name="framework" depends="compiler" description="Build the n framework">
    <!-- More compile steps -->
    <java jar="nc.jar" fork="true">
        <arg value="-p"/>
        <arg path="../nframework/build/n.core.nc"/>
        <arg path="../nframework/n/debug/DebugPrint.ns"/>
        <arg path="../nframework/n/debug/Trace.ns"/>
        <arg value="-o"/>
        <arg path="../nframework/build/n.debug.nc"/>
    </java>
    <!-- More compile steps -->
</target>

I would like to create an ANT task of some sort that can simplify this into something like:

<target name="framework" depends="compiler" description="Build the n framework">
    <!-- More compile steps -->
    <nc output="../nframework/build/n.debug.nc">
        <link-package path="../nframework/build/n.core.nc"/>
        <src>
            <fileset dir="../nframework/n/debug" includes="**/*.ns"/>
        </src>
    </nc>
    <!-- More compile steps -->
</target>

To this end, I tried macrodef:

<macrodef name="nc">
    <attribute name="output"/>
    <element name="link-package"/>
    <element name="src"/>
    <sequential>
        <java jar="nc.jar" fork="true">
            <arg value="-p"/>
            <!-- This doesn't do what I want -->
            <link-package/>
            <!-- Neither does this -->
            <src/>
            <arg value="-o"/>
            <arg path="@{output}"/>
        </java>
    </sequential>
</macrodef>

I've tried several variations on the above, but each errors out with something like: /home/jwarner/code/nlang/nc/build.xml:55: java doesn't support nested "fileset" element.

Is there a way to do this without extending ANT itself? Alternatively, would it be fairly easy to add an ant task to my compiler? I'm not terribly picky about the syntax of the final <nc> task.


I have had a similar problem in the past where the out-of-the-box Ant tasks didn't quite do what I wanted them to do. I found that it was very easy to write my own Ant task.

The documentation is concise but does a good job of explaining what you need to do.

http://ant.apache.org/manual/develop.html#writingowntask

0

精彩评论

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