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:
@@ -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(
|
||||
|
||||
+17
-5
@@ -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"));
|
||||
}
|
||||
|
||||
@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 runtime;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user