-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-macros.xml
100 lines (84 loc) · 3.59 KB
/
build-macros.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?xml version="1.0" encoding="utf-8" ?>
<!--
! Excerpted from "Language Implementation Patterns",
! published by The Pragmatic Bookshelf.
! Copyrights apply to this code. It may not be used to create training material,
! courses, books, articles, and the like. Contact us if you are in doubt.
! We make no guarantees that this code is fit for any purpose.
! Visit http://www.pragmaticprogrammer.com/titles/tpdsl for more book information.
-->
<project name="build-macros" basedir=".">
<!-- Looks weird but correct, as it runs from our subdirs, this allows the ant build to function from every subdirectory -->
<path id="libs.all">
<fileset dir="../../" includes="*.jar" />
</path>
<!-- Creates output directories for classes -->
<macrodef name="init">
<sequential>
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
</sequential>
</macrodef>
<!-- Clean macro we use for all sub-projects, deletes build dir. -->
<macrodef name="clean">
<sequential>
<delete dir="${build.dir}" failonerror="false" includes="*.class" />
</sequential>
</macrodef>
<macrodef name="generate">
<sequential>
<pathconvert pathsep=" " dirsep="/" property="grammars">
<path id="test">
<fileset dir="${src.dir}" includes="*.g" />
</path>
</pathconvert>
<echo message="Grammars: ${grammars}" />
<java classname="org.antlr.Tool" classpathref="libs.all" fork="true">
<arg line="-o ${src.dir} ${grammars}" />
<!--
<arg value="-o" />
<arg value="${src.dir}" />
<arg value="${grammars}" />
-->
</java>
</sequential>
</macrodef>
<!-- Compile macro we use for all sub-projects, it may optionally have another classpathrefid parameter if libraries need to be changed for a project -->
<macrodef name="compile">
<attribute name="cprefid" default="libs.all" />
<sequential>
<!-- The libraries, for convenience we just import them into one path, the weird ../ assures we can run it from any directory where there is a build.xml -->
<javac destdir="${classes.dir}" target="1.5">
<classpath refid="@{cprefid}" />
<src location="${src.dir}" />
</javac>
</sequential>
</macrodef>
<!-- Macro to run a class, in our case it runs a test. Default class that runs is 'Test', can be changed. -->
<macrodef name="run">
<attribute name="class" default="Test" />
<attribute name="argline" default="" />
<attribute name="cprefid" default="libs.all" />
<sequential>
<!-- The libraries, for convenience we just import them into one path, the weird ../ assures we can run it from any directory where there is a build.xml -->
<java classname="@{class}" fork="true">
<classpath refid="@{cprefid}" />
<classpath location="${classes.dir}" />
<arg line="@{argline}" />
</java>
</sequential>
</macrodef>
<macrodef name="run-single">
<attribute name="class" default="${class}" />
<attribute name="argline" default="${file}" />
<attribute name="cprefid" default="libs.all" />
<sequential>
<!-- The libraries, for convenience we just import them into one path, the weird ../ assures we can run it from any directory where there is a build.xml -->
<java classname="@{class}" fork="true">
<classpath refid="@{cprefid}" />
<classpath location="${classes.dir}" />
<arg line="@{argline}" />
</java>
</sequential>
</macrodef>
</project>