From c012efe64ef64a9d8da95f5967c52347de58777d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 4 Dec 2014 12:26:26 +0300 Subject: [PATCH] Drop compilation of built-ins/stdlib from ForTestCompileRuntime Because the process of building kotlin-runtime.jar will likely get more complicated soon, and that logic will already be present in build.xml. Run "ant compiler-quick runtime" instead before All Tests --- .idea/runConfigurations/All_Tests.xml | 6 +- .../Incremental_Compilation_Tests.xml | 4 +- .../Smart_Completion_Tests.xml | 4 +- .../forTestCompile/ForTestCompileRuntime.java | 102 +--------------- .../ForTestCompileSomething.java | 111 ------------------ .../highlighter/NoErrorsInStdlibTest.kt | 7 +- 6 files changed, 9 insertions(+), 225 deletions(-) delete mode 100644 compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileSomething.java diff --git a/.idea/runConfigurations/All_Tests.xml b/.idea/runConfigurations/All_Tests.xml index 02dd59f813e..3ffa35a501e 100644 --- a/.idea/runConfigurations/All_Tests.xml +++ b/.idea/runConfigurations/All_Tests.xml @@ -22,7 +22,6 @@ - @@ -35,6 +34,9 @@ - + + \ No newline at end of file diff --git a/.idea/runConfigurations/Incremental_Compilation_Tests.xml b/.idea/runConfigurations/Incremental_Compilation_Tests.xml index 0f66f9e2253..b50aaf485ae 100644 --- a/.idea/runConfigurations/Incremental_Compilation_Tests.xml +++ b/.idea/runConfigurations/Incremental_Compilation_Tests.xml @@ -16,9 +16,7 @@ - - - + diff --git a/.idea/runConfigurations/Smart_Completion_Tests.xml b/.idea/runConfigurations/Smart_Completion_Tests.xml index 3f27f24afea..a987ed3950e 100644 --- a/.idea/runConfigurations/Smart_Completion_Tests.xml +++ b/.idea/runConfigurations/Smart_Completion_Tests.xml @@ -21,9 +21,7 @@ - - - + diff --git a/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileRuntime.java b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileRuntime.java index 44dd6dbccad..e0369563d0b 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileRuntime.java +++ b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileRuntime.java @@ -16,113 +16,13 @@ package org.jetbrains.jet.codegen.forTestCompile; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.util.ArrayUtil; -import kotlin.Function1; -import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.JetTestUtils; -import org.jetbrains.jet.cli.common.ExitCode; -import org.jetbrains.jet.cli.jvm.K2JVMCompiler; -import org.jetbrains.jet.utils.Profiler; -import org.jetbrains.jet.utils.UtilsPackage; import java.io.File; -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 - * - * @see #runtimeJarForTests - */ public class ForTestCompileRuntime { - private static final String[] PATHS = { - "core/builtins/src", "core/runtime.jvm/src", "core/reflection/src", "core/reflection.jvm/src" - }; - - private ForTestCompileRuntime() { - } - - private static class Runtime extends ForTestCompileSomething { - private Runtime() { - super("runtime"); - } - - private static final Runtime runtime = new Runtime(); - - @Override - protected void doCompile(@NotNull File classesDir) throws Exception { - compileBuiltIns(classesDir); - compileStdlib(classesDir); - } - } - - public static void compileBuiltIns(@NotNull File destDir) throws IOException { - compileKotlinToJvm("built-ins", destDir, UtilsPackage.join(Arrays.asList(PATHS), File.pathSeparator), PATHS); - - JetTestUtils.compileJavaFiles( - javaFilesUnder(PATHS), - Arrays.asList( - "-classpath", destDir.getPath(), - "-d", destDir.getPath() - ) - ); - } - - @NotNull - private static List javaFilesUnder(@NotNull String... paths) { - return KotlinPackage.flatMap(Arrays.asList(paths), new Function1>() { - @Override - public List invoke(String path) { - return FileUtil.findFilesByMask(Pattern.compile(".*\\.java"), new File(path)); - } - }); - } - - private static void compileStdlib(@NotNull File destDir) throws IOException { - compileKotlinToJvm("stdlib", destDir, destDir.getPath(), "libraries/stdlib/src"); - } - - private static void compileKotlinToJvm( - @NotNull String debugName, - @NotNull File destDir, - @NotNull String classPath, - @NotNull String... src - ) { - List args = KotlinPackage.arrayListOf( - "-d", destDir.getPath(), - "-no-stdlib", - "-no-jdk-annotations", - "-nowarn", - "-annotations", JetTestUtils.getJdkAnnotationsJar().getAbsolutePath(), - "-classpath", classPath - ); - args.addAll(Arrays.asList(src)); - ExitCode exitCode = new K2JVMCompiler().exec(System.out, ArrayUtil.toStringArray(args)); - if (exitCode != ExitCode.OK) { - throw new IllegalStateException("Compilation of " + debugName + " failed: " + exitCode); - } - } - @NotNull public static File runtimeJarForTests() { - return ForTestCompileSomething.ACTUALLY_COMPILE ? Runtime.runtime.getJarFile() : new File("dist/kotlinc/lib/kotlin-runtime.jar"); + return new File("dist/kotlinc/lib/kotlin-runtime.jar"); } - - // This method is very convenient when you have trouble compiling runtime in tests - 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(); - compileStdlib(destDir); - stdlib.end(); - } - } diff --git a/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileSomething.java b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileSomething.java deleted file mode 100644 index 2dbf60693e0..00000000000 --- a/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileSomething.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.codegen.forTestCompile; - -import com.google.common.io.Files; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.util.containers.Stack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.JetTestUtils; -import org.jetbrains.jet.TimeUtils; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.jar.JarEntry; -import java.util.jar.JarOutputStream; - -abstract class ForTestCompileSomething { - - public static final boolean ACTUALLY_COMPILE = "true".equals(System.getenv("kotlin.tests.actually.compile")); - - @NotNull - private final String jarName; - private Throwable error; - private File jarFile; - - ForTestCompileSomething(@NotNull String jarName) { - System.out.println("Compiling " + jarName + "..."); - long start = System.currentTimeMillis(); - this.jarName = jarName; - try { - File tmpDir = JetTestUtils.tmpDir("test_jars"); - - jarFile = new File(tmpDir, jarName + ".jar"); - - File classesDir = new File(tmpDir, "classes"); - - FileUtil.createParentDirs(new File(classesDir, "dummy")); - - doCompile(classesDir); - - FileOutputStream stdlibJar = new FileOutputStream(jarFile); - try { - JarOutputStream jarOutputStream = new JarOutputStream(new BufferedOutputStream(stdlibJar)); - try { - copyToJar(classesDir, jarOutputStream); - } - finally { - jarOutputStream.close(); - } - } - finally { - stdlibJar.close(); - } - - FileUtil.delete(classesDir); - long end = System.currentTimeMillis(); - System.out.println("Compiling " + jarName + " done in " + TimeUtils.millisecondsToSecondsString(end - start) + "s"); - } catch (Throwable e) { - error = e; - } - } - - static void copyToJar(File root, JarOutputStream os) throws IOException { - Stack> toCopy = new Stack>(); - toCopy.add(new Pair("", root)); - while (!toCopy.empty()) { - Pair pop = toCopy.pop(); - File file = pop.getSecond(); - if (file.isFile()) { - os.putNextEntry(new JarEntry(pop.getFirst())); - Files.copy(file, os); - } - else if (file.isDirectory()) { - for (File child : file.listFiles()) { - String path = pop.getFirst().isEmpty() ? child.getName() : pop.getFirst() + "/" + child.getName(); - toCopy.add(new Pair(path, child)); - } - } - else { - throw new IllegalStateException(); - } - } - } - - protected abstract void doCompile(@NotNull File classesDir) throws Exception; - - @NotNull - public File getJarFile() { - if (error != null) { - throw new IllegalStateException("compilation of " + jarName + " failed: " + error, error); - } - return jarFile; - } -} diff --git a/idea/tests/org/jetbrains/jet/plugin/highlighter/NoErrorsInStdlibTest.kt b/idea/tests/org/jetbrains/jet/plugin/highlighter/NoErrorsInStdlibTest.kt index e9edaf76552..207dcd2541b 100644 --- a/idea/tests/org/jetbrains/jet/plugin/highlighter/NoErrorsInStdlibTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/highlighter/NoErrorsInStdlibTest.kt @@ -27,10 +27,9 @@ import org.jetbrains.jet.plugin.PluginTestCaseBase import kotlin.test.assertEquals import org.jetbrains.jet.plugin.caches.resolve.analyzeFully import org.jetbrains.jet.lang.diagnostics.Severity -import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime -import org.jetbrains.jet.JetTestUtils import kotlin.test.assertTrue import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase +import java.io.File public class NoErrorsInStdlibTest : JetLightCodeInsightFixtureTestCase() { public fun testNoErrors() { @@ -68,9 +67,7 @@ public class NoErrorsInStdlibTest : JetLightCodeInsightFixtureTestCase() { } override fun getProjectDescriptor(): LightProjectDescriptor { - val dir = JetTestUtils.tmpDir("noErrorsInStdlibTest") - ForTestCompileRuntime.compileBuiltIns(dir) - return object : JetJdkAndLibraryProjectDescriptor(dir) { + return object : JetJdkAndLibraryProjectDescriptor(File("dist/classes/builtins")) { override fun getSdk(): Sdk? = PluginTestCaseBase.fullJdk() } }