ForTestCompileBuiltins and ForTestCompileJdkHeaders
(will be used later)
This commit is contained in:
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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;
|
|
||||||
|
|
||||||
import org.jetbrains.jet.cli.KotlinCompiler;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stepan Koltsov
|
|
||||||
*/
|
|
||||||
public class CompileBuiltinsTest extends TestCaseWithTmpdirIndependentFromIdea {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void compile() {
|
|
||||||
KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec(
|
|
||||||
System.err, "-output", tmpdir.getPath(), "-src", "./compiler/frontend/src", "-mode", "builtins");
|
|
||||||
if (exitCode != KotlinCompiler.ExitCode.OK) {
|
|
||||||
throw new IllegalStateException("jdk headers compilation failed: " + exitCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+14
-2
@@ -16,16 +16,28 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet;
|
package org.jetbrains.jet;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileBuiltins;
|
||||||
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileJdkHeaders;
|
||||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Stepan Koltsov
|
* @author Stepan Koltsov
|
||||||
*/
|
*/
|
||||||
public class CompileStdlibTest {
|
public class CompileCompilerDependenciesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compile() {
|
public void compileBuiltins() {
|
||||||
|
ForTestCompileBuiltins.builtinsJarForTests();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void compileJdkHeaders() {
|
||||||
|
ForTestCompileJdkHeaders.jdkHeadersForTests();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void compileRuntime() {
|
||||||
ForTestCompileRuntime.runtimeJarForTests();
|
ForTestCompileRuntime.runtimeJarForTests();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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;
|
|
||||||
|
|
||||||
import org.jetbrains.jet.cli.KotlinCompiler;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stepan Koltsov
|
|
||||||
*/
|
|
||||||
public class CompileJdkHeadersTest extends TestCaseWithTmpdirIndependentFromIdea {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void compile() {
|
|
||||||
KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec(
|
|
||||||
System.err, "-output", tmpdir.getPath(), "-src", "./jdk-headers/src", "-mode", "jdkHeaders");
|
|
||||||
if (exitCode != KotlinCompiler.ExitCode.OK) {
|
|
||||||
throw new IllegalStateException("jdk headers compilation failed: " + exitCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -30,7 +30,7 @@ public abstract class TestCaseWithTmpdirIndependentFromIdea {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() throws Exception {
|
public void before() throws Exception {
|
||||||
tmpdir = JetTestUtils.tmpDir(CompileJdkHeadersTest.class.getName());
|
tmpdir = JetTestUtils.tmpDir(TestCaseWithTmpdirIndependentFromIdea.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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 org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.cli.KotlinCompiler;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Stepan Koltsov
|
||||||
|
*/
|
||||||
|
public class ForTestCompileBuiltins {
|
||||||
|
|
||||||
|
private ForTestCompileBuiltins() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Builtins extends ForTestCompileSomething {
|
||||||
|
|
||||||
|
Builtins() {
|
||||||
|
super("builtins");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doCompile(@NotNull File classesDir) throws Exception {
|
||||||
|
KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec(
|
||||||
|
System.err, "-output", classesDir.getPath(), "-src", "./compiler/frontend/src", "-mode", "builtins");
|
||||||
|
if (exitCode != KotlinCompiler.ExitCode.OK) {
|
||||||
|
throw new IllegalStateException("jdk headers compilation failed: " + exitCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Builtins builtins = new Builtins();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static File builtinsJarForTests() {
|
||||||
|
return Builtins.builtins.getJarFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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 org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.cli.KotlinCompiler;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Stepan Koltsov
|
||||||
|
*/
|
||||||
|
public class ForTestCompileJdkHeaders {
|
||||||
|
|
||||||
|
private ForTestCompileJdkHeaders() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class JdkHeaders extends ForTestCompileSomething {
|
||||||
|
|
||||||
|
JdkHeaders() {
|
||||||
|
super("jdkHeaders");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doCompile(@NotNull File classesDir) throws Exception {
|
||||||
|
KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec(
|
||||||
|
System.err, "-output", classesDir.getPath(), "-src", "./jdk-headers/src", "-mode", "jdkHeaders");
|
||||||
|
if (exitCode != KotlinCompiler.ExitCode.OK) {
|
||||||
|
throw new IllegalStateException("jdk headers compilation failed: " + exitCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final JdkHeaders jdkHeaders = new JdkHeaders();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static File jdkHeadersForTests() {
|
||||||
|
return JdkHeaders.jdkHeaders.getJarFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
-62
@@ -19,6 +19,7 @@ package org.jetbrains.jet.codegen.forTestCompile;
|
|||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.cli.KotlinCompiler;
|
import org.jetbrains.jet.cli.KotlinCompiler;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@@ -43,57 +44,21 @@ import java.util.jar.JarOutputStream;
|
|||||||
* @author Stepan Koltsov
|
* @author Stepan Koltsov
|
||||||
*/
|
*/
|
||||||
public class ForTestCompileRuntime {
|
public class ForTestCompileRuntime {
|
||||||
private static File runtimeJarFile;
|
|
||||||
|
|
||||||
private ForTestCompileRuntime() {
|
private ForTestCompileRuntime() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File doCompile() throws Exception {
|
private static class Runtime extends ForTestCompileSomething {
|
||||||
File tmpDir = JetTestUtils.tmpDir("runtimejar");
|
private Runtime() {
|
||||||
|
super("runtime");
|
||||||
File jarFile = new File(tmpDir, "runtime.jar");
|
|
||||||
|
|
||||||
File classesDir = new File(tmpDir, "classes");
|
|
||||||
|
|
||||||
FileUtil.createParentDirs(new File(classesDir, "dummy"));
|
|
||||||
compileJavaPartOfBuiltins(classesDir);
|
|
||||||
compileStdlib(classesDir);
|
|
||||||
|
|
||||||
FileOutputStream stdlibJar = new FileOutputStream(jarFile);
|
|
||||||
try {
|
|
||||||
JarOutputStream jarOutputStream = new JarOutputStream(stdlibJar);
|
|
||||||
try {
|
|
||||||
copyToJar(classesDir, jarOutputStream);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
jarOutputStream.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
stdlibJar.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
FileUtil.delete(classesDir);
|
|
||||||
return jarFile;
|
|
||||||
|
|
||||||
}
|
private static final Runtime runtime = new Runtime();
|
||||||
private static void copyToJar(File root, JarOutputStream os) throws IOException {
|
|
||||||
Stack<Pair<String, File>> toCopy = new Stack<Pair<String, File>>();
|
@Override
|
||||||
toCopy.add(new Pair<String, File>("", root));
|
protected void doCompile(@NotNull File classesDir) throws Exception {
|
||||||
while (!toCopy.empty()) {
|
compileJavaPartOfBuiltins(classesDir);
|
||||||
Pair<String, File> pop = toCopy.pop();
|
compileStdlib(classesDir);
|
||||||
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<String, File>(path, child));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,24 +107,9 @@ public class ForTestCompileRuntime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Throwable compilationException;
|
@NotNull
|
||||||
|
|
||||||
public static File runtimeJarForTests() {
|
public static File runtimeJarForTests() {
|
||||||
synchronized (ForTestCompileRuntime.class) {
|
return Runtime.runtime.getJarFile();
|
||||||
if (compilationException != null) {
|
|
||||||
throw new RuntimeException("runtime compilation failed in previous tests: " + compilationException, compilationException);
|
|
||||||
}
|
|
||||||
if (runtimeJarFile == null || !runtimeJarFile.exists()) {
|
|
||||||
try {
|
|
||||||
runtimeJarFile = doCompile();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
compilationException = e;
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return runtimeJarFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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 org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarOutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Stepan Koltsov
|
||||||
|
*/
|
||||||
|
abstract class ForTestCompileSomething {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final String jarName;
|
||||||
|
private Throwable error;
|
||||||
|
private File jarFile;
|
||||||
|
|
||||||
|
ForTestCompileSomething(@NotNull String jarName) {
|
||||||
|
this.jarName = jarName;
|
||||||
|
try {
|
||||||
|
File tmpDir = JetTestUtils.tmpDir("runtimejar");
|
||||||
|
|
||||||
|
jarFile = new File(tmpDir, "runtime.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(stdlibJar);
|
||||||
|
try {
|
||||||
|
copyToJar(classesDir, jarOutputStream);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
jarOutputStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
stdlibJar.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUtil.delete(classesDir);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyToJar(File root, JarOutputStream os) throws IOException {
|
||||||
|
Stack<Pair<String, File>> toCopy = new Stack<Pair<String, File>>();
|
||||||
|
toCopy.add(new Pair<String, File>("", root));
|
||||||
|
while (!toCopy.empty()) {
|
||||||
|
Pair<String, File> 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<String, File>(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user