Files
kotlin-fork/build-tools/build.xml
T
2012-01-27 00:50:36 +02:00

339 lines
14 KiB
XML

<project name="build-tools" default="buildToolsJar">
<property name="tests-dir" location="${output}/ant-test/build-tools-test"/>
<property name="kotlin-home" location="${output}/ant-test/kotlin-home"/>
<property name="tests-jar" location="${tests-dir}/out.jar"/>
<property name="bootstrap-dir" location="${basedir}/bootstrap.compiler"/>
<property name="failonerror" value="true"/> <!-- Whether invoking compiled classes should file on error -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${basedir}/build-tools/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!-- Creates ${kotlin-home} and defines <kotlin> task -->
<macrodef name="define-kotlinc">
<sequential>
<if>
<not>
<available file="${kotlin-home}" type="dir"/>
</not>
<then>
<mkdir dir = "${kotlin-home}"/>
<if>
<available file="${bootstrap-dir}/kotlinc" type="dir"/>
<then>
<!-- Running in TeamCity environment -->
<copy todir="${kotlin-home}">
<fileset dir = "${bootstrap-dir}/kotlinc"/>
</copy>
</then>
<else>
<!-- Running in dev environment -->
<if>
<not>
<available file="${output}/${output.name}.zip"/>
</not>
<then>
<antcall target="dist"/>
</then>
</if>
<delete dir="${bootstrap-dir}" failonerror="true"/>
<mkdir dir="${bootstrap-dir}"/>
<copy file="${output}/${output.name}.zip" todir="${bootstrap-dir}"/>
<ant antfile="${basedir}/bootstrap.xml"/>
<define-kotlinc/> <!-- Recursive invocation, will use bootstrapped compiler this time -->
</else>
</if>
</then>
</if>
<taskdef resource = "org/jetbrains/jet/buildtools/ant/antlib.xml">
<classpath>
<fileset dir = "${kotlin-home}/lib" includes = "*.jar"/>
</classpath>
</taskdef>
</sequential>
</macrodef>
<!-- Deletes all previously compiled files -->
<macrodef name="cleanup">
<sequential>
<delete dir = "${tests-dir}" failonerror="true"/>
<delete file = "${tests-jar}" failonerror="true"/>
<mkdir dir = "${tests-dir}"/>
</sequential>
</macrodef>
<!-- Runs <kotlinc> create a *.class files in directory -->
<macrodef name="kotlinc-dir">
<attribute name="file" default=""/>
<attribute name="srcdir" default=""/>
<attribute name="includeRuntime" default="true"/>
<attribute name="stdlib" default="${kotlin-home}/lib/kotlin-runtime.jar"/>
<sequential>
<cleanup/>
<if>
<equals arg1="@{file}" arg2=""/>
<then>
<kotlinc srcdir = "@{srcdir}" destdir = "${tests-dir}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</then>
<else>
<kotlinc file = "@{file}" destdir = "${tests-dir}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</else>
</if>
</sequential>
</macrodef>
<!-- Runs <kotlinc> to create a *.class files in a jar -->
<macrodef name="kotlinc-jar">
<attribute name="file" default=""/>
<attribute name="srcdir" default=""/>
<attribute name="module" default=""/>
<attribute name="includeRuntime" default="true"/>
<attribute name="stdlib" default="${kotlin-home}/lib/kotlin-runtime.jar"/>
<sequential>
<cleanup/>
<if>
<not>
<equals arg1="@{file}" arg2=""/>
</not>
<then>
<kotlinc file = "@{file}" destjar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</then>
<elseif>
<not>
<equals arg1="@{srcdir}" arg2=""/>
</not>
<then>
<kotlinc srcdir = "@{srcdir}" destjar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</then>
</elseif>
<elseif>
<not>
<equals arg1="@{module}" arg2=""/>
</not>
<then>
<kotlinc module = "@{module}" destjar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</then>
</elseif>
<else>
<fail message="One of 'file', 'srcdir', or 'module' should be specified"/>
</else>
</if>
</sequential>
</macrodef>
<!-- Runs <java> for compiled classes and verifies the output correctness -->
<macrodef name="run-java">
<attribute name="out"/>
<attribute name="classname" default="namespace"/>
<attribute name="args" default=""/>
<attribute name="equals" default="true"/> <!-- Whether strict equality of output to @{out} required -->
<attribute name="run-jar" default="false"/> <!-- Whether to run compiled classes or a jar file -->
<sequential>
<var name = "java-out" unset = "true"/>
<if>
<istrue value="@{run-jar}"/>
<then>
<echo>Running [@{classname}], classpath = "${tests-jar}"</echo>
<java outputproperty = "java-out"
classname = "@{classname}"
failonerror = "${failonerror}">
<classpath>
<pathelement path = "${tests-jar}"/>
</classpath>
<arg line = "@{args}"/>
</java>
</then>
<else>
<echo>Running [@{classname}], classpath = "${tests-dir};${kotlin-home}/lib/kotlin-runtime.jar"</echo>
<java outputproperty = "java-out"
classname = "@{classname}"
failonerror = "${failonerror}">
<classpath>
<pathelement path = "${tests-dir}"/>
<fileset file = "${kotlin-home}/lib/kotlin-runtime.jar"/>
</classpath>
<arg line = "@{args}"/>
</java>
</else>
</if>
<if>
<or>
<equals arg1="${java-out}" arg2="@{out}"/>
<and>
<isfalse value="@{equals}"/>
<contains string="${java-out}" substring="@{out}"/>
</and>
</or>
<then>
<echo>${java-out}</echo>
</then>
<elseif>
<istrue value="${failonerror}"/>
<then>
<fail message="Test failed: '${java-out}' (received) != '@{out}' (expected), equals = [@{equals}]"/>
</then>
</elseif>
</if>
</sequential>
</macrodef>
<!-- Compiles "Hello.kt" as a single file and a folder, runs <java> and verifies the output -->
<macrodef name="hello-test">
<attribute name="root"/>
<attribute name="args" default=""/>
<attribute name="out"/>
<sequential>
<kotlinc-dir file = "@{root}/Hello.kt"/>
<run-java args = "@{args}" out = "@{out}"/>
<kotlinc-dir srcdir = "@{root}"/>
<run-java args = "@{args}" out = "@{out}"/>
<kotlinc-jar file = "@{root}/Hello.kt"/>
<run-java args = "@{args}" out = "@{out}" run-jar="true"/>
<kotlinc-jar srcdir = "@{root}"/>
<run-java args = "@{args}" out = "@{out}" run-jar="true"/>
</sequential>
</macrodef>
<!-- Runs all Hello tests -->
<macrodef name="hello-tests">
<sequential>
<hello-test root="${basedir}/build-tools/test/hello/1" out="Hello, world!"/>
<hello-test root="${basedir}/build-tools/test/hello/2" args="Kotlin-Developer" out="Hello, Kotlin-Developer!"/>
<hello-test root="${basedir}/build-tools/test/hello/3" args="Mickey-Mouse" out="Hello, Mickey-Mouse!"/>
<hello-test root="${basedir}/build-tools/test/hello/4" args="IT" out="Ciao!"/>
<hello-test root="${basedir}/build-tools/test/hello/4" args="FR" out="Salut!"/>
<hello-test root="${basedir}/build-tools/test/hello/5" args="Donald-Duck" out="Hello, Donald-Duck!"/>
</sequential>
</macrodef>
<!-- Compiles, runs and verifies the output of web demo longer examples -->
<macrodef name="longer-examples-tests">
<sequential>
<kotlinc-dir srcdir = "${basedir}/build-tools/test/longer-examples"/>
<run-java classname = "bottles.namespace" equals="false" out="12 bottles of beer on the wall, 12 bottles of beer."/>
<run-java classname = "maze.namespace" equals="false" out="O ~OOOOOOOOOOOOOO"/>
<run-java classname = "life.namespace" equals="false" out="*** ** ** ***"/>
<run-java classname = "html.namespace" equals="false" out="&lt;a href=&quot;http://jetbrains.com/kotlin&quot;&gt;"/>
<kotlinc-jar srcdir = "${basedir}/build-tools/test/longer-examples"/>
<run-java classname = "bottles.namespace" equals="false" run-jar="true" out="12 bottles of beer on the wall, 12 bottles of beer."/>
<run-java classname = "maze.namespace" equals="false" run-jar="true" out="O ~OOOOOOOOOOOOOO"/>
<run-java classname = "life.namespace" equals="false" run-jar="true" out="*** ** ** ***"/>
<run-java classname = "html.namespace" equals="false" run-jar="true" out="&lt;a href=&quot;http://jetbrains.com/kotlin&quot;&gt;"/>
</sequential>
</macrodef>
<!-- Compiles and runs a Kotlin module -->
<macrodef name="module-tests">
<sequential>
<kotlinc-jar module="${basedir}/build-tools/test/modules/smoke/Smoke.kts"/>
<run-java classname = "Smoke.namespace" run-jar = "true" args = "1 2 3" out = "1|2|3"/>
</sequential>
</macrodef>
<!-- Verifies build fails if <kotlinc> fails -->
<macrodef name="compilation-fail-test">
<sequential>
<var name="failed" value="false"/>
<trycatch property="error-message" reference="bar">
<try>
<!-- Should fail -->
<kotlinc-dir srcdir = "${basedir}/build-tools/test/compilation-fail"/>
</try>
<catch>
<var name="failed" value="true"/>
<echo>"ERROR:" was expected here</echo>
</catch>
</trycatch>
<if>
<isfalse value="${failed}"/>
<then>
<fail message="kotlinc-dir: compilation should have failed!"/>
</then>
</if>
<var name="failed" value="false"/>
<trycatch property="error-message" reference="bar">
<try>
<!-- Should fail -->
<kotlinc-jar srcdir = "${basedir}/build-tools/test/compilation-fail"/>
</try>
<catch>
<var name="failed" value="true"/>
<echo>"ERROR:" was expected here</echo>
</catch>
</trycatch>
<if>
<isfalse value="${failed}"/>
<then>
<fail message="kotlinc-jar: compilation should have failed!"/>
</then>
</if>
</sequential>
</macrodef>
<!-- Creates build tools distribution jar -->
<target name="buildToolsJar" depends="compile">
<mkdir dir ="${output}/classes/buildTools"/>
<javac destdir="${output}/classes/buildTools" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false">
<src>
<dirset dir="${basedir}/build-tools">
<include name="core/src"/>
<include name="ant/src"/>
<include name="maven/src"/>
<include name="gradle/src"/>
</dirset>
</src>
<compilerarg value="-Xlint:all"/>
<classpath>
<path refid = "classpath.kotlin"/>
<fileset dir = "${ant.home}/lib" includes="*.jar"/>
</classpath>
</javac>
<jar destfile="${output}/kotlin-build-tools.jar">
<fileset dir = "${output}/classes/buildTools"/>
<fileset dir = "${basedir}/build-tools/ant/src" includes="**/*.xml"/>
</jar>
</target>
<!-- Tests build tools distribution jar -->
<target name="buildToolsTest">
<define-kotlinc/>
<hello-tests/>
<longer-examples-tests/>
<module-tests/>
<compilation-fail-test/>
</target>
</project>