aboutsummaryrefslogtreecommitdiff
path: root/antlr-3.4/runtime/JavaScript/build/build.xml
blob: 43223a71b191e63b1223d000c29ac40ba80f8d04 (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<project name="Antlr3JavaScriptRuntime" basedir=".." default="build">
<description>
Build procedure and task automation for the ANTLR JavaScript target.
</description>

    <property name="build.dir" value="${basedir}/build" />
    <property name="out.dir" value="${build.dir}/out" />
    <property name="lib.dir" value="${basedir}/lib" />
    <property name="doc.dir" value="${basedir}/doc" />
    <property name="test.dir" value="${basedir}/tests" />
    <property name="src.dir" value="${basedir}/src" />
    <property name="third.dir" value="${basedir}/third" />
    <property file="${build.dir}/antlr3.properties" />

    <taskdef file="${third.dir}/antcontrib.properties" classpath="${third.dir}/ant-contrib-1.0b3.jar" />

    <!-- ******* -->
    <!-- LIBRARY -->
    <!-- ******* -->

    <target name="build" depends="-init" description="Build ANTLR JavaScript runtime library.">
        <antcall target="-make-debug" />
        <antcall target="-make-min" />
        <!--<antcall target="-make-docs" />-->
        <antcall target="-del-build" />
    </target>

    <!-- Make uncompressed JS runtime files -->
    <target name="-make-debug">
        <!-- no file name suffix for debug files -->
        <property name="debugormin" value="" />
        <antcall target="-make-packages" inheritall="true" />
    </target>

    <!-- Make compressed JS files -->
    <target name="-make-min">
        <property name="debugormin" value="-min" />
        <antcall target="-make-packages" inheritall="true" />
    </target>

    <!-- Make each package defined in atlr3.list -->
    <target name="-make-packages">
        <property name="pkg" value="" />
        <foreach list="${antlr3.list}" target="-make-package" param="pkg" inheritall="true" />
    </target>

    <!-- Create a package -->
    <target name="-make-package">
        <var name="package" value="${pkg}" />
        <property name="dest" value="${lib.dir}/antlr3-${package}${debugormin}.js" />
        <propertycopy property="list" from="antlr3.${package}.list" override="true" />
        <propertyregex property="list" input="${list}" regexp=" +" replace="" override="true" />

        <concat destfile="${dest}">
            <filelist dir="${src.dir}" files="${list}" />
        </concat>

        <if>
            <equals arg1="${debugormin}" arg2="-min" />
            <then>
                <antcall target="-compress" inheritall="true" />
            </then>
        </if>

        <antcall target="-add-license" inheritall="true" />
    </target>

    <!-- Compress JavaScript using Closure Compiler -->
    <target name="-compress">
        <java fork="true" jar="${third.dir}/compiler.jar">
            <arg line="--js" />
            <arg value="${dest}" />
            <arg line="--js_output_file" />
            <arg line="${dest}.tmp" />
        </java>
        <move file="${dest}.tmp" tofile="${dest}" />
    </target>

    <!-- insert required legaleze at the top of a file -->
    <target name="-add-license">
        <property name="tmp-file" value="${dest}.tmp" />
        <move file="${dest}" tofile="${tmp-file}" />
        <concat destfile="${dest}">
            <header file="${build.dir}/${antlr3.license}" />
            <fileset file="${tmp-file}" />
        </concat>
        <delete file="${tmp-file}" />
    </target>

    <!-- delete build directory -->
    <target name="-del-build">
        <delete dir="${out.dir}" />
    </target>

    <!-- ***** -->
    <!-- TESTS -->
    <!-- ***** -->

    <target name="compile-tests" depends="build" description="Compile all test grammars.">
        <foreach target="-compile-test-class" param="testdirectory" inheritall="true">
            <path>
                <dirset dir="${test.dir}" includes="*" excludes="README" />
            </path>
        </foreach>
    </target>

    <target name="-compile-test-class" >
        <foreach target="-compile-single-test" param="grammar" inheritall="true">
            <path>
                <fileset dir="${testdirectory}" includes="*.g" excludes="*__.g" />
            </path>
        </foreach>
    </target>

    <target name="-compile-single-test">
        <!-- turn on antlr tracing if necessary -->
        <var name="g" value="${grammar}" />
        <loadfile property="g-contents" srcfile="${g}" />
        <var name="opt" value="" />
        <property name="trace-key" value="// @@ANTLR Tool Options@@: -trace" />
        <if>
            <contains string="${g-contents}" substring="${trace-key}" />
            <then>
                <var name="opt" value="-trace" />
            </then>
        </if>

        <java dir="${testdirectory}" jar="${antlr3.tool}" fork="yes">
            <arg line="${opt}" />
            <arg line="${g}" />
        </java>
    </target>

    <!-- **** -->
    <!-- DOCS -->
    <!-- **** -->

    <target name="make-docs" description="Generate jsdoc API documentation." depends="-init">
        <property name="jsdoc.dir" value="${third.dir}/jsdoc-toolkit" />
        <property name="docs.dir" value="${lib.dir}/docs" />

        <mkdir dir="${docs.dir}" />
        <java jar="${jsdoc.dir}/jsrun.jar" fork="yes">
            <arg line="${jsdoc.dir}/app/run.js ${src.dir} -r=10 -t=${jsdoc.dir}/templates/jsdoc -d=${docs.dir}" />
        </java>
    </target>

    <target name="-init">
        <!-- clear build dir -->
        <delete dir="${out.dir}" quiet="true" />
        <mkdir dir="${out.dir}" />
    </target>
</project>