-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.xml
114 lines (95 loc) · 3.46 KB
/
build.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<project name="MyProject" default="all" basedir=".">
<dirname property="basedir" file="${ant.file}"/>
<!-- Global Libraries -->
<path id="library.antlr-4.2-complete">
<pathelement location="/usr/local/lib/antlr-4.2-complete.jar"/>
</path>
<path id="library.st-4.0.7">
<pathelement location="/usr/local/lib/ST-4.0.7.jar"/>
</path>
<!-- set global properties for this build -->
<property name="srcroot" location="${basedir}/src"/>
<property name="src" location="${basedir}/src/java"/>
<property name="grammars" location="${basedir}/src/grammar"/>
<property name="gen" location="${basedir}/src/gen"/>
<property name="build" location="${basedir}/out/production/tool"/> <!-- mimic what intellij uses -->
<path id="classpath">
<path refid="library.antlr-4.2-complete"/>
<path refid="library.st-4.0.7"/>
</path>
<target name="init">
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="antlr4-init">
<!-- ANTLR generates X.java or XParser.java or XLexer.java from X.g4
so we use a touch file to indicate when we've just build all
grammars. File is wiped out during clean target.
-->
<property name="antlr4.touch" value="${build}/antlr4.touch" />
</target>
<macrodef name="antlr4">
<attribute name="file"/>
<attribute name="dest"/>
<element name="args" optional="true"/>
<sequential>
<echo message="Run antlr 4 on @{file}"/>
<local name="package"/>
<local name="path.antlr4.local"/>
<local name="sources.antlr4.local"/>
<property name="package" value="mantra"/>
<java classname="org.antlr.v4.Tool" fork="true" failonerror="true">
<arg value="-o"/>
<arg value="${gen}/${package}"/>
<arg value="-package"/>
<arg value="${package}"/>
<args/>
<arg line="@{file}"/>
<classpath>
<path refid="classpath"/>
<pathelement location="${java.class.path}"/>
</classpath>
</java>
</sequential>
</macrodef>
<target name="chk-parsers-up-to-date" depends="antlr4-init">
<!-- if any .g4 or .tokens file is newer than the touch file (i.e.,
last time we built the parsers, indicate we need a rebuild
-->
<uptodate property="parsers-up-to-date" targetfile="${antlr4.touch}" >
<srcfiles dir="${grammars}">
<include name="**/*.g4"/>
<include name="**/*.tokens"/> <!-- we might create a .tokens file by hand -->
</srcfiles>
</uptodate>
</target>
<!-- how to run antlr4 on a dir of grammars -->
<target name="antlr4" depends="init, chk-parsers-up-to-date" unless="parsers-up-to-date">
<echo message="Generating Parsers for ANTLR 4 grammars"/>
<antlr4 file="${grammars}/mantra/Mantra.g4" dest="${build}">
<args>
<arg value="-listener"/>
</args>
</antlr4>
<touch file="${antlr4.touch}" mkdirs="true"/>
</target>
<target name="compile" depends="init, antlr4" description="Compile module tool; production classes">
<javac destdir="${build}" includeantruntime="false" debug="true">
<classpath refid="classpath"/>
<src path="${src}"/>
<src path="${gen}"/>
</javac>
<copy todir="${build}"> <!-- copy any non-java resource files to build dir -->
<fileset dir="${basedir}/resources">
<exclude name="**/?*.java"/>
<type type="file"/>
</fileset>
</copy>
</target>
<target name="clean" description="clean up" >
<delete dir="${build}"/>
<delete dir="${gen}"/>
</target>
<target name="all" depends="init, antlr4, compile" description="do everything" >
</target>
</project>