Rename CompileEnvironmentConfiguration. Drop ArgsUtil class. Add CompilerSpecialMode.JS.

This commit is contained in:
pTalanov
2012-05-02 15:23:40 +04:00
parent c7d5f79ec8
commit ce929fab49
14 changed files with 75 additions and 112 deletions
@@ -42,17 +42,18 @@ public class BytecodeCompiler {
/** /**
* Creates new instance of {@link org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration} instance using the arguments specified. * Creates new instance of {@link org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration} instance using the arguments specified.
* *
* @param stdlib path to "kotlin-runtime.jar", only used if not null and not empty * @param stdlib path to "kotlin-runtime.jar", only used if not null and not empty
* @param classpath compilation classpath, only used if not null and not empty * @param classpath compilation classpath, only used if not null and not empty
* *
* @return compile environment instance * @return compile environment instance
*/ */
private CompileEnvironmentConfiguration env( String stdlib, String[] classpath ) { private K2JVMCompileEnvironmentConfiguration env( String stdlib, String[] classpath ) {
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR); CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
JetCoreEnvironment environment = new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), dependencies); JetCoreEnvironment environment = new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), dependencies);
CompileEnvironmentConfiguration env = new CompileEnvironmentConfiguration(environment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR); K2JVMCompileEnvironmentConfiguration
env = new K2JVMCompileEnvironmentConfiguration(environment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
if (( stdlib != null ) && ( stdlib.trim().length() > 0 )) { if (( stdlib != null ) && ( stdlib.trim().length() > 0 )) {
File file = new File(stdlib); File file = new File(stdlib);
@@ -140,7 +141,7 @@ public class BytecodeCompiler {
*/ */
public void moduleToJar ( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) { public void moduleToJar ( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) {
try { try {
CompileEnvironmentConfiguration env = env(stdlib, classpath); K2JVMCompileEnvironmentConfiguration env = env(stdlib, classpath);
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(module, env.getMessageCollector()); List<Module> modules = CompileEnvironmentUtil.loadModuleScript(module, env.getMessageCollector());
File directory = new File(module).getParentFile(); File directory = new File(module).getParentFile();
boolean success = KotlinToJVMBytecodeCompiler.compileModules(env, modules, directory, jar, null, includeRuntime); boolean success = KotlinToJVMBytecodeCompiler.compileModules(env, modules, directory, jar, null, includeRuntime);
@@ -1,49 +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.cli.common;
import com.sampullara.cli.Args;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments;
import java.io.PrintStream;
/**
* @author Pavel Talanov
*/
public final class ArgsUtil {
private ArgsUtil() {
}
public static void printUsage(@NotNull PrintStream target, @NotNull CompilerArguments exampleInstance) {
// We should say something like
// Args.usage(target, K2JVMCompilerArguments.class);
// but currently cli-parser we are using does not support that
// a corresponding patch has been sent to the authors
// For now, we are using this:
PrintStream oldErr = System.err;
System.setErr(target);
try {
// TODO: use proper argv0
Args.usage(exampleInstance);
}
finally {
System.setErr(oldErr);
}
}
}
@@ -33,11 +33,11 @@ import static org.jetbrains.jet.cli.common.ExitCode.OK;
/** /**
* @author Pavel Talanov * @author Pavel Talanov
*/ */
public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf extends CompileEnvironmentConfig> { public abstract class CLICompiler<A extends CompilerArguments, C extends CompileEnvironmentConfiguration> {
@NotNull @NotNull
public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) { public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) {
CLArgs arguments = createArguments(); A arguments = createArguments();
if (!parseArguments(errStream, arguments, args)) { if (!parseArguments(errStream, arguments, args)) {
return INTERNAL_ERROR; return INTERNAL_ERROR;
} }
@@ -47,7 +47,7 @@ public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf exten
/** /**
* Returns true if the arguments can be parsed correctly * Returns true if the arguments can be parsed correctly
*/ */
protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull CLArgs arguments, @NotNull String[] args) { protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull A arguments, @NotNull String[] args) {
try { try {
Args.parse(arguments, args); Args.parse(arguments, args);
return true; return true;
@@ -66,26 +66,40 @@ public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf exten
* Allow derived classes to add additional command line arguments * Allow derived classes to add additional command line arguments
*/ */
protected void usage(@NotNull PrintStream target) { protected void usage(@NotNull PrintStream target) {
ArgsUtil.printUsage(target, createArguments()); // We should say something like
// Args.usage(target, K2JVMCompilerArguments.class);
// but currently cli-parser we are using does not support that
// a corresponding patch has been sent to the authors
// For now, we are using this:
PrintStream oldErr = System.err;
System.setErr(target);
try {
// TODO: use proper argv0
Args.usage(createArguments());
}
finally {
System.setErr(oldErr);
}
} }
/** /**
* Strategy method to configure the environment, allowing compiler * Strategy method to configure the environment, allowing compiler
* based tools to customise their own plugins * based tools to customise their own plugins
*/ */
protected void configureEnvironment(@NotNull CEConf configuration, @NotNull CLArgs arguments) { //TODO: add parameter annotations when KT-1863 is resolved
protected void configureEnvironment(C configuration, A arguments) {
List<CompilerPlugin> plugins = arguments.getCompilerPlugins(); List<CompilerPlugin> plugins = arguments.getCompilerPlugins();
configuration.getCompilerPlugins().addAll(plugins); configuration.getCompilerPlugins().addAll(plugins);
} }
@NotNull @NotNull
protected abstract CLArgs createArguments(); protected abstract A createArguments();
/** /**
* Executes the compiler on the parsed arguments * Executes the compiler on the parsed arguments
*/ */
@NotNull @NotNull
public ExitCode exec(final PrintStream errStream, CLArgs arguments) { public ExitCode exec(final PrintStream errStream, A arguments) {
if (arguments.isHelp()) { if (arguments.isHelp()) {
usage(errStream); usage(errStream);
return OK; return OK;
@@ -104,15 +118,15 @@ public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf exten
//TODO: can't declare parameters as not null due to KT-1863 //TODO: can't declare parameters as not null due to KT-1863
@NotNull @NotNull
protected abstract ExitCode doExecute(PrintStream stream, CLArgs arguments, MessageRenderer renderer); protected abstract ExitCode doExecute(PrintStream stream, A arguments, MessageRenderer renderer);
@NotNull @NotNull
private MessageRenderer getMessageRenderer(@NotNull CLArgs arguments) { private MessageRenderer getMessageRenderer(@NotNull A arguments) {
return arguments.isTags() ? MessageRenderer.TAGS : MessageRenderer.PLAIN; return arguments.isTags() ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
} }
protected void printVersionIfNeeded(@NotNull PrintStream errStream, protected void printVersionIfNeeded(@NotNull PrintStream errStream,
@NotNull CLArgs arguments, @NotNull A arguments,
@NotNull MessageRenderer messageRenderer) { @NotNull MessageRenderer messageRenderer) {
if (arguments.isVersion()) { if (arguments.isVersion()) {
String versionMessage = messageRenderer.render(CompilerMessageSeverity.INFO, String versionMessage = messageRenderer.render(CompilerMessageSeverity.INFO,
@@ -26,7 +26,7 @@ import java.util.List;
/** /**
* @author Pavel Talanov * @author Pavel Talanov
*/ */
public abstract class CompileEnvironmentConfig { public abstract class CompileEnvironmentConfiguration {
@NotNull @NotNull
private final MessageCollector messageCollector; private final MessageCollector messageCollector;
@@ -38,7 +38,7 @@ public abstract class CompileEnvironmentConfig {
* *
* @see Disposer * @see Disposer
*/ */
public CompileEnvironmentConfig(@NotNull MessageCollector messageCollector) { public CompileEnvironmentConfiguration(@NotNull MessageCollector messageCollector) {
this.messageCollector = messageCollector; this.messageCollector = messageCollector;
} }
@@ -18,13 +18,13 @@ package org.jetbrains.jet.cli.js;
import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.CompileEnvironmentConfig; import org.jetbrains.jet.cli.common.CompileEnvironmentConfiguration;
import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.messages.MessageCollector;
/** /**
* @author Pavel Talanov * @author Pavel Talanov
*/ */
public class K2JSCompileEnvironmentConfiguration extends CompileEnvironmentConfig { public class K2JSCompileEnvironmentConfiguration extends CompileEnvironmentConfiguration {
/** /**
* NOTE: It's very important to call dispose for every object of this class or there will be memory leaks. * NOTE: It's very important to call dispose for every object of this class or there will be memory leaks.
* *
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.CLICompiler; import org.jetbrains.jet.cli.common.CLICompiler;
import org.jetbrains.jet.cli.common.ExitCode; import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.cli.common.messages.*; import org.jetbrains.jet.cli.common.messages.*;
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration; import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler; import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
@@ -45,7 +45,7 @@ import static org.jetbrains.jet.cli.common.ExitCode.*;
* @author alex.tkachman * @author alex.tkachman
*/ */
@SuppressWarnings("UseOfSystemOutOrSystemErr") @SuppressWarnings("UseOfSystemOutOrSystemErr")
public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEnvironmentConfiguration> { public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMCompileEnvironmentConfiguration> {
public static void main(String... args) { public static void main(String... args) {
doMain(new K2JVMCompiler(), args); doMain(new K2JVMCompiler(), args);
@@ -89,8 +89,8 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable(); Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(rootDisposable, dependencies); JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(rootDisposable, dependencies);
CompileEnvironmentConfiguration configuration = K2JVMCompileEnvironmentConfiguration configuration =
new CompileEnvironmentConfiguration(environment, dependencies, messageCollector); new K2JVMCompileEnvironmentConfiguration(environment, messageCollector);
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment", messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
CompilerMessageLocation.NO_LOCATION); CompilerMessageLocation.NO_LOCATION);
@@ -175,16 +175,16 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
@Override @Override
protected void configureEnvironment(@NotNull CompileEnvironmentConfiguration configuration, protected void configureEnvironment(K2JVMCompileEnvironmentConfiguration configuration, K2JVMCompilerArguments arguments) {
@NotNull K2JVMCompilerArguments arguments) {
super.configureEnvironment(configuration, arguments); super.configureEnvironment(configuration, arguments);
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) { if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar()); CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(),
configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
} }
if (arguments.classpath != null) { if (arguments.classpath != null) {
final Iterable<String> classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath); Iterable<String> classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath);
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class)); CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class));
} }
} }
@@ -62,7 +62,7 @@ public class CompileEnvironmentUtil {
@Nullable @Nullable
public static File getUnpackedRuntimePath() { public static File getUnpackedRuntimePath() {
URL url = CompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class"); URL url = K2JVMCompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class");
if (url != null && url.getProtocol().equals("file")) { if (url != null && url.getProtocol().equals("file")) {
return new File(url.getPath()).getParentFile().getParentFile(); return new File(url.getPath()).getParentFile().getParentFile();
} }
@@ -71,7 +71,7 @@ public class CompileEnvironmentUtil {
@Nullable @Nullable
public static File getRuntimeJarPath() { public static File getRuntimeJarPath() {
URL url = CompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class"); URL url = K2JVMCompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class");
if (url != null && url.getProtocol().equals("jar")) { if (url != null && url.getProtocol().equals("jar")) {
String path = url.getPath(); String path = url.getPath();
return new File(path.substring(path.indexOf(":") + 1, path.indexOf("!/"))); return new File(path.substring(path.indexOf(":") + 1, path.indexOf("!/")));
@@ -163,7 +163,7 @@ public class CompileEnvironmentUtil {
scriptEnvironment.addSources(moduleScriptFile); scriptEnvironment.addSources(moduleScriptFile);
GenerationState generationState = KotlinToJVMBytecodeCompiler GenerationState generationState = KotlinToJVMBytecodeCompiler
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false); .analyzeAndGenerate(new K2JVMCompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false);
if (generationState == null) { if (generationState == null) {
return null; return null;
} }
@@ -195,7 +195,7 @@ public class CompileEnvironmentUtil {
} }
} }
else { else {
loader = new GeneratedClassLoader(factory, CompileEnvironmentConfiguration.class.getClassLoader()); loader = new GeneratedClassLoader(factory, K2JVMCompileEnvironmentConfiguration.class.getClassLoader());
} }
try { try {
Class namespaceClass = loader.loadClass(JvmAbi.PACKAGE_CLASS); Class namespaceClass = loader.loadClass(JvmAbi.PACKAGE_CLASS);
@@ -18,36 +18,27 @@ package org.jetbrains.jet.cli.jvm.compiler;
import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.CompileEnvironmentConfig; import org.jetbrains.jet.cli.common.CompileEnvironmentConfiguration;
import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
/** /**
* @author abreslav * @author abreslav
*/ */
public class CompileEnvironmentConfiguration extends CompileEnvironmentConfig { public class K2JVMCompileEnvironmentConfiguration extends CompileEnvironmentConfiguration {
private final JetCoreEnvironment environment; private final JetCoreEnvironment environment;
private final CompilerDependencies compilerDependencies;
/** /**
* NOTE: It's very important to call dispose for every object of this class or there will be memory leaks. * NOTE: It's very important to call dispose for every object of this class or there will be memory leaks.
* *
* @see Disposer * @see Disposer
*/ */
public CompileEnvironmentConfiguration(@NotNull JetCoreEnvironment environment, public K2JVMCompileEnvironmentConfiguration(@NotNull JetCoreEnvironment environment,
@NotNull CompilerDependencies compilerDependencies,
@NotNull MessageCollector messageCollector) { @NotNull MessageCollector messageCollector) {
super(messageCollector); super(messageCollector);
this.compilerDependencies = compilerDependencies;
this.environment = environment; this.environment = environment;
} }
public JetCoreEnvironment getEnvironment() { public JetCoreEnvironment getEnvironment() {
return environment; return environment;
} }
@NotNull
public CompilerDependencies getCompilerDependencies() {
return compilerDependencies;
}
} }
@@ -59,7 +59,7 @@ public class KotlinToJVMBytecodeCompiler {
@Nullable @Nullable
public static ClassFileFactory compileModule( public static ClassFileFactory compileModule(
CompileEnvironmentConfiguration configuration, K2JVMCompileEnvironmentConfiguration configuration,
Module moduleBuilder, Module moduleBuilder,
File directory File directory
) { ) {
@@ -82,7 +82,7 @@ public class KotlinToJVMBytecodeCompiler {
} }
public static boolean compileModules( public static boolean compileModules(
CompileEnvironmentConfiguration configuration, K2JVMCompileEnvironmentConfiguration configuration,
@NotNull List<Module> modules, @NotNull List<Module> modules,
@@ -118,7 +118,7 @@ public class KotlinToJVMBytecodeCompiler {
} }
private static boolean compileBunchOfSources( private static boolean compileBunchOfSources(
CompileEnvironmentConfiguration configuration, K2JVMCompileEnvironmentConfiguration configuration,
String jar, String jar,
String outputDir, String outputDir,
boolean includeRuntime boolean includeRuntime
@@ -163,7 +163,7 @@ public class KotlinToJVMBytecodeCompiler {
} }
public static boolean compileBunchOfSources( public static boolean compileBunchOfSources(
CompileEnvironmentConfiguration configuration, K2JVMCompileEnvironmentConfiguration configuration,
String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) { String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
configuration.getEnvironment().addSources(sourceFileOrDir); configuration.getEnvironment().addSources(sourceFileOrDir);
@@ -172,7 +172,7 @@ public class KotlinToJVMBytecodeCompiler {
} }
public static boolean compileBunchOfSourceDirectories( public static boolean compileBunchOfSourceDirectories(
CompileEnvironmentConfiguration configuration, K2JVMCompileEnvironmentConfiguration configuration,
List<String> sources, String jar, String outputDir, boolean includeRuntime) { List<String> sources, String jar, String outputDir, boolean includeRuntime) {
for (String source : sources) { for (String source : sources) {
@@ -184,7 +184,7 @@ public class KotlinToJVMBytecodeCompiler {
@Nullable @Nullable
public static ClassLoader compileText( public static ClassLoader compileText(
CompileEnvironmentConfiguration configuration, K2JVMCompileEnvironmentConfiguration configuration,
String code) { String code) {
configuration.getEnvironment() configuration.getEnvironment()
.addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code)); .addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code));
@@ -197,13 +197,13 @@ public class KotlinToJVMBytecodeCompiler {
} }
@Nullable @Nullable
public static GenerationState analyzeAndGenerate(CompileEnvironmentConfiguration configuration) { public static GenerationState analyzeAndGenerate(K2JVMCompileEnvironmentConfiguration configuration) {
return analyzeAndGenerate(configuration, configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode().isStubs()); return analyzeAndGenerate(configuration, configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode().isStubs());
} }
@Nullable @Nullable
public static GenerationState analyzeAndGenerate( public static GenerationState analyzeAndGenerate(
CompileEnvironmentConfiguration configuration, K2JVMCompileEnvironmentConfiguration configuration,
boolean stubs boolean stubs
) { ) {
AnalyzeExhaust exhaust = analyze(configuration, stubs); AnalyzeExhaust exhaust = analyze(configuration, stubs);
@@ -219,7 +219,7 @@ public class KotlinToJVMBytecodeCompiler {
@Nullable @Nullable
private static AnalyzeExhaust analyze( private static AnalyzeExhaust analyze(
final CompileEnvironmentConfiguration configuration, final K2JVMCompileEnvironmentConfiguration configuration,
boolean stubs) { boolean stubs) {
final JetCoreEnvironment environment = configuration.getEnvironment(); final JetCoreEnvironment environment = configuration.getEnvironment();
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(configuration.getMessageCollector()); AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(configuration.getMessageCollector());
@@ -243,7 +243,7 @@ public class KotlinToJVMBytecodeCompiler {
@NotNull @NotNull
private static GenerationState generate( private static GenerationState generate(
final CompileEnvironmentConfiguration configuration, final K2JVMCompileEnvironmentConfiguration configuration,
AnalyzeExhaust exhaust, AnalyzeExhaust exhaust,
boolean stubs) { boolean stubs) {
JetCoreEnvironment environment = configuration.getEnvironment(); JetCoreEnvironment environment = configuration.getEnvironment();
@@ -24,6 +24,7 @@ public enum CompilerSpecialMode {
BUILTINS, BUILTINS,
JDK_HEADERS, JDK_HEADERS,
STDLIB, STDLIB,
JS
; ;
public boolean includeJdkHeaders() { public boolean includeJdkHeaders() {
@@ -16,7 +16,7 @@
package org.jetbrains.jet.codegen; package org.jetbrains.jet.codegen;
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration; import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler; import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.messages.MessageCollector;
@@ -27,7 +27,7 @@ public class CompileTextTest extends CodegenTestCase {
public void testMe() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { public void testMe() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
createEnvironmentWithMockJdk(); createEnvironmentWithMockJdk();
String text = "import org.jetbrains.jet.codegen.CompileTextTest; fun x() = CompileTextTest()"; String text = "import org.jetbrains.jet.codegen.CompileTextTest; fun x() = CompileTextTest()";
CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration( K2JVMCompileEnvironmentConfiguration configuration = new K2JVMCompileEnvironmentConfiguration(
myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR); myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
configuration.getEnvironment().addToClasspathFromClassLoader(getClass().getClassLoader()); configuration.getEnvironment().addToClasspathFromClassLoader(getClass().getClassLoader());
ClassLoader classLoader = KotlinToJVMBytecodeCompiler.compileText(configuration, text); ClassLoader classLoader = KotlinToJVMBytecodeCompiler.compileText(configuration, text);
@@ -22,7 +22,7 @@ import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration; import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler; import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
@@ -87,7 +87,7 @@ public class TestlibTest extends CodegenTestCase {
myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src")); myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src"));
GenerationState generationState = KotlinToJVMBytecodeCompiler GenerationState generationState = KotlinToJVMBytecodeCompiler
.analyzeAndGenerate(new CompileEnvironmentConfiguration(myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR), false); .analyzeAndGenerate(new K2JVMCompileEnvironmentConfiguration(myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR), false);
if (generationState == null) { if (generationState == null) {
throw new RuntimeException("There were compilation errors"); throw new RuntimeException("There were compilation errors");
@@ -22,6 +22,7 @@ import com.intellij.openapi.compiler.CompilerMessageCategory;
import com.intellij.openapi.compiler.TranslatingCompiler; import com.intellij.openapi.compiler.TranslatingCompiler;
import com.intellij.openapi.module.Module; import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Chunk; import com.intellij.util.Chunk;
import jet.Function1; import jet.Function1;
@@ -62,7 +63,7 @@ public final class K2JSCompiler implements TranslatingCompiler {
return; return;
} }
Module module = moduleChunk.getNodes().iterator().next(); final Module module = moduleChunk.getNodes().iterator().next();
final CompilerEnvironment environment = CompilerEnvironment.getEnvironmentFor(context, module, /*tests = */ false); final CompilerEnvironment environment = CompilerEnvironment.getEnvironmentFor(context, module, /*tests = */ false);
if (!environment.success()) { if (!environment.success()) {
environment.reportErrorsTo(context); environment.reportErrorsTo(context);
@@ -73,7 +74,7 @@ public final class K2JSCompiler implements TranslatingCompiler {
outputCompilerMessagesAndHandleExitCode(context, collector, new Function1<PrintStream, Integer>() { outputCompilerMessagesAndHandleExitCode(context, collector, new Function1<PrintStream, Integer>() {
@Override @Override
public Integer invoke(PrintStream stream) { public Integer invoke(PrintStream stream) {
return execInProcess(context, environment, stream); return execInProcess(context, environment, stream, module);
} }
}); });
sink.add(environment.getOutput().getPath(), collector.getOutputs(), collector.getSources().toArray(VirtualFile.EMPTY_ARRAY)); sink.add(environment.getOutput().getPath(), collector.getOutputs(), collector.getSources().toArray(VirtualFile.EMPTY_ARRAY));
@@ -81,11 +82,15 @@ public final class K2JSCompiler implements TranslatingCompiler {
@NotNull @NotNull
private static Integer execInProcess(@NotNull CompileContext context, private static Integer execInProcess(@NotNull CompileContext context,
@NotNull CompilerEnvironment environment, @NotNull PrintStream out) { @NotNull CompilerEnvironment environment, @NotNull PrintStream out, @NotNull Module module) {
try { try {
String[] commandLineArgs = {"-tags", "-verbose", "-version"}; VirtualFile[] roots = ModuleRootManager.getInstance(module).getSourceRoots();
Object rc = invokeExecMethod(environment, out, context, commandLineArgs, if (roots.length != 1) {
"org.jetbrains.jet.cli.js.K2JSCompiler"); context.addMessage(CompilerMessageCategory.ERROR, "K2JSCompiler does not support module source roots.", null, -1, -1);
return -1;
}
String[] commandLineArgs = {"-tags", "-verbose", "-version", "-srcdir", roots[0].getPath()};
Object rc = invokeExecMethod(environment, out, context, commandLineArgs, "org.jetbrains.jet.cli.js.K2JSCompiler");
return CompilerUtils.getReturnCodeFromObject(rc); return CompilerUtils.getReturnCodeFromObject(rc);
} }
catch (Throwable e) { catch (Throwable e) {
@@ -5,7 +5,7 @@ import java.io.PrintStream
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
import org.jetbrains.jet.cli.jvm.K2JVMCompiler import org.jetbrains.jet.cli.jvm.K2JVMCompiler
import org.jetbrains.jet.cli.common.CLICompiler import org.jetbrains.jet.cli.common.CLICompiler
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration
import org.jetbrains.kotlin.doc.highlighter.HtmlCompilerPlugin import org.jetbrains.kotlin.doc.highlighter.HtmlCompilerPlugin
import org.jetbrains.jet.cli.common.ExitCode import org.jetbrains.jet.cli.common.ExitCode