JPS: removed unnecessary code for running compiler out of process.

This commit is contained in:
Zalim Bashorov
2013-10-10 15:15:20 +04:00
parent 1176d58f40
commit 41d0a8be24
3 changed files with 16 additions and 99 deletions
@@ -16,26 +16,15 @@
package org.jetbrains.jet.compiler.runner;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.SimpleJavaParameters;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.projectRoots.JavaSdkType;
import com.intellij.openapi.projectRoots.JdkUtil;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SimpleJavaSdkType;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.SystemProperties;
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.common.messages.MessageCollectorUtil;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.*;
@@ -47,17 +36,10 @@ public class KotlinCompilerRunner {
MessageCollector messageCollector,
CompilerEnvironment environment,
File moduleFile,
OutputItemsCollector collector,
boolean runOutOfProcess
OutputItemsCollector collector
) {
String[] arguments = createArgumentsForJvmCompiler(moduleFile);
if (runOutOfProcess) {
runOutOfProcess(K2JVM_COMPILER, arguments, messageCollector, collector, environment);
}
else {
runInProcess(K2JVM_COMPILER, arguments, messageCollector, collector, environment);
}
runCompiler(K2JVM_COMPILER, arguments, messageCollector, collector, environment);
}
public static void runK2JsCompiler(
@@ -69,24 +51,31 @@ public class KotlinCompilerRunner {
File outputFile
) {
String[] arguments = createArgumentsForJsCompiler(outputFile, sourceFiles, libraryFiles);
runInProcess(K2JS_COMPILER, arguments, messageCollector, collector, environment);
runCompiler(K2JS_COMPILER, arguments, messageCollector, collector, environment);
}
private static void runInProcess(
private static void runCompiler(
final String compilerClassName,
final String[] arguments,
final MessageCollector messageCollector,
OutputItemsCollector collector,
final CompilerEnvironment environment) {
final CompilerEnvironment environment
) {
CompilerRunnerUtil.outputCompilerMessagesAndHandleExitCode(messageCollector, collector, new Function<PrintStream, Integer>() {
@Override
public Integer fun(PrintStream stream) {
return execInProcess(compilerClassName, arguments, environment, stream, messageCollector);
return execCompiler(compilerClassName, arguments, environment, stream, messageCollector);
}
});
}
private static int execInProcess(String compilerClassName, String[] arguments, CompilerEnvironment environment, PrintStream out, MessageCollector messageCollector) {
private static int execCompiler(
String compilerClassName,
String[] arguments,
CompilerEnvironment environment,
PrintStream out,
MessageCollector messageCollector
) {
try {
messageCollector.report(CompilerMessageSeverity.INFO,
"Using kotlinHome=" + environment.getKotlinPaths().getHomePath(),
@@ -142,72 +131,4 @@ public class KotlinCompilerRunner {
return ArrayUtil.toStringArray(args);
}
private static void runOutOfProcess(
String compilerClassName,
String[] arguments,
final MessageCollector messageCollector,
final OutputItemsCollector itemCollector,
CompilerEnvironment environment
) {
SimpleJavaParameters params = new SimpleJavaParameters();
params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
params.setMainClass(compilerClassName);
for (String arg : arguments) {
params.getProgramParametersList().add(arg);
}
for (File jar : CompilerRunnerUtil.kompilerClasspath(environment.getKotlinPaths(), messageCollector)) {
params.getClassPath().add(jar);
}
params.getVMParametersList().addParametersString("-Djava.awt.headless=true -Xmx512m");
// params.getVMParametersList().addParametersString("-agentlib:yjpagent=sampling");
Sdk sdk = params.getJdk();
assert sdk != null;
GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(
((JavaSdkType) sdk.getSdkType()).getVMExecutablePath(sdk), params, false);
messageCollector.report(CompilerMessageSeverity.INFO,
"Invoking out-of-process compiler with arguments: " + commandLine,
CompilerMessageLocation.NO_LOCATION);
try {
final Process process = commandLine.createProcess();
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
CompilerOutputParser
.parseCompilerMessagesFromReader(messageCollector, new InputStreamReader(process.getInputStream()),
itemCollector);
}
});
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
FileUtil.loadBytes(process.getErrorStream());
}
catch (IOException e) {
// Don't care
}
}
});
int exitCode = process.waitFor();
CompilerRunnerUtil.handleProcessTermination(exitCode, messageCollector);
}
catch (Exception e) {
messageCollector.report(CompilerMessageSeverity.ERROR,
"[Internal Error] " + e.getLocalizedMessage(),
CompilerMessageLocation.NO_LOCATION);
}
}
}
@@ -41,9 +41,6 @@ import java.io.IOException;
import java.util.*;
public class JetCompiler implements TranslatingCompiler {
private static final boolean RUN_OUT_OF_PROCESS = false;
@Override
public boolean isCompilableFile(VirtualFile virtualFile, CompileContext compileContext) {
if (!(virtualFile.getFileType() instanceof JetFileType)) {
@@ -136,7 +133,7 @@ public class JetCompiler implements TranslatingCompiler {
File scriptFile,
OutputItemsCollector outputItemsCollector
) {
KotlinCompilerRunner.runK2JvmCompiler(messageCollector, environment, scriptFile, outputItemsCollector, RUN_OUT_OF_PROCESS);
KotlinCompilerRunner.runK2JvmCompiler(messageCollector, environment, scriptFile, outputItemsCollector);
}
public static File tryToWriteScriptFile(
@@ -152,8 +152,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
messageCollector,
environment,
moduleFile,
outputItemCollector,
/*runOutOfProcess = */false);
outputItemCollector);
}
for (SimpleOutputItem outputItem : outputItemCollector.getOutputs()) {