Ant task: do not include runtime by default if destination is a jar

This commit is contained in:
scaventz
2021-01-14 00:04:48 +08:00
committed by Alexander Udalov
parent b0b7f39c75
commit a13eb4c8e6
6 changed files with 78 additions and 2 deletions

View File

@@ -26,7 +26,7 @@ import java.io.File.separator
class Kotlin2JvmTask : KotlinCompilerBaseTask() { class Kotlin2JvmTask : KotlinCompilerBaseTask() {
override val compilerFqName = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" override val compilerFqName = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
var includeRuntime: Boolean = true var includeRuntime: Boolean = false
var moduleName: String? = null var moduleName: String? = null
var noReflect: Boolean = false var noReflect: Boolean = false

View File

@@ -0,0 +1,16 @@
OUT:
Buildfile: [TestData]/build.xml
test1:
[kotlinc] Compiling [[TestData]/test.kt] => [[Temp]/test.jar]
test2:
[kotlinc] Compiling [[TestData]/test.kt] => [[Temp]/test.jar]
test3:
[kotlinc] Compiling [[TestData]/test.kt] => [[Temp]/test.jar]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0

View File

@@ -0,0 +1,41 @@
<project name="Ant Task Test" default="test3">
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
<target name="test1" description="destination is a jar and attribute includeRuntime is not specified">
<kotlinc src="${test.data}/test.kt" output="${temp}/test.jar"/>
<java classname="TestKt" description="check the resulting jar">
<classpath>
<pathelement location="${temp}/test.jar"/>
<pathelement location="${kotlin.runtime.jar}"/>
</classpath>
<arg value="${temp}/test.jar"/>
<arg value="false" description="if includeRuntime is specified to be true"/>
</java>
</target>
<target name="test2" description="destination is a jar and attribute includeRuntime is specified to be false" depends="test1">
<kotlinc src="${test.data}/test.kt" output="${temp}/test.jar" includeRuntime="false"/>
<java classname="TestKt" description="check the resulting jar">
<classpath>
<pathelement location="${temp}/test.jar"/>
<pathelement location="${kotlin.runtime.jar}"/>
</classpath>
<arg value="${temp}/test.jar"/>
<arg value="false" description="if includeRuntime is specified to be true"/>
</java>
</target>
<target name="test3" description="destination is a jar and attribute includeRuntime is specified to be true" depends="test2">
<kotlinc src="${test.data}/test.kt" output="${temp}/test.jar" includeRuntime="true"/>
<java classname="TestKt">
<classpath>
<pathelement location="${temp}/test.jar"/>
</classpath>
<arg value="${temp}/test.jar"/>
<arg value="true" description="if includeRuntime is specified to be true"/>
</java>
</target>
</project>

View File

@@ -0,0 +1,14 @@
import java.io.File
import java.util.jar.JarFile
fun main(args: Array<String>) {
val jar = File(args[0])
// if "includeRuntime" is specified to be true
var specifiedBeTrue = args[1].toBoolean()
for (entry in JarFile(jar).entries()) {
if (!specifiedBeTrue && entry.name.startsWith("kotlin/")) {
println("Error: Kotlin runtime is expected to be excluded if the attribute \"includeRuntime\" is not specified to be true")
break;
}
}
}

View File

@@ -2,7 +2,7 @@
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/> <taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
<target name="build"> <target name="build">
<kotlinc src="${test.data}/test.kt" classpath="${test.data}/Kt11995.jar" output="${temp}/test.jar" nowarn="true" /> <kotlinc src="${test.data}/test.kt" classpath="${test.data}/Kt11995.jar" output="${temp}/test.jar" nowarn="true" includeRuntime="true"/>
<exec executable="java"> <exec executable="java">
<arg line="-classpath ${temp}/test.jar foo.TestKt"/> <arg line="-classpath ${temp}/test.jar foo.TestKt"/>

View File

@@ -39,6 +39,11 @@ public class AntTaskTestGenerated extends AbstractAntTaskTest {
runTest("compiler/testData/integration/ant/jvm/doNotFailOnError/"); runTest("compiler/testData/integration/ant/jvm/doNotFailOnError/");
} }
@TestMetadata("doNotIncludeRuntimeByDefault")
public void testDoNotIncludeRuntimeByDefault() throws Exception {
runTest("compiler/testData/integration/ant/jvm/doNotIncludeRuntimeByDefault/");
}
@TestMetadata("failOnErrorByDefault") @TestMetadata("failOnErrorByDefault")
public void testFailOnErrorByDefault() throws Exception { public void testFailOnErrorByDefault() throws Exception {
runTest("compiler/testData/integration/ant/jvm/failOnErrorByDefault/"); runTest("compiler/testData/integration/ant/jvm/failOnErrorByDefault/");