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