• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<project name="Antlr3JavaScriptRuntime" basedir=".." default="build">
2<description>
3Build procedure and task automation for the ANTLR JavaScript target.
4</description>
5
6    <property name="build.dir" value="${basedir}/build" />
7    <property name="out.dir" value="${build.dir}/out" />
8    <property name="lib.dir" value="${basedir}/lib" />
9    <property name="doc.dir" value="${basedir}/doc" />
10    <property name="test.dir" value="${basedir}/tests" />
11    <property name="src.dir" value="${basedir}/src" />
12    <property name="third.dir" value="${basedir}/third" />
13    <property file="${build.dir}/antlr3.properties" />
14
15    <taskdef file="${third.dir}/antcontrib.properties" classpath="${third.dir}/ant-contrib-1.0b3.jar" />
16
17    <!-- ******* -->
18    <!-- LIBRARY -->
19    <!-- ******* -->
20
21    <target name="build" depends="-init" description="Build ANTLR JavaScript runtime library.">
22        <antcall target="-make-debug" />
23        <antcall target="-make-min" />
24        <!--<antcall target="-make-docs" />-->
25        <antcall target="-del-build" />
26    </target>
27
28    <!-- Make uncompressed JS runtime files -->
29    <target name="-make-debug">
30        <!-- no file name suffix for debug files -->
31        <property name="debugormin" value="" />
32        <antcall target="-make-packages" inheritall="true" />
33    </target>
34
35    <!-- Make compressed JS files -->
36    <target name="-make-min">
37        <property name="debugormin" value="-min" />
38        <antcall target="-make-packages" inheritall="true" />
39    </target>
40
41    <!-- Make each package defined in atlr3.list -->
42    <target name="-make-packages">
43        <property name="pkg" value="" />
44        <foreach list="${antlr3.list}" target="-make-package" param="pkg" inheritall="true" />
45    </target>
46
47    <!-- Create a package -->
48    <target name="-make-package">
49        <var name="package" value="${pkg}" />
50        <property name="dest" value="${lib.dir}/antlr3-${package}${debugormin}.js" />
51        <propertycopy property="list" from="antlr3.${package}.list" override="true" />
52        <propertyregex property="list" input="${list}" regexp=" +" replace="" override="true" />
53
54        <concat destfile="${dest}">
55            <filelist dir="${src.dir}" files="${list}" />
56        </concat>
57
58        <if>
59            <equals arg1="${debugormin}" arg2="-min" />
60            <then>
61                <antcall target="-compress" inheritall="true" />
62            </then>
63        </if>
64
65        <antcall target="-add-license" inheritall="true" />
66    </target>
67
68    <!-- Compress JavaScript using Closure Compiler -->
69    <target name="-compress">
70        <java fork="true" jar="${third.dir}/compiler.jar">
71            <arg line="--js" />
72            <arg value="${dest}" />
73            <arg line="--js_output_file" />
74            <arg line="${dest}.tmp" />
75        </java>
76        <move file="${dest}.tmp" tofile="${dest}" />
77    </target>
78
79    <!-- insert required legaleze at the top of a file -->
80    <target name="-add-license">
81        <property name="tmp-file" value="${dest}.tmp" />
82        <move file="${dest}" tofile="${tmp-file}" />
83        <concat destfile="${dest}">
84            <header file="${build.dir}/${antlr3.license}" />
85            <fileset file="${tmp-file}" />
86        </concat>
87        <delete file="${tmp-file}" />
88    </target>
89
90    <!-- delete build directory -->
91    <target name="-del-build">
92        <delete dir="${out.dir}" />
93    </target>
94
95    <!-- ***** -->
96    <!-- TESTS -->
97    <!-- ***** -->
98
99    <target name="compile-tests" depends="build" description="Compile all test grammars.">
100        <foreach target="-compile-test-class" param="testdirectory" inheritall="true">
101            <path>
102                <dirset dir="${test.dir}" includes="*" excludes="README" />
103            </path>
104        </foreach>
105    </target>
106
107    <target name="-compile-test-class" >
108        <foreach target="-compile-single-test" param="grammar" inheritall="true">
109            <path>
110                <fileset dir="${testdirectory}" includes="*.g" excludes="*__.g" />
111            </path>
112        </foreach>
113    </target>
114
115    <target name="-compile-single-test">
116        <!-- turn on antlr tracing if necessary -->
117        <var name="g" value="${grammar}" />
118        <loadfile property="g-contents" srcfile="${g}" />
119        <var name="opt" value="" />
120        <property name="trace-key" value="// @@ANTLR Tool Options@@: -trace" />
121        <if>
122            <contains string="${g-contents}" substring="${trace-key}" />
123            <then>
124                <var name="opt" value="-trace" />
125            </then>
126        </if>
127
128        <java dir="${testdirectory}" jar="${antlr3.tool}" fork="yes">
129            <arg line="${opt}" />
130            <arg line="${g}" />
131        </java>
132    </target>
133
134    <!-- **** -->
135    <!-- DOCS -->
136    <!-- **** -->
137
138    <target name="make-docs" description="Generate jsdoc API documentation." depends="-init">
139        <property name="jsdoc.dir" value="${third.dir}/jsdoc-toolkit" />
140        <property name="docs.dir" value="${lib.dir}/docs" />
141
142        <mkdir dir="${docs.dir}" />
143        <java jar="${jsdoc.dir}/jsrun.jar" fork="yes">
144            <arg line="${jsdoc.dir}/app/run.js ${src.dir} -r=10 -t=${jsdoc.dir}/templates/jsdoc -d=${docs.dir}" />
145        </java>
146    </target>
147
148    <target name="-init">
149        <!-- clear build dir -->
150        <delete dir="${out.dir}" quiet="true" />
151        <mkdir dir="${out.dir}" />
152    </target>
153</project>
154