diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java index 9695a45ac73..e77856c9f22 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java @@ -18,7 +18,10 @@ package org.jetbrains.jet.cli.common; import com.sampullara.cli.Args; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; +import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; import org.jetbrains.jet.cli.common.messages.MessageRenderer; +import org.jetbrains.jet.cli.jvm.K2JVMCompilerVersion; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException; import java.io.PrintStream; @@ -78,8 +81,44 @@ public abstract class CLICompiler modules = CompileEnvironmentUtil + .loadModuleScript(arguments.module, new PrintingMessageCollector(errStream, messageRenderer, false)); + File directory = new File(arguments.module).getParentFile(); + noErrors = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, + directory, arguments.jar, arguments.outputDir, + arguments.includeRuntime); } else { - jdkHeadersJar = null; - } - File runtimeJar; - - if (mode.includeKotlinRuntime()) { - if (arguments.stdlib != null) { - runtimeJar = new File(arguments.stdlib); + // TODO ideally we'd unify to just having a single field that supports multiple files/dirs + if (arguments.getSourceDirs() != null) { + noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSourceDirectories(configuration, + arguments.getSourceDirs(), arguments.jar, + arguments.outputDir, + arguments.includeRuntime); } else { - runtimeJar = PathUtil.getDefaultRuntimePath(); + noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(configuration, + arguments.src, arguments.jar, arguments.outputDir, + arguments.includeRuntime); } } - else { - runtimeJar = null; - } - - CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), jdkHeadersJar, runtimeJar); - PrintingMessageCollector messageCollector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose); - Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable(); - - JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(rootDisposable, dependencies); - CompileEnvironmentConfiguration configuration = - new CompileEnvironmentConfiguration(environment, dependencies, messageCollector); - - messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment", + return noErrors ? OK : COMPILATION_ERROR; + } + catch (CompilationException e) { + messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(e), + MessageUtil.psiElementToMessageLocation(e.getElement())); + return INTERNAL_ERROR; + } + catch (Throwable t) { + messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(t), CompilerMessageLocation.NO_LOCATION); - try { - configureEnvironment(configuration, arguments); - - boolean noErrors; - if (arguments.module != null) { - List modules = CompileEnvironmentUtil - .loadModuleScript(arguments.module, new PrintingMessageCollector(errStream, messageRenderer, false)); - File directory = new File(arguments.module).getParentFile(); - noErrors = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, - directory, arguments.jar, arguments.outputDir, - arguments.includeRuntime); - } - else { - // TODO ideally we'd unify to just having a single field that supports multiple files/dirs - if (arguments.getSourceDirs() != null) { - noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSourceDirectories(configuration, - arguments.getSourceDirs(), arguments.jar, - arguments.outputDir, - arguments.includeRuntime); - } - else { - noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(configuration, - arguments.src, arguments.jar, arguments.outputDir, - arguments.includeRuntime); - } - } - return noErrors ? OK : COMPILATION_ERROR; - } - catch (CompilationException e) { - messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(e), - MessageUtil.psiElementToMessageLocation(e.getElement())); - return INTERNAL_ERROR; - } - catch (Throwable t) { - messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(t), - CompilerMessageLocation.NO_LOCATION); - return INTERNAL_ERROR; - } - finally { - Disposer.dispose(rootDisposable); - messageCollector.printToErrStream(); - } + return INTERNAL_ERROR; } finally { - errStream.print(messageRenderer.renderConclusion()); + Disposer.dispose(rootDisposable); + messageCollector.printToErrStream(); } } @@ -186,6 +166,15 @@ public class K2JVMCompiler extends CLICompiler