Ant宏定义编译任务

发布于 2024-10-14 13:39:32 字数 2163 浏览 2 评论 0原文

我正在构建一个编译器(和语言),通常会这样调用:

java -jar nc.jar \
    -p some/referenced/package.nc \ 
    -p framework.nc \ 
    source1.ns source2.ns sourceN.ns \ 
    -o output/package.nc

我想在我的 ANT 构建文件中包含一个任务,该任务调用编译器来编译标准库和所有测试用例,但指定每个单独的编译器调用因为 任务很痛苦:

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

我想创建某种 ANT 任务,可以将其简化为:

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

为此,我尝试了 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>

我尝试了几种变体上面的内容,但每个错误都会出现类似以下内容: /home/jwarner/code/nlang/nc/build.xml:55:java 不支持嵌套的“文件集”元素。

有没有办法在不扩展 ANT 本身的情况下做到这一点?或者,向我的编译器添加 ant 任务是否相当容易?我对最终 任务的语法并不是非常挑剔。

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 \ 
    source1.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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难得心□动 2024-10-21 13:39:32

我过去也遇到过类似的问题,开箱即用的 Ant 任务并没有完全按照我想要的方式执行。我发现编写自己的 Ant 任务非常容易。

该文档很简洁,但很好地解释了您需要做什么。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文