Build kotlin-reflect.jar in build.xml and for Maven

Reflection will be distributed in a separate jar and not in kotlin-runtime.jar
for two primary reasons:
- Reflection implementation at the moment takes almost 2Mb
- Separate libraries for separate features is a technique encouraged by Maven,
  and it's inconvenient to make it different in the compiler distribution
This commit is contained in:
Alexander Udalov
2014-12-05 11:38:43 +03:00
parent 2c8754a6af
commit 2b090e02a1
11 changed files with 159 additions and 91 deletions
+71 -47
View File
@@ -15,7 +15,13 @@
<property name="bootstrap.home" value="dependencies/bootstrap-compiler"/>
<property name="bootstrap.compiler.home" value="${bootstrap.home}/Kotlin/kotlinc"/>
<property name="bootstrap.runtime" value="${bootstrap.compiler.home}/lib/kotlin-runtime.jar"/>
<property name="bootstrap.runtime.minimal" value="${bootstrap.compiler.home}/lib/kotlin-runtime-minimal.jar"/>
<!-- TODO: temporary, remove "else" after bootstrap -->
<condition property="bootstrap.reflect"
value="${bootstrap.compiler.home}/lib/kotlin-reflect.jar"
else="${bootstrap.runtime}">
<available file="${bootstrap.compiler.home}/lib/kotlin-reflect.jar"/>
</condition>
<property name="output" value="${basedir}/dist"/>
<property name="kotlin-home" value="${output}/kotlinc"/>
@@ -23,6 +29,7 @@
<property name="bootstrap.build.no.tests" value="false"/>
<property name="idea.sdk" value="${basedir}/ideaSDK"/>
<property name="protobuf.jar" value="${idea.sdk}/lib/protobuf-2.5.0.jar"/>
<property name="protobuf-lite.jar" value="${basedir}/dependencies/protobuf-2.5.0-lite.jar"/>
<property name="javax.inject.jar" value="${basedir}/lib/javax.inject.jar"/>
<property name="java.target" value="1.6"/>
@@ -50,8 +57,8 @@
little to no differences between the new and the newest runtime.
-->
<condition property="compiler.manifest.class.path"
value="kotlin-runtime-internal-bootstrap.jar"
else="kotlin-runtime.jar">
value="kotlin-runtime-internal-bootstrap.jar kotlin-reflect-internal-bootstrap.jar"
else="kotlin-runtime.jar kotlin-reflect.jar">
<istrue value="${bootstrap.or.local.build}"/>
</condition>
@@ -541,7 +548,7 @@
-libraryjars '${rtjar}'
-libraryjars '${jssejar}'
-libraryjars '${bootstrap.runtime.minimal}'
-libraryjars '${bootstrap.runtime}'
-target 1.6
-dontoptimize
@@ -625,6 +632,7 @@
<istrue value="${bootstrap.or.local.build}"/>
<then>
<copy file="${bootstrap.runtime}" tofile="${kotlin-home}/lib/kotlin-runtime-internal-bootstrap.jar"/>
<copy file="${bootstrap.reflect}" tofile="${kotlin-home}/lib/kotlin-reflect-internal-bootstrap.jar"/>
</then>
</if>
@@ -783,6 +791,25 @@
</new-kotlinc>
</target>
<target name="core">
<new-kotlinc output="${output}/classes/core">
<src>
<include name="core/descriptor.loader.java/src"/>
<include name="core/descriptors/src"/>
<include name="core/descriptors.runtime/src"/>
<include name="core/serialization/src"/>
<include name="core/serialization.jvm/src"/>
<include name="core/util.runtime/src"/>
</src>
<class-path>
<pathelement path="${output}/classes/builtins"/>
<pathelement path="${output}/classes/stdlib"/>
<pathelement path="${protobuf-lite.jar}"/>
<pathelement path="${javax.inject.jar}"/>
</class-path>
</new-kotlinc>
</target>
<target name="reflection">
<new-kotlinc output="${output}/classes/reflection">
<src>
@@ -791,21 +818,20 @@
<class-path>
<pathelement path="${output}/classes/builtins"/>
<pathelement path="${output}/classes/stdlib"/>
<pathelement path="${output}/classes/core"/>
<pathelement path="${protobuf-lite.jar}"/>
</class-path>
</new-kotlinc>
</target>
<target name="pack-runtime">
<macrodef name="do-pack-runtime">
<macrodef name="pack-runtime-jar">
<attribute name="jar-name"/>
<attribute name="implementation-title"/>
<element name="reflection-classes" optional="true"/>
<element name="jar-content"/>
<sequential>
<jar destfile="${kotlin-home}/lib/@{jar-name}" duplicate="fail">
<fileset dir="${output}/classes/builtins"/>
<fileset dir="${output}/classes/stdlib"/>
<reflection-classes/>
<jar-content/>
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
<manifest>
@@ -818,54 +844,52 @@
</sequential>
</macrodef>
<do-pack-runtime jar-name="kotlin-runtime.jar" implementation-title="${manifest.impl.title.kotlin.jvm.runtime}">
<reflection-classes>
<fileset dir="${output}/classes/reflection"/>
</reflection-classes>
</do-pack-runtime>
<target name="pack-runtime">
<pack-runtime-jar jar-name="kotlin-runtime.jar" implementation-title="${manifest.impl.title.kotlin.jvm.runtime}">
<jar-content>
<fileset dir="${output}/classes/builtins"/>
<fileset dir="${output}/classes/stdlib"/>
<zipfileset dir="${output}/builtins"/>
</jar-content>
</pack-runtime-jar>
<do-pack-runtime jar-name="kotlin-runtime-minimal.jar" implementation-title="${manifest.impl.title.kotlin.jvm.runtime.minimal}"/>
<pack-runtime-jar jar-name="kotlin-reflect.jar" implementation-title="${manifest.impl.title.kotlin.jvm.reflect}">
<jar-content>
<fileset dir="${output}/classes/reflection"/>
<fileset dir="${output}/classes/core"/>
<zipfileset src="${protobuf-lite.jar}"/>
<zipfileset src="${javax.inject.jar}"/>
</jar-content>
</pack-runtime-jar>
<jar destfile="${kotlin-home}/lib/kotlin-reflect.jar" update="true">
<manifest>
<attribute name="Class-Path" value="kotlin-runtime.jar"/>
</manifest>
</jar>
</target>
<target name="pack-runtime-sources">
<macrodef name="do-pack-runtime-sources">
<attribute name="jar-name"/>
<attribute name="implementation-title"/>
<element name="reflection-sources" optional="true"/>
<sequential>
<jar destfile="${kotlin-home}/lib/@{jar-name}" duplicate="fail">
<pack-runtime-jar jar-name="kotlin-runtime-sources.jar" implementation-title="${manifest.impl.title.kotlin.jvm.runtime.sources}">
<jar-content>
<fileset dir="${basedir}/core/builtins/native" includes="**/*"/>
<fileset dir="${basedir}/core/builtins/src" includes="**/*"/>
<fileset dir="${basedir}/core/runtime.jvm/src" includes="**/*"/>
<fileset dir="${basedir}/core/descriptor.loader.java/src" includes="**/*"/>
<fileset dir="${basedir}/core/descriptors/src" includes="**/*"/>
<fileset dir="${basedir}/core/descriptors.runtime/src" includes="**/*"/>
<fileset dir="${basedir}/core/reflection/src" includes="**/*"/>
<reflection-sources/>
<fileset dir="${basedir}/libraries/stdlib/src" includes="**/*"/>
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
<manifest>
<attribute name="Built-By" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Vendor" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Title" value="@{implementation-title}"/>
<attribute name="Implementation-Version" value="${build.number}"/>
</manifest>
</jar>
</sequential>
</macrodef>
<do-pack-runtime-sources jar-name="kotlin-runtime-sources.jar"
implementation-title="${manifest.impl.title.kotlin.jvm.runtime.sources}">
<reflection-sources>
<fileset dir="${basedir}/core/reflection.jvm/src" includes="**/*"/>
</reflection-sources>
</do-pack-runtime-sources>
<do-pack-runtime-sources jar-name="kotlin-runtime-minimal-sources.jar"
implementation-title="${manifest.impl.title.kotlin.jvm.runtime.minimal.sources}"/>
<fileset dir="${basedir}/core/runtime.jvm/src" includes="**/*"/>
<fileset dir="${basedir}/core/serialization/src" includes="**/*"/>
<fileset dir="${basedir}/core/serialization.jvm/src" includes="**/*"/>
<fileset dir="${basedir}/core/util.runtime/src" includes="**/*"/>
<fileset dir="${basedir}/libraries/stdlib/src" includes="**/*"/>
</jar-content>
</pack-runtime-jar>
</target>
<target name="runtime"
depends="builtins,stdlib,reflection,pack-runtime,pack-runtime-sources"/>
depends="builtins,stdlib,core,reflection,pack-runtime,pack-runtime-sources"/>
<target name="dist"
depends="clean,init,prepare-dist,preloader,serialize-builtins,compiler,compiler-sources,ant-tools,jdk-annotations,android-sdk-annotations,runtime,kotlin-js-stdlib,android-compiler-plugin"
@@ -122,6 +122,7 @@ public class CodegenTestUtil {
File javaClassesTempDirectory = JetTestUtils.tmpDir("java-classes");
List<String> classpath = new ArrayList<String>();
classpath.add(ForTestCompileRuntime.runtimeJarForTests().getPath());
classpath.add(ForTestCompileRuntime.reflectJarForTests().getPath());
classpath.add(JetTestUtils.getAnnotationsJar().getPath());
classpath.addAll(Arrays.asList(additionalClasspath));
List<String> options = Arrays.asList(
@@ -31,11 +31,20 @@ public class ForTestCompileRuntime {
@NotNull
public static File runtimeJarForTests() {
File runtime = new File("dist/kotlinc/lib/kotlin-runtime.jar");
if (!runtime.exists()) {
throw new IllegalStateException("kotlin-runtime.jar in dist/kotlinc/lib does not exist. Run 'ant dist'");
return assertExists(new File("dist/kotlinc/lib/kotlin-runtime.jar"));
}
return runtime;
@NotNull
public static File reflectJarForTests() {
return assertExists(new File("dist/kotlinc/lib/kotlin-reflect.jar"));
}
@NotNull
private static File assertExists(@NotNull File file) {
if (!file.exists()) {
throw new IllegalStateException(file + " does not exist. Run 'ant dist'");
}
return file;
}
@NotNull
@@ -43,7 +52,10 @@ public class ForTestCompileRuntime {
ClassLoader loader = runtimeJarClassLoader.get();
if (loader == null) {
try {
loader = new URLClassLoader(new URL[] {runtimeJarForTests().toURI().toURL()}, null);
loader = new URLClassLoader(new URL[] {
runtimeJarForTests().toURI().toURL(),
reflectJarForTests().toURI().toURL()
}, null);
}
catch (MalformedURLException e) {
throw rethrow(e);
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.integration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.kotlin.utils.UtilsPackage;
import org.junit.Rule;
import org.junit.Test;
@@ -40,16 +41,20 @@ public class AntTaskJvmTest extends AntTaskBaseTest {
private void doJvmAntTest(String... extraJavaArgs) throws Exception {
doAntTest(SUCCESSFUL, extraJavaArgs);
String jar = getOutputFileByName(JVM_OUT_FILE).getAbsolutePath();
String classpath = UtilsPackage.join(Arrays.asList(
getOutputFileByName(JVM_OUT_FILE).getAbsolutePath(),
ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath(),
ForTestCompileRuntime.reflectJarForTests().getAbsolutePath()
), File.pathSeparator);
runJava("hello.run", "-cp", jar + File.pathSeparator + getKotlinRuntimePath(), "hello.HelloPackage");
runJava("hello.run", "-cp", classpath, "hello.HelloPackage");
}
private static String getClassPathForAnt() {
return UtilsPackage.join(Arrays.asList(
getCompilerLib() + File.separator + "kotlin-ant.jar",
getCompilerLib() + File.separator + "kotlin-compiler.jar",
getKotlinRuntimePath()
ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath()
), File.pathSeparator);
}
@@ -18,12 +18,15 @@ package org.jetbrains.kotlin.integration;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.kotlin.utils.UtilsPackage;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -40,13 +43,16 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
}
private int runCompiler(String logName, String... arguments) throws Exception {
String classpath = getCompilerLib().getAbsolutePath() + File.separator + "kotlin-compiler.jar" + File.pathSeparator +
getKotlinRuntimePath();
Collection<String> javaArgs = new ArrayList<String>();
javaArgs.add("-cp");
javaArgs.add(classpath);
javaArgs.add(UtilsPackage.join(Arrays.asList(
getCompilerLib().getAbsolutePath() + File.separator + "kotlin-compiler.jar",
ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath(),
ForTestCompileRuntime.reflectJarForTests().getAbsolutePath()
), File.pathSeparator));
javaArgs.add("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler");
Collections.addAll(javaArgs, arguments);
return runJava(logName, ArrayUtil.toStringArray(javaArgs));
@@ -81,7 +87,8 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
assertEquals("compilation failed", 0, runCompiler("Smoke.compile", "-module", "Smoke.ktm", "-d", jar));
runJava("Smoke.run", "-cp", jar + File.pathSeparator + getKotlinRuntimePath(), "Smoke.SmokePackage", "1", "2", "3");
String classpath = jar + File.pathSeparator + ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath();
runJava("Smoke.run", "-cp", classpath, "Smoke.SmokePackage", "1", "2", "3");
}
@Test
@@ -31,7 +31,6 @@ import kotlin.KotlinPackage;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.KotlinVersion;
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.test.Tmpdir;
import org.jetbrains.kotlin.utils.PathUtil;
@@ -166,10 +165,6 @@ public abstract class KotlinIntegrationTestBase {
return file;
}
protected static String getKotlinRuntimePath() {
return ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath();
}
protected static File getKotlinProjectHome() {
return new File(PathManager.getHomePath()).getParentFile();
}
@@ -385,14 +385,21 @@ public class JetTestUtils {
}
@NotNull
public static CompilerConfiguration compilerConfigurationForTests(@NotNull ConfigurationKind configurationKind,
@NotNull TestJdkKind jdkKind, File... extraClasspath) {
public static CompilerConfiguration compilerConfigurationForTests(
@NotNull ConfigurationKind configurationKind,
@NotNull TestJdkKind jdkKind,
@NotNull File... extraClasspath
) {
return compilerConfigurationForTests(configurationKind, jdkKind, Arrays.asList(extraClasspath), Collections.<File>emptyList());
}
@NotNull
public static CompilerConfiguration compilerConfigurationForTests(@NotNull ConfigurationKind configurationKind,
@NotNull TestJdkKind jdkKind, @NotNull Collection<File> extraClasspath, @NotNull Collection<File> priorityClasspath) {
public static CompilerConfiguration compilerConfigurationForTests(
@NotNull ConfigurationKind configurationKind,
@NotNull TestJdkKind jdkKind,
@NotNull Collection<File> extraClasspath,
@NotNull Collection<File> priorityClasspath
) {
CompilerConfiguration configuration = new CompilerConfiguration();
configuration.addAll(CLASSPATH_KEY, priorityClasspath);
if (jdkKind == TestJdkKind.MOCK_JDK) {
@@ -406,13 +413,15 @@ public class JetTestUtils {
}
if (configurationKind == ALL) {
configuration.add(CLASSPATH_KEY, ForTestCompileRuntime.runtimeJarForTests());
configuration.add(CLASSPATH_KEY, ForTestCompileRuntime.reflectJarForTests());
}
configuration.addAll(CLASSPATH_KEY, extraClasspath);
if (configurationKind == ALL || configurationKind == JDK_AND_ANNOTATIONS) {
if (jdkKind == TestJdkKind.ANDROID_API) {
configuration.add(ANNOTATIONS_PATH_KEY, getAndroidSdkAnnotationsJar());
} else {
}
else {
configuration.add(ANNOTATIONS_PATH_KEY, getJdkAnnotationsJar());
}
}
@@ -18,7 +18,6 @@ package kotlin.jvm;
public class KotlinReflectionNotSupportedError extends Error {
public KotlinReflectionNotSupportedError() {
super("Kotlin reflection implementation is not found at runtime. " +
"Make sure you do have kotlin-runtime.jar and do not have kotlin-runtime-minimal.jar in the classpath");
super("Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath");
}
}
+1
View File
@@ -45,6 +45,7 @@
<asm.version>3.3.1</asm.version>
<dart.name>dart-r3300</dart.name>
<guava.version>11.0.2</guava.version>
<protobuf.version>2.5.0</protobuf.version>
<junit-version>4.11</junit-version>
<kotlin-maven-plugin.version>0.2.3.8</kotlin-maven-plugin.version>
<kotlin-dist>${project-root}/dist</kotlin-dist>
+16
View File
@@ -21,6 +21,16 @@
<artifactId>kotlin-stdlib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies>
<build>
@@ -40,7 +50,13 @@
<target>
<delete dir="${basedir}/target/copied-sources" failonerror="false" />
<copy todir="${basedir}/target/copied-sources">
<fileset dir="${basedir}/../../../core/descriptor.loader.java/src"/>
<fileset dir="${basedir}/../../../core/descriptors/src"/>
<fileset dir="${basedir}/../../../core/descriptors.runtime/src"/>
<fileset dir="${basedir}/../../../core/reflection.jvm/src"/>
<fileset dir="${basedir}/../../../core/serialization/src"/>
<fileset dir="${basedir}/../../../core/serialization.jvm/src"/>
<fileset dir="${basedir}/../../../core/util.runtime/src"/>
</copy>
</target>
</configuration>
+1 -2
View File
@@ -7,9 +7,8 @@ manifest.impl.title.kotlin.compiler.sources=Kotlin Compiler Sources
manifest.impl.title.kotlin.compiler.ant.task=Kotlin Compiler Ant Tasks
manifest.impl.title.kotlin.jvm.runtime=Kotlin Runtime
manifest.impl.title.kotlin.jvm.runtime.minimal=Kotlin Runtime Minimal
manifest.impl.title.kotlin.jvm.reflect=Kotlin Reflect
manifest.impl.title.kotlin.jvm.runtime.sources=Kotlin Runtime Sources
manifest.impl.title.kotlin.jvm.runtime.minimal.sources=Kotlin Runtime Minimal Sources
manifest.impl.title.kotlin.javascript.stdlib=Kotlin JavaScript StdLib
manifest.spec.title.kotlin.javascript.lib=Kotlin JavaScript Lib