Compile built-ins in ForTestCompileRuntime
Remove references to "out/production/builtins", since those built-ins are compiled by the bootstrap compiler, whereas we want to test built-ins compiled by the new (working copy) compiler
This commit is contained in:
@@ -18,7 +18,6 @@ package org.jetbrains.jet.codegen;
|
|||||||
|
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.intellij.openapi.util.SystemInfo;
|
import com.intellij.openapi.util.SystemInfo;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -26,6 +25,7 @@ import org.jetbrains.jet.JetTestUtils;
|
|||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.Progress;
|
import org.jetbrains.jet.codegen.state.Progress;
|
||||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
@@ -101,10 +101,8 @@ public class CodegenTestUtil {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static File compileJava(@NotNull String filename) {
|
public static File compileJava(@NotNull String filename) {
|
||||||
try {
|
try {
|
||||||
File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes");
|
File javaClassesTempDirectory = JetTestUtils.tmpDir("java-classes");
|
||||||
JetTestUtils.mkdirs(javaClassesTempDirectory);
|
String classPath = ForTestCompileRuntime.runtimeJarForTests() + File.pathSeparator +
|
||||||
String classPath = "out/production/builtins" + File.pathSeparator +
|
|
||||||
"out/production/runtime.jvm" + File.pathSeparator +
|
|
||||||
JetTestUtils.getAnnotationsJar().getPath();
|
JetTestUtils.getAnnotationsJar().getPath();
|
||||||
List<String> options = Arrays.asList(
|
List<String> options = Arrays.asList(
|
||||||
"-classpath", classPath,
|
"-classpath", classPath,
|
||||||
|
|||||||
+47
-14
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.codegen.forTestCompile;
|
package org.jetbrains.jet.codegen.forTestCompile;
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.cli.common.ExitCode;
|
import org.jetbrains.jet.cli.common.ExitCode;
|
||||||
@@ -25,6 +26,9 @@ import org.jetbrains.jet.utils.Profiler;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile kotlin-runtime.jar that can be used in tests
|
* Compile kotlin-runtime.jar that can be used in tests
|
||||||
@@ -32,6 +36,8 @@ import java.io.IOException;
|
|||||||
* @see #runtimeJarForTests
|
* @see #runtimeJarForTests
|
||||||
*/
|
*/
|
||||||
public class ForTestCompileRuntime {
|
public class ForTestCompileRuntime {
|
||||||
|
private static final String BUILT_INS_SRC_PATH = "core/builtins/src";
|
||||||
|
private static final String RUNTIME_JVM_SRC_PATH = "core/runtime.jvm/src";
|
||||||
|
|
||||||
private ForTestCompileRuntime() {
|
private ForTestCompileRuntime() {
|
||||||
}
|
}
|
||||||
@@ -45,33 +51,54 @@ public class ForTestCompileRuntime {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doCompile(@NotNull File classesDir) throws Exception {
|
protected void doCompile(@NotNull File classesDir) throws Exception {
|
||||||
compileJvmBuiltins(classesDir);
|
compileBuiltIns(classesDir);
|
||||||
compileStdlib(classesDir);
|
compileStdlib(classesDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void compileBuiltIns(@NotNull File destDir) throws IOException {
|
||||||
|
String src = BUILT_INS_SRC_PATH + File.pathSeparator + RUNTIME_JVM_SRC_PATH;
|
||||||
|
compileKotlinToJvm("built-ins", destDir, src, src);
|
||||||
|
|
||||||
|
JetTestUtils.compileJavaFiles(
|
||||||
|
ContainerUtil.concat(javaFilesUnder(BUILT_INS_SRC_PATH), javaFilesUnder(RUNTIME_JVM_SRC_PATH)),
|
||||||
|
Arrays.asList(
|
||||||
|
"-classpath", destDir.getPath(),
|
||||||
|
"-d", destDir.getPath()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static List<File> javaFilesUnder(@NotNull String path) {
|
||||||
|
return FileUtil.findFilesByMask(Pattern.compile(".*\\.java"), new File(path));
|
||||||
|
}
|
||||||
|
|
||||||
private static void compileStdlib(@NotNull File destDir) throws IOException {
|
private static void compileStdlib(@NotNull File destDir) throws IOException {
|
||||||
ExitCode exitCode = new K2JVMCompiler().exec(System.out,
|
compileKotlinToJvm("stdlib", destDir, "libraries/stdlib/src", destDir.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void compileKotlinToJvm(
|
||||||
|
@NotNull String debugName,
|
||||||
|
@NotNull File destDir,
|
||||||
|
@NotNull String src,
|
||||||
|
@NotNull String classPath
|
||||||
|
) {
|
||||||
|
ExitCode exitCode = new K2JVMCompiler().exec(
|
||||||
|
System.out,
|
||||||
"-output", destDir.getPath(),
|
"-output", destDir.getPath(),
|
||||||
"-src", "./libraries/stdlib/src",
|
"-src", src,
|
||||||
"-noStdlib",
|
"-noStdlib",
|
||||||
"-noJdkAnnotations",
|
"-noJdkAnnotations",
|
||||||
"-suppress", "warnings",
|
"-suppress", "warnings",
|
||||||
"-annotations", "./jdk-annotations",
|
"-annotations", "./jdk-annotations",
|
||||||
"-classpath", "out/production/builtins" + File.pathSeparator + "out/production/runtime.jvm");
|
"-classpath", classPath
|
||||||
|
);
|
||||||
if (exitCode != ExitCode.OK) {
|
if (exitCode != ExitCode.OK) {
|
||||||
throw new IllegalStateException("stdlib for test compilation failed: " + exitCode);
|
throw new IllegalStateException("Compilation of " + debugName + " failed: " + exitCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void compileJvmBuiltins(@NotNull File destDir) throws IOException {
|
|
||||||
// Sources of stdlib and built-ins may diverge this way, because the former are compiled with the new compiler and the latter are
|
|
||||||
// just copied from the sources built by bootstrap plugin (which has an old compiler)
|
|
||||||
// TODO: compile Kotlin+Java built-in sources properly here, maybe reusing KotlinCompilerAdapter ant task
|
|
||||||
FileUtil.copyDir(new File("out/production/builtins"), destDir);
|
|
||||||
FileUtil.copyDir(new File("out/production/runtime.jvm"), destDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static File runtimeJarForTests() {
|
public static File runtimeJarForTests() {
|
||||||
return ForTestCompileSomething.ACTUALLY_COMPILE ? Runtime.runtime.getJarFile() : new File("dist/kotlinc/lib/kotlin-runtime.jar");
|
return ForTestCompileSomething.ACTUALLY_COMPILE ? Runtime.runtime.getJarFile() : new File("dist/kotlinc/lib/kotlin-runtime.jar");
|
||||||
@@ -79,8 +106,14 @@ public class ForTestCompileRuntime {
|
|||||||
|
|
||||||
// This method is very convenient when you have trouble compiling runtime in tests
|
// This method is very convenient when you have trouble compiling runtime in tests
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
File destDir = JetTestUtils.tmpDir("runtime");
|
||||||
|
|
||||||
|
Profiler builtIns = Profiler.create("compileBuiltIns").start();
|
||||||
|
compileBuiltIns(destDir);
|
||||||
|
builtIns.end();
|
||||||
|
|
||||||
Profiler stdlib = Profiler.create("compileStdlib").start();
|
Profiler stdlib = Profiler.create("compileStdlib").start();
|
||||||
compileStdlib(JetTestUtils.tmpDir("runtime"));
|
compileStdlib(destDir);
|
||||||
stdlib.end();
|
stdlib.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
|||||||
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
|
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.codegen.GenerationUtils;
|
import org.jetbrains.jet.codegen.GenerationUtils;
|
||||||
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
import org.jetbrains.jet.di.InjectorForJavaDescriptorResolver;
|
import org.jetbrains.jet.di.InjectorForJavaDescriptorResolver;
|
||||||
@@ -110,8 +111,7 @@ public final class LoadDescriptorUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void compileJavaWithAnnotationsJar(@NotNull Collection<File> javaFiles, @NotNull File outDir) throws IOException {
|
private static void compileJavaWithAnnotationsJar(@NotNull Collection<File> javaFiles, @NotNull File outDir) throws IOException {
|
||||||
String classPath = "out/production/builtins" + File.pathSeparator +
|
String classPath = ForTestCompileRuntime.runtimeJarForTests() + File.pathSeparator +
|
||||||
"out/production/runtime.jvm" + File.pathSeparator +
|
|
||||||
JetTestUtils.getAnnotationsJar().getPath();
|
JetTestUtils.getAnnotationsJar().getPath();
|
||||||
JetTestUtils.compileJavaFiles(javaFiles, Arrays.asList(
|
JetTestUtils.compileJavaFiles(javaFiles, Arrays.asList(
|
||||||
"-classpath", classPath,
|
"-classpath", classPath,
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.jetbrains.jet.JetTestUtils;
|
|||||||
import org.jetbrains.jet.TestJdkKind;
|
import org.jetbrains.jet.TestJdkKind;
|
||||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||||
import org.jetbrains.jet.cli.jvm.repl.ReplInterpreter;
|
import org.jetbrains.jet.cli.jvm.repl.ReplInterpreter;
|
||||||
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@@ -46,10 +47,8 @@ public class ReplInterpreterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void testFile(@NotNull String relativePath) {
|
private void testFile(@NotNull String relativePath) {
|
||||||
CompilerConfiguration configuration =
|
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.FULL_JDK);
|
||||||
JetTestUtils.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.FULL_JDK);
|
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, ForTestCompileRuntime.runtimeJarForTests());
|
||||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, new File("out/production/builtins"));
|
|
||||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, new File("out/production/runtime.jvm"));
|
|
||||||
ReplInterpreter repl = new ReplInterpreter(disposable, configuration);
|
ReplInterpreter repl = new ReplInterpreter(disposable, configuration);
|
||||||
|
|
||||||
ReplSessionTestFile file = ReplSessionTestFile.load(new File("compiler/testData/repl/" + relativePath));
|
ReplSessionTestFile file = ReplSessionTestFile.load(new File("compiler/testData/repl/" + relativePath));
|
||||||
|
|||||||
Reference in New Issue
Block a user