Files
kotlin-fork/build-tools/build.xml
T

296 lines
12 KiB
XML

<project name="build-tools" default="buildToolsJar">
<property name="tests-dir" location="${output}/ant-test/build-tools-test"/>
<property name="tests-jar" location="${tests-dir}/out.jar"/>
<property name="kotlin-home" location="${output}/ant-test/kotlin-home"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${basedir}/build-tools/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!-- Re-creates ${kotlin-home} and defines <kotlin> tasks using "${kotlin-home}/lib" jars -->
<macrodef name="setup-kotlin-home">
<sequential>
<if>
<not>
<available file="${kotlin-home}" type="dir"/>
</not>
<then>
<mkdir dir = "${kotlin-home}"/>
<if>
<available file="${basedir}/bootstrap.compiler/kotlinc" type="dir"/>
<then>
<!-- Running in TeamCity environment -->
<copy todir="${kotlin-home}">
<fileset dir = "${basedir}/bootstrap.compiler/kotlinc"/>
</copy>
</then>
<else>
<!-- Running in dev environment -->
<if>
<not>
<available file="${output}/${output.name}.zip"/>
</not>
<then>
<antcall target="dist"/>
</then>
</if>
<unzip src = "${output}/${output.name}.zip"
dest = "${kotlin-home}"/>
<move todir = "${kotlin-home}">
<fileset dir = "${kotlin-home}/kotlinc"/>
</move>
<delete dir = "${kotlin-home}/kotlinc" failonerror = "true"/>
</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>
<!-- Runs <kotlinc> in test directory -->
<macrodef name="kotlinc-dir">
<attribute name="file" default=""/>
<attribute name="srcdir" default=""/>
<sequential>
<delete dir = "${tests-dir}"/>
<mkdir dir = "${tests-dir}"/>
<if>
<equals arg1="@{file}" arg2=""/>
<then>
<kotlinc srcdir = "@{srcdir}" destdir = "${tests-dir}" />
</then>
<else>
<kotlinc file = "@{file}" destdir = "${tests-dir}" />
</else>
</if>
</sequential>
</macrodef>
<!-- Runs <kotlinc> with test jar -->
<macrodef name="kotlinc-jar">
<attribute name="file" default=""/>
<attribute name="srcdir" default=""/>
<sequential>
<delete dir = "${tests-dir}"/>
<mkdir dir = "${tests-dir}"/>
<delete file = "${tests-jar}"/>
<if>
<equals arg1="@{file}" arg2=""/>
<then>
<kotlinc srcdir = "@{srcdir}" destjar = "${tests-jar}"/>
</then>
<else>
<kotlinc file = "@{file}" destjar = "${tests-jar}"/>
</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}], cp = [${tests-jar}]</echo>
<java outputproperty = "java-out"
classname = "@{classname}"
failonerror = "true">
<classpath>
<pathelement path = "${tests-jar}"/>
</classpath>
<arg line = "@{args}"/>
</java>
</then>
<else>
<echo>Running [@{classname}], cp = [${tests-dir}];[${kotlin-home}/lib/kotlin-runtime.jar]</echo>
<java outputproperty = "java-out"
classname = "@{classname}"
failonerror = "true">
<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>
<else>
<fail message="Test failed: '${java-out}' (received) != '@{out}' (expected), equals = [@{equals}]"/>
</else>
</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>
<!-- 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">
<setup-kotlin-home/>
<hello-tests/>
<longer-examples-tests/>
<compilation-fail-test/>
</target>
</project>