495 lines
21 KiB
XML
495 lines
21 KiB
XML
<project name="build-tools" default="buildToolsJar" xmlns:ivy="antlib:org.apache.ivy.ant">
|
|
|
|
<property name="tests-dir" location="${output}/ant-test/build-tools-test"/>
|
|
<property name="tests-jar" location="${tests-dir}/out.jar"/>
|
|
<property name="junit-jar" location="${basedir}/libraries/testlib/lib/junit-4.9.jar"/>
|
|
<property name="failonerror" value="true"/> <!-- Whether invoking compiled classes should file on error -->
|
|
<property name="use-ivy" value="false"/> <!-- Whether Ivy should be used to define "kotlin.classpath" and <kotlinc> task -->
|
|
<!-- Override with "-Duse-ivy=true" -->
|
|
|
|
|
|
<!-- http://ant-contrib.sourceforge.net/tasks/tasks/index.html -->
|
|
<taskdef resource="net/sf/antcontrib/antlib.xml">
|
|
<classpath>
|
|
<pathelement location="${basedir}/build-tools/lib/ant-contrib-1.0b3.jar"/>
|
|
</classpath>
|
|
</taskdef>
|
|
|
|
|
|
<path id="junit-jar">
|
|
<fileset file="${junit-jar}"/>
|
|
</path>
|
|
|
|
|
|
<!-- Verifies file or directory specified exists -->
|
|
<macrodef name="verify-exists">
|
|
<attribute name="file"/>
|
|
<attribute name="type" default="dir"/>
|
|
<sequential>
|
|
<if>
|
|
<available file="@{file}" type="@{type}"/>
|
|
<then>
|
|
<echo>[@{file}] of type [@{type}] exists</echo>
|
|
</then>
|
|
<else>
|
|
<fail message="[@{file}] of type [@{type}] is not found!"/>
|
|
</else>
|
|
</if>
|
|
</sequential>
|
|
</macrodef>
|
|
|
|
|
|
<!-- Defines "kotlin.classpath" using ${kotlin-home} -->
|
|
<macrodef name="kotlin-home-setup">
|
|
<sequential>
|
|
<if>
|
|
<and>
|
|
<available file="${kotlin-home}/lib/kotlin-build-tools.jar" type="file"/>
|
|
<available file="${kotlin-home}/lib/kotlin-compiler.jar" type="file"/>
|
|
<available file="${kotlin-home}/lib/kotlin-runtime.jar" type="file"/>
|
|
</and>
|
|
<then>
|
|
<echo>[${kotlin-home}/lib] jars found, defining "kotlin.classpath"</echo>
|
|
<path id="kotlin.classpath">
|
|
<fileset dir = "${kotlin-home}/lib" includes = "*.jar"/>
|
|
</path>
|
|
</then>
|
|
<else>
|
|
<!-- Creating and unpacking the distribution archive to make sure it's Ok -->
|
|
<echo>[${kotlin-home}/lib] jars *not* found, creating distribution zip</echo>
|
|
|
|
<antcall target = "zip"/>
|
|
<verify-exists file="${output}/${output.name}.zip" type="file"/>
|
|
|
|
<!-- Sometimes deleting "dist/kotlinc/lib/alt/kotlin-jdk-headers.jar" fails -->
|
|
<delete dir = "${kotlin-home}" failonerror="false"/>
|
|
<mkdir dir = "${kotlin-home}"/>
|
|
<unzip src = "${output}/${output.name}.zip" dest="${output}"/>
|
|
|
|
<verify-exists file="${kotlin-home}/lib"/>
|
|
<verify-exists file="${kotlin-home}/lib/kotlin-build-tools.jar" type="file"/>
|
|
<verify-exists file="${kotlin-home}/lib/kotlin-compiler.jar" type="file"/>
|
|
<verify-exists file="${kotlin-home}/lib/kotlin-runtime.jar" type="file"/>
|
|
|
|
<kotlin-home-setup/>
|
|
</else>
|
|
</if>
|
|
</sequential>
|
|
</macrodef>
|
|
|
|
|
|
<!-- Defines "kotlin.classpath" and <kotlinc> task -->
|
|
<macrodef name="define-kotlinc">
|
|
<sequential>
|
|
<if>
|
|
<istrue value="${use-ivy}"/>
|
|
<then>
|
|
<!-- Defining "kotlin.classpath" with Ivy -->
|
|
<taskdef uri="antlib:org.apache.ivy.ant" resource="org/apache/ivy/ant/antlib.xml"/>
|
|
<ivy:configure file="${basedir}/build-tools/ivyconf.xml"/>
|
|
<ivy:resolve file="${basedir}/build-tools/ivy.xml"/>
|
|
<ivy:cachepath pathid="kotlin.classpath" organisation="org" revision="latest.lastSuccessful"/>
|
|
</then>
|
|
<else>
|
|
<!-- Defining "kotlin.classpath" with ${kotlin-home} -->
|
|
<kotlin-home-setup/>
|
|
</else>
|
|
</if>
|
|
|
|
<taskdef resource = "org/jetbrains/jet/buildtools/ant/antlib.xml">
|
|
<classpath>
|
|
<path refid="kotlin.classpath"/>
|
|
</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="src"/>
|
|
<attribute name="stdlib" default=""/>
|
|
|
|
<sequential>
|
|
<cleanup/>
|
|
<kotlinc src = "@{src}" output = "${tests-dir}" stdlib = "@{stdlib}" classpathref="junit-jar"/>
|
|
</sequential>
|
|
</macrodef>
|
|
|
|
|
|
<!-- Runs <kotlinc> to create a *.class files in a jar -->
|
|
<macrodef name="kotlinc-jar">
|
|
<attribute name="src" default=""/>
|
|
<attribute name="module" default=""/>
|
|
<attribute name="includeRuntime" default="true"/>
|
|
<attribute name="stdlib" default=""/>
|
|
<attribute name="jar" default="${tests-jar}"/>
|
|
<sequential>
|
|
|
|
<cleanup/>
|
|
|
|
<if>
|
|
<equals arg1="@{module}" arg2=""/>
|
|
<then>
|
|
<kotlinc src = "@{src}" jar = "@{jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}">
|
|
<classpath>
|
|
<path refid="junit-jar"/>
|
|
</classpath>
|
|
</kotlinc>
|
|
</then>
|
|
<elseif>
|
|
<equals arg1="@{jar}" arg2=""/>
|
|
<then>
|
|
<kotlinc module = "@{module}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}">
|
|
<classpath>
|
|
<fileset file="${junit-jar}"/>
|
|
</classpath>
|
|
</kotlinc>
|
|
</then>
|
|
</elseif>
|
|
<else>
|
|
<kotlinc module = "@{module}" jar = "@{jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}" classpath="${junit-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 -->
|
|
<attribute name="jar" default="${tests-jar}"/> <!-- Jar to use for classpath if "run-jar" is "true" -->
|
|
<sequential>
|
|
<var name = "java-out" unset = "true"/>
|
|
|
|
<if>
|
|
<istrue value="@{run-jar}"/>
|
|
<then>
|
|
<echo>Running [@{classname}], classpath = "@{jar}"</echo>
|
|
<java outputproperty = "java-out"
|
|
classname = "@{classname}"
|
|
failonerror = "${failonerror}">
|
|
<classpath>
|
|
<pathelement path = "@{jar}"/>
|
|
</classpath>
|
|
<arg line = "@{args}"/>
|
|
</java>
|
|
</then>
|
|
<else>
|
|
<echo>Running [@{classname}], classpath = "${tests-dir}"</echo>
|
|
<java outputproperty = "java-out"
|
|
classname = "@{classname}"
|
|
failonerror = "${failonerror}">
|
|
<classpath>
|
|
<pathelement path = "${tests-dir}"/>
|
|
<path refid = "kotlin.classpath"/>
|
|
</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 src = "@{root}/Hello.kt"/>
|
|
<run-java args = "@{args}" out = "@{out}"/>
|
|
|
|
<kotlinc-dir src = "@{root}"/>
|
|
<run-java args = "@{args}" out = "@{out}"/>
|
|
|
|
<kotlinc-jar src = "@{root}/Hello.kt"/>
|
|
<run-java args = "@{args}" out = "@{out}" run-jar="true"/>
|
|
|
|
<kotlinc-jar src = "@{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 src = "${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 = "life.namespace" equals="false" out="*** ** ** ***"/>
|
|
<!--<run-java classname = "maze.namespace" equals="false" out="O ~OOOOOOOOOOOOOO"/>-->
|
|
<!--<run-java classname = "html.namespace" equals="false" out="<a href="http://jetbrains.com/kotlin">"/>-->
|
|
|
|
<kotlinc-jar src = "${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 = "life.namespace" equals="false" run-jar="true" out="*** ** ** ***"/>
|
|
<!--<run-java classname = "maze.namespace" equals="false" run-jar="true" out="O ~OOOOOOOOOOOOOO"/>-->
|
|
<!--<run-java classname = "html.namespace" equals="false" run-jar="true" out="<a href="http://jetbrains.com/kotlin">"/>-->
|
|
</sequential>
|
|
</macrodef>
|
|
|
|
|
|
<!-- Compiles and runs a Kotlin module -->
|
|
<macrodef name="module-tests">
|
|
<sequential>
|
|
<!-- Module => Explicit Jar -->
|
|
<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"/>
|
|
|
|
<!-- Module => Default Jar -->
|
|
<kotlinc-jar module="${basedir}/build-tools/test/modules/smoke/Smoke.kts" jar=""/>
|
|
<move file="${basedir}/build-tools/test/modules/smoke/smoke.jar" todir="${tests-dir}"/>
|
|
<run-java classname = "Smoke.namespace" run-jar = "true" args = "1 2 3" out = "1|2|3" jar="${tests-dir}/smoke.jar"/>
|
|
</sequential>
|
|
</macrodef>
|
|
|
|
|
|
<!-- Runs JUnit single test or batch tests -->
|
|
<macrodef name="run-junit">
|
|
<attribute name="classpath"/>
|
|
<attribute name="test" default=""/>
|
|
<sequential>
|
|
|
|
<path id="junit-classpath">
|
|
<path refid="junit-jar"/>
|
|
<path refid="kotlin.classpath"/>
|
|
<pathelement location="@{classpath}"/>
|
|
</path>
|
|
|
|
<if>
|
|
<equals arg1="@{test}" arg2=""/>
|
|
<then>
|
|
<!-- Batch tests -->
|
|
<if>
|
|
<matches string="@{classpath}" pattern="\.jar$"/>
|
|
<then>
|
|
<!-- Batch tests from a jar -->
|
|
<echo>Running JUnit: classpath = "@{classpath}" (Jar)</echo>
|
|
<junit haltonfailure="true">
|
|
<classpath>
|
|
<path refid="junit-classpath"/>
|
|
</classpath>
|
|
<formatter type="plain" usefile="false"/>
|
|
<batchtest>
|
|
<zipfileset src="@{classpath}" includes="**/*Test.class" excludes="**/BuiltTest.class"/>
|
|
</batchtest>
|
|
</junit>
|
|
</then>
|
|
<else>
|
|
<!-- Batch tests from a dir -->
|
|
<echo>Running JUnit: classpath = "@{classpath}" (Dir)</echo>
|
|
<junit haltonfailure="true">
|
|
<classpath>
|
|
<path refid="junit-classpath"/>
|
|
</classpath>
|
|
<formatter type="plain" usefile="false"/>
|
|
<batchtest>
|
|
<fileset dir="@{classpath}" includes="**/*Test.class" excludes="**/BuiltTest.class"/>
|
|
</batchtest>
|
|
</junit>
|
|
</else>
|
|
</if>
|
|
</then>
|
|
<else>
|
|
<!-- Single test -->
|
|
<echo>Running JUnit: test = "@{test}", classpath = "@{classpath}"</echo>
|
|
<junit haltonfailure="true">
|
|
<classpath>
|
|
<path refid="junit-classpath"/>
|
|
</classpath>
|
|
<formatter type="plain" usefile="false"/>
|
|
<test name="@{test}"/>
|
|
</junit>
|
|
</else>
|
|
</if>
|
|
</sequential>
|
|
</macrodef>
|
|
|
|
|
|
<!-- Runs all JUnit tests, first each test separately and then all of them in a batch mode -->
|
|
<macrodef name="testlib-junit-tests">
|
|
<attribute name="classpath"/>
|
|
<sequential>
|
|
<run-junit classpath="@{classpath}" test="test.collections.CollectionTest"/>
|
|
<run-junit classpath="@{classpath}" test="test.collections.IoTest"/>
|
|
<run-junit classpath="@{classpath}" test="test.collections.ListTest"/>
|
|
<run-junit classpath="@{classpath}" test="test.collections.MapTest"/>
|
|
<run-junit classpath="@{classpath}" test="test.collections.OldStdlibTest"/>
|
|
<run-junit classpath="@{classpath}" test="test.collections.SetTest"/>
|
|
<run-junit classpath="@{classpath}" test="test.collections.StandardCollectionTest"/>
|
|
<run-junit classpath="@{classpath}" test="test.stdlib.issues.StdLibIssuesTest"/>
|
|
<run-junit classpath="@{classpath}" test="testString.StringTest"/>
|
|
|
|
<run-junit classpath="@{classpath}"/>
|
|
</sequential>
|
|
</macrodef>
|
|
|
|
|
|
<!-- Compiles "testlib" Kotlin tests (dir/module => dir/jar) and runs all JUnit tests resulted -->
|
|
<macrodef name="testlib-tests">
|
|
<sequential>
|
|
<!-- Dir => Dir -->
|
|
<kotlinc-dir src = "${basedir}/libraries/testlib/test"/>
|
|
<testlib-junit-tests classpath = "${tests-dir}"/>
|
|
|
|
<!-- Dir => Jar -->
|
|
<kotlinc-jar src = "${basedir}/libraries/testlib/test"/>
|
|
<testlib-junit-tests classpath = "${tests-jar}"/>
|
|
|
|
<!-- Module => Explicit Jar -->
|
|
<kotlinc-jar module = "${basedir}/libraries/testlib/module.kt"/>
|
|
<testlib-junit-tests classpath = "${tests-jar}"/>
|
|
|
|
<!-- Module => Default Jar -->
|
|
<kotlinc-jar module = "${basedir}/libraries/testlib/module.kt" jar=""/>
|
|
<move file="${basedir}/libraries/testlib/testlib.jar" todir="${tests-dir}"/>
|
|
<testlib-junit-tests classpath = "${tests-dir}/testlib.jar"/>
|
|
</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 src = "${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 src = "${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>
|
|
|
|
<var name="failed" value="false"/>
|
|
<trycatch property="error-message" reference="bar">
|
|
<try>
|
|
<!-- Should fail -->
|
|
<kotlinc-jar module = "${basedir}/build-tools/test/compilation-fail/Smoke.kts"/>
|
|
</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="${kotlin-home}/lib/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/>
|
|
<!--<testlib-tests/>-->
|
|
<compilation-fail-test/>
|
|
</target>
|
|
</project>
|