Finally drop attaching stdlib sources everywhere
This commit is contained in:
@@ -4,6 +4,7 @@ examples/.idea/workspace.xml
|
||||
confluence/target
|
||||
confluence/target
|
||||
out
|
||||
dist
|
||||
ideaSDK
|
||||
.idea/dictionaries/yozh.xml
|
||||
.idea/codeStyleSettings.xml
|
||||
|
||||
Generated
+1
-1
@@ -1,7 +1,7 @@
|
||||
<component name="libraryTable">
|
||||
<library name="idea-full">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/IdeaSDK/lib" />
|
||||
<root url="file://$PROJECT_DIR$/ideaSDK/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
|
||||
Generated
+1
-1
@@ -1,7 +1,7 @@
|
||||
<component name="libraryTable">
|
||||
<library name="intellij-core">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/IdeaSDK/core" />
|
||||
<root url="file://$PROJECT_DIR$/ideaSDK/core" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
|
||||
Generated
+1
@@ -4,6 +4,7 @@
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Jet.iml" filepath="$PROJECT_DIR$/Jet.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/backend/backend.iml" filepath="$PROJECT_DIR$/compiler/backend/backend.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/build-tools/build-tools.iml" filepath="$PROJECT_DIR$/build-tools/build-tools.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/cli/cli.iml" filepath="$PROJECT_DIR$/compiler/cli/cli.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/tests/compiler-tests.iml" filepath="$PROJECT_DIR$/compiler/tests/compiler-tests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/examples/examples.iml" filepath="$PROJECT_DIR$/examples/examples.iml" />
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/core/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="cli" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -20,15 +20,7 @@ public class BytecodeCompiler {
|
||||
* @return new {@link CompileEnvironment} instance
|
||||
*/
|
||||
private CompileEnvironment createCompileEnvironment () {
|
||||
|
||||
CompileEnvironment environment = new CompileEnvironment();
|
||||
environment.setJavaRuntime( CompileEnvironment.findRtJar( true ));
|
||||
|
||||
if ( ! environment.initializeKotlinRuntime()) {
|
||||
throw new RuntimeException( "No Kotlin runtime library found" );
|
||||
}
|
||||
|
||||
return environment;
|
||||
return new CompileEnvironment();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +42,7 @@ public class BytecodeCompiler {
|
||||
* @param excludeStdlib whether Kotlin standard library is excluded in compilation
|
||||
*/
|
||||
public void sourcesToDir ( String source, String destination, boolean excludeStdlib ) {
|
||||
boolean success = ENV.compileBunchOfSources( source, null, destination, true, ! excludeStdlib );
|
||||
boolean success = ENV.compileBunchOfSources( source, null, destination, true);
|
||||
if ( ! success ) {
|
||||
throw new RuntimeException( compilationError( source ));
|
||||
}
|
||||
@@ -66,7 +58,7 @@ public class BytecodeCompiler {
|
||||
* @param excludeStdlib whether Kotlin standard library is excluded in compilation
|
||||
*/
|
||||
public void sourcesToJar ( String source, String jar, boolean includeRuntime, boolean excludeStdlib ) {
|
||||
boolean success = ENV.compileBunchOfSources( source, jar, null, includeRuntime, ! excludeStdlib );
|
||||
boolean success = ENV.compileBunchOfSources( source, jar, null, includeRuntime);
|
||||
if ( ! success ) {
|
||||
throw new RuntimeException( compilationError( source ));
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
<path id="classpath">
|
||||
<fileset dir="${idea.sdk}" includes="*.jar"/>
|
||||
<fileset dir="${idea.sdk}" includes="core/*.jar"/>
|
||||
<fileset dir="${basedir}/lib" includes="*.jar"/>
|
||||
<pathelement path="${output}/classes/runtime"/>
|
||||
</path>
|
||||
@@ -38,23 +39,25 @@
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compileStdlib" depends="compile">
|
||||
<target name="compileStdlib" depends="jar">
|
||||
<mkdir dir="${output}/classes/stdlib"/>
|
||||
<java classname="org.jetbrains.jet.cli.KotlinCompiler">
|
||||
<classpath refid="classpath.kotlin"/>
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
<pathelement location="${output}/kotlin-compiler.jar"/>
|
||||
</classpath>
|
||||
<arg value="-excludeStdlib"/>
|
||||
<arg value="-src"/>
|
||||
<arg value="${basedir}/stdlib/ktSrc"/>
|
||||
<arg value="-output"/>
|
||||
<arg value="${basedir}/classes/stdlib"/>
|
||||
<arg value="${output}/classes/stdlib"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="jarRT" depends="compile">
|
||||
<target name="jarRT" depends="compile,compileStdlib">
|
||||
<jar destfile="${output}/kotlin-runtime.jar">
|
||||
<fileset dir="${output}/classes/runtime"/>
|
||||
<!--<fileset dir="${output}/classes/stdlib"/>-->
|
||||
<fileset dir="${basedir}" includes="stdlib/ktSrc/**/*"/>
|
||||
<fileset dir="${output}/classes/stdlib"/>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
|
||||
@@ -19,16 +19,22 @@ public class KotlinCompiler {
|
||||
public static class Arguments {
|
||||
@Argument(value = "output", description = "output directory")
|
||||
public String outputDir;
|
||||
|
||||
@Argument(value = "jar", description = "jar file name")
|
||||
public String jar;
|
||||
|
||||
@Argument(value = "src", description = "source file or directory")
|
||||
public String src;
|
||||
|
||||
@Argument(value = "module", description = "module to compile")
|
||||
public String module;
|
||||
|
||||
@Argument(value = "includeRuntime", description = "include Kotlin runtime in to resulting jar")
|
||||
public boolean includeRuntime;
|
||||
@Argument(value = "excludeStdlib", description = "do not load stdlib (to compile stdlib itself)")
|
||||
public boolean excludeStdlib;
|
||||
|
||||
@Argument(value = "stdlib", description = "Path to the stdlib.jar")
|
||||
public String stdlib;
|
||||
|
||||
@Argument(value = "help", alias = "h", description = "show help")
|
||||
public boolean help;
|
||||
}
|
||||
@@ -61,20 +67,17 @@ public class KotlinCompiler {
|
||||
|
||||
CompileEnvironment environment = new CompileEnvironment();
|
||||
|
||||
try {
|
||||
environment.setJavaRuntime(CompileEnvironment.findRtJar());
|
||||
if (!environment.initializeKotlinRuntime()) {
|
||||
System.err.println("No Kotlin runtime library found");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
if (arguments.stdlib != null) {
|
||||
environment.setStdlib(arguments.stdlib);
|
||||
}
|
||||
|
||||
try {
|
||||
if (arguments.module != null) {
|
||||
environment.compileModuleScript(arguments.module, arguments.jar, arguments.includeRuntime);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (!environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime, !arguments.excludeStdlib)) {
|
||||
if (!environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime)) {
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package org.jetbrains.jet.compiler;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.Processor;
|
||||
import jet.modules.AllModules;
|
||||
import jet.modules.Module;
|
||||
@@ -16,7 +19,9 @@ import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.List;
|
||||
import java.util.jar.*;
|
||||
|
||||
@@ -29,6 +34,7 @@ public class CompileEnvironment {
|
||||
private JetCoreEnvironment myEnvironment;
|
||||
private final Disposable myRootDisposable;
|
||||
private PrintStream myErrorStream = System.out;
|
||||
private URL myStdlib;
|
||||
|
||||
public CompileEnvironment() {
|
||||
myRootDisposable = new Disposable() {
|
||||
@@ -47,27 +53,6 @@ public class CompileEnvironment {
|
||||
Disposer.dispose(myRootDisposable);
|
||||
}
|
||||
|
||||
public boolean initializeKotlinRuntime() {
|
||||
return initializeKotlinRuntime(myEnvironment);
|
||||
}
|
||||
|
||||
public static boolean initializeKotlinRuntime(JetCoreEnvironment environment) {
|
||||
final File unpackedRuntimePath = getUnpackedRuntimePath();
|
||||
if (unpackedRuntimePath != null) {
|
||||
environment.addToClasspath(unpackedRuntimePath);
|
||||
}
|
||||
else {
|
||||
final File runtimeJarPath = getRuntimeJarPath();
|
||||
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||
environment.addToClasspath(runtimeJarPath);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static File getUnpackedRuntimePath() {
|
||||
URL url = CompileEnvironment.class.getClassLoader().getResource("jet/JetObject.class");
|
||||
if (url != null && url.getProtocol().equals("file")) {
|
||||
@@ -85,10 +70,25 @@ public class CompileEnvironment {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setJavaRuntime(File rtJarPath) {
|
||||
myEnvironment.addToClasspath(rtJarPath);
|
||||
public void ensureRuntime() {
|
||||
ensureRuntime(myEnvironment);
|
||||
}
|
||||
|
||||
|
||||
public static void ensureRuntime(JetCoreEnvironment env) {
|
||||
Project project = env.getProject();
|
||||
if (JavaPsiFacade.getInstance(project).findClass("java.lang.Obect", GlobalSearchScope.allScope(project)) == null) {
|
||||
// TODO: prepend
|
||||
env.addToClasspath(findRtJar());
|
||||
}
|
||||
|
||||
if (JavaPsiFacade.getInstance(project).findClass("jet.JetObject", GlobalSearchScope.allScope(project)) == null) {
|
||||
// TODO: prepend
|
||||
File kotlin = getUnpackedRuntimePath();
|
||||
if (kotlin == null) kotlin = getRuntimeJarPath();
|
||||
env.addToClasspath(kotlin);
|
||||
}
|
||||
}
|
||||
|
||||
public static File findRtJar() {
|
||||
String javaHome = System.getProperty("java.home");
|
||||
if ("jre".equals(new File(javaHome).getName())) {
|
||||
@@ -139,7 +139,7 @@ public class CompileEnvironment {
|
||||
public List<Module> loadModuleScript(String moduleFile) {
|
||||
CompileSession scriptCompileSession = new CompileSession(myEnvironment);
|
||||
scriptCompileSession.addSources(moduleFile);
|
||||
scriptCompileSession.addStdLibSources(true);
|
||||
ensureRuntime();
|
||||
|
||||
if (!scriptCompileSession.analyze(myErrorStream)) {
|
||||
return null;
|
||||
@@ -149,8 +149,8 @@ public class CompileEnvironment {
|
||||
return runDefineModules(moduleFile, factory);
|
||||
}
|
||||
|
||||
private static List<Module> runDefineModules(String moduleFile, ClassFileFactory factory) {
|
||||
GeneratedClassLoader loader = new GeneratedClassLoader(factory);
|
||||
private List<Module> runDefineModules(String moduleFile, ClassFileFactory factory) {
|
||||
ClassLoader loader = myStdlib != null ? new GeneratedClassLoader(factory, new URLClassLoader(new URL[] {myStdlib})) : new GeneratedClassLoader(factory);
|
||||
try {
|
||||
Class namespaceClass = loader.loadClass(JvmAbi.PACKAGE_CLASS);
|
||||
final Method method = namespaceClass.getDeclaredMethod("project");
|
||||
@@ -163,16 +163,12 @@ public class CompileEnvironment {
|
||||
|
||||
return AllModules.modules;
|
||||
} catch (Exception e) {
|
||||
throw new CompileEnvironmentException(e);
|
||||
throw new ModuleExecutionException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ClassFileFactory compileModule(Module moduleBuilder, String directory) {
|
||||
CompileSession moduleCompileSession = new CompileSession(myEnvironment);
|
||||
if (!"stdlib".equals(moduleBuilder.getModuleName())) {
|
||||
moduleCompileSession.addStdLibSources(false);
|
||||
}
|
||||
|
||||
for (String sourceFile : moduleBuilder.getSourceFiles()) {
|
||||
File source = new File(sourceFile);
|
||||
if (!source.isAbsolute()) {
|
||||
@@ -182,9 +178,11 @@ public class CompileEnvironment {
|
||||
moduleCompileSession.addSources(source.getPath());
|
||||
}
|
||||
for (String classpathRoot : moduleBuilder.getClasspathRoots()) {
|
||||
if (classpathRoot.contains("/stdlib/") || classpathRoot.contains("\\stdlib\\")) continue; // TODO: We have source-level dependency on stdlib for now
|
||||
myEnvironment.addToClasspath(new File(classpathRoot));
|
||||
}
|
||||
|
||||
ensureRuntime();
|
||||
|
||||
if (!moduleCompileSession.analyze(myErrorStream)) {
|
||||
return null;
|
||||
}
|
||||
@@ -268,12 +266,9 @@ public class CompileEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime, boolean includeSources) {
|
||||
public boolean compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
session.addSources(sourceFileOrDir);
|
||||
if (includeSources) {
|
||||
session.addStdLibSources(false);
|
||||
}
|
||||
|
||||
String mainClass = null;
|
||||
for (JetFile file : session.getSourceFileNamespaces()) {
|
||||
@@ -282,6 +277,9 @@ public class CompileEnvironment {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ensureRuntime();
|
||||
|
||||
if (!session.analyze(myErrorStream)) {
|
||||
return false;
|
||||
}
|
||||
@@ -314,4 +312,20 @@ public class CompileEnvironment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setStdlib(String stdlib) {
|
||||
File path = new File(stdlib);
|
||||
if (!path.exists()) {
|
||||
throw new CompileEnvironmentException("'" + stdlib + "' does not exist");
|
||||
}
|
||||
|
||||
try {
|
||||
myStdlib = path.toURL();
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
myEnvironment.addToClasspath(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.GenerationState;
|
||||
@@ -125,6 +126,7 @@ public class CompileSession {
|
||||
return generationState.createText();
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public boolean addStdLibSources(boolean toModuleSources) {
|
||||
final File unpackedRuntimePath = CompileEnvironment.getUnpackedRuntimePath();
|
||||
if (unpackedRuntimePath != null) {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.jetbrains.jet.compiler;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class ModuleExecutionException extends RuntimeException {
|
||||
public ModuleExecutionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ModuleExecutionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ModuleExecutionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.io.Files;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
@@ -15,12 +14,7 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Stack;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
|
||||
@@ -31,7 +25,7 @@ import java.util.jar.JarOutputStream;
|
||||
*
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
class ForTestCompileStdlib {
|
||||
public class ForTestCompileStdlib {
|
||||
|
||||
public static final File stdlibJarForTests = new File(
|
||||
JetTestUtils.tmpDirForTest(ForTestCompileStdlib.class), "stdlib.jar");
|
||||
@@ -107,7 +101,7 @@ class ForTestCompileStdlib {
|
||||
|
||||
private static void compileKotlinPartOfStdlib(File destdir) throws IOException {
|
||||
// lame
|
||||
KotlinCompiler.main("-excludeStdlib", "-output", destdir.getPath(), "-src", "./stdlib/ktSrc");
|
||||
KotlinCompiler.main("-output", destdir.getPath(), "-src", "./stdlib/ktSrc");
|
||||
}
|
||||
|
||||
private static List<File> javaFilesInDir(File dir) {
|
||||
|
||||
@@ -37,9 +37,11 @@ public class StdlibTest extends CodegenTestCase {
|
||||
protected ClassFileFactory generateClassesInFile() {
|
||||
try {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
CompileEnvironment.initializeKotlinRuntime(myEnvironment);
|
||||
session.addSources(myFile.getVirtualFile());
|
||||
|
||||
session.addStdLibSources(true);
|
||||
session.addSources(myFile.getVirtualFile());
|
||||
|
||||
CompileEnvironment.ensureRuntime(myEnvironment);
|
||||
|
||||
if (!session.analyze(System.out)) {
|
||||
throw new RuntimeException();
|
||||
|
||||
+8
-25
@@ -5,7 +5,6 @@ import com.intellij.openapi.vfs.local.CoreLocalFileSystem;
|
||||
import gnu.trove.THashSet;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileSession;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
@@ -20,19 +19,15 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public abstract class TestlibTestBase extends CodegenTestCase {
|
||||
public class TestlibTest extends CodegenTestCase {
|
||||
|
||||
/** Binary or source */
|
||||
private final boolean binary;
|
||||
|
||||
protected TestlibTestBase(boolean binary) {
|
||||
this.binary = binary;
|
||||
public static TestSuite suite() {
|
||||
return new TestlibTest().buildSuite();
|
||||
}
|
||||
|
||||
protected TestSuite buildSuite() {
|
||||
@@ -58,12 +53,8 @@ public abstract class TestlibTestBase extends CodegenTestCase {
|
||||
private TestSuite doBuildSuite() {
|
||||
try {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
|
||||
if (binary) {
|
||||
myEnvironment.addToClasspath(ForTestCompileStdlib.stdlibJarForTests());
|
||||
} else {
|
||||
CompileEnvironment.initializeKotlinRuntime(myEnvironment);
|
||||
}
|
||||
|
||||
myEnvironment.addToClasspath(ForTestCompileStdlib.stdlibJarForTests());
|
||||
|
||||
File junitJar = new File("testlib/lib/junit-4.9.jar");
|
||||
|
||||
@@ -77,10 +68,6 @@ public abstract class TestlibTestBase extends CodegenTestCase {
|
||||
VirtualFile path = localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../testlib/test");
|
||||
session.addSources(path);
|
||||
|
||||
if (!binary) {
|
||||
session.addStdLibSources(true);
|
||||
}
|
||||
|
||||
if (!session.analyze(System.out)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
@@ -89,13 +76,9 @@ public abstract class TestlibTestBase extends CodegenTestCase {
|
||||
|
||||
URLClassLoader dependenciesClassLoader = new URLClassLoader(new URL[] { junitJar.toURI().toURL() });
|
||||
GeneratedClassLoader loader;
|
||||
if (binary) {
|
||||
URLClassLoader parentClassLoader = new URLClassLoader(new URL[]{
|
||||
ForTestCompileStdlib.stdlibJarForTests().toURI().toURL() }, dependenciesClassLoader);
|
||||
loader = new GeneratedClassLoader(classFileFactory, parentClassLoader);
|
||||
} else {
|
||||
loader = new GeneratedClassLoader(classFileFactory, dependenciesClassLoader);
|
||||
}
|
||||
URLClassLoader parentClassLoader = new URLClassLoader(new URL[]{
|
||||
ForTestCompileStdlib.stdlibJarForTests().toURI().toURL()}, dependenciesClassLoader);
|
||||
loader = new GeneratedClassLoader(classFileFactory, parentClassLoader);
|
||||
|
||||
JetTypeMapper typeMapper = new JetTypeMapper(classFileFactory.state.getStandardLibrary(), session.getMyBindingContext());
|
||||
TestSuite suite = new TestSuite("StandardLibrary");
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class TestlibWithStdlibBinaryTest extends TestlibTestBase {
|
||||
|
||||
protected TestlibWithStdlibBinaryTest() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestlibWithStdlibBinaryTest().buildSuite();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class TestlibWithStdlibSrcTest extends TestlibTestBase {
|
||||
|
||||
protected TestlibWithStdlibSrcTest() {
|
||||
super(false);
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestlibWithStdlibSrcTest().buildSuite();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package org.jetbrains.jet.compiler;
|
||||
|
||||
import jet.modules.Module;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.jet.cli.KotlinCompiler;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.ForTestCompileStdlib;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
@@ -31,30 +32,17 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void _testSmoke() throws IOException {
|
||||
final File activeRtJar = CompileEnvironment.findRtJar();
|
||||
environment.setJavaRuntime(activeRtJar);
|
||||
environment.initializeKotlinRuntime();
|
||||
final String testDataDir = JetParsingTest.getTestDataDir() + "/compiler/smoke/";
|
||||
final List<Module> modules = environment.loadModuleScript(testDataDir + "Smoke.kts");
|
||||
assertEquals(1, modules.size());
|
||||
final Module moduleBuilder = modules.get(0);
|
||||
final ClassFileFactory factory = environment.compileModule(moduleBuilder, testDataDir);
|
||||
assertNotNull(factory);
|
||||
assertNotNull(factory.asBytes("Smoke/namespace.class"));
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
CompileEnvironment.writeToJar(factory, baos, null, false);
|
||||
JarInputStream is = new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
||||
final List<String> entries = listEntries(is);
|
||||
assertTrue(entries.contains("Smoke/namespace.class"));
|
||||
}
|
||||
|
||||
public void testSmokeWithCompilerJar() throws IOException {
|
||||
File tempFile = File.createTempFile("compilerTest", "compilerTest");
|
||||
File tempDir = FileUtil.createTempDirectory("compilerTest", "compilerTest");
|
||||
|
||||
try {
|
||||
KotlinCompiler.main(Arrays.asList("-module", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts", "-jar", tempFile.getAbsolutePath()).toArray(new String[0]));
|
||||
FileInputStream fileInputStream = new FileInputStream(tempFile);
|
||||
File stdlib = new File(tempDir, "stdlib.jar");
|
||||
FileUtil.copy(ForTestCompileStdlib.stdlibJarForTests(), stdlib);
|
||||
File resultJar = new File(tempDir, "result.jar");
|
||||
KotlinCompiler.main("-module", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts",
|
||||
"-jar", resultJar.getAbsolutePath(),
|
||||
"-stdlib", stdlib.getAbsolutePath());
|
||||
FileInputStream fileInputStream = new FileInputStream(resultJar);
|
||||
try {
|
||||
JarInputStream is = new JarInputStream(fileInputStream);
|
||||
try {
|
||||
@@ -71,33 +59,24 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
tempFile.delete();
|
||||
FileUtil.delete(tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean delete(File file) {
|
||||
boolean success = true;
|
||||
if(file.isDirectory()) {
|
||||
for (File child : file.listFiles()) {
|
||||
success = success && delete(child);
|
||||
}
|
||||
}
|
||||
|
||||
return file.delete() && success;
|
||||
}
|
||||
|
||||
public void testSmokeWithCompilerOutput() throws IOException {
|
||||
File tempFile = File.createTempFile("compilerTest", "compilerTest");
|
||||
tempFile.delete();
|
||||
tempFile = new File(tempFile.getAbsolutePath());
|
||||
tempFile.mkdir();
|
||||
File tempDir = FileUtil.createTempDirectory("compilerTest", "compilerTest");
|
||||
try {
|
||||
KotlinCompiler.main(Arrays.asList("-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt", "-output", tempFile.getAbsolutePath()).toArray(new String[0]));
|
||||
assertEquals(1, tempFile.listFiles().length);
|
||||
assertEquals(1, tempFile.listFiles()[0].listFiles().length);
|
||||
}
|
||||
finally {
|
||||
delete(tempFile);
|
||||
File out = new File(tempDir, "out");
|
||||
File stdlib = new File(tempDir, "stdlib.jar");
|
||||
FileUtil.copy(ForTestCompileStdlib.stdlibJarForTests(), stdlib);
|
||||
KotlinCompiler.main("-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt",
|
||||
"-output", out.getAbsolutePath(),
|
||||
"-stdlib", stdlib.getAbsolutePath());
|
||||
|
||||
assertEquals(1, out.listFiles().length);
|
||||
assertEquals(1, out.listFiles()[0].listFiles().length);
|
||||
} finally {
|
||||
FileUtil.delete(tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user