JPS: removed unnecessary code for running compiler out of process.
This commit is contained in:
+14
-93
@@ -16,26 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.compiler.runner;
|
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.openapi.util.text.StringUtil;
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
import com.intellij.util.Function;
|
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.CompilerMessageLocation;
|
||||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollectorUtil;
|
import org.jetbrains.jet.cli.common.messages.MessageCollectorUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -47,17 +36,10 @@ public class KotlinCompilerRunner {
|
|||||||
MessageCollector messageCollector,
|
MessageCollector messageCollector,
|
||||||
CompilerEnvironment environment,
|
CompilerEnvironment environment,
|
||||||
File moduleFile,
|
File moduleFile,
|
||||||
OutputItemsCollector collector,
|
OutputItemsCollector collector
|
||||||
boolean runOutOfProcess
|
|
||||||
) {
|
) {
|
||||||
String[] arguments = createArgumentsForJvmCompiler(moduleFile);
|
String[] arguments = createArgumentsForJvmCompiler(moduleFile);
|
||||||
|
runCompiler(K2JVM_COMPILER, arguments, messageCollector, collector, environment);
|
||||||
if (runOutOfProcess) {
|
|
||||||
runOutOfProcess(K2JVM_COMPILER, arguments, messageCollector, collector, environment);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
runInProcess(K2JVM_COMPILER, arguments, messageCollector, collector, environment);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runK2JsCompiler(
|
public static void runK2JsCompiler(
|
||||||
@@ -69,24 +51,31 @@ public class KotlinCompilerRunner {
|
|||||||
File outputFile
|
File outputFile
|
||||||
) {
|
) {
|
||||||
String[] arguments = createArgumentsForJsCompiler(outputFile, sourceFiles, libraryFiles);
|
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 compilerClassName,
|
||||||
final String[] arguments,
|
final String[] arguments,
|
||||||
final MessageCollector messageCollector,
|
final MessageCollector messageCollector,
|
||||||
OutputItemsCollector collector,
|
OutputItemsCollector collector,
|
||||||
final CompilerEnvironment environment) {
|
final CompilerEnvironment environment
|
||||||
|
) {
|
||||||
CompilerRunnerUtil.outputCompilerMessagesAndHandleExitCode(messageCollector, collector, new Function<PrintStream, Integer>() {
|
CompilerRunnerUtil.outputCompilerMessagesAndHandleExitCode(messageCollector, collector, new Function<PrintStream, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer fun(PrintStream stream) {
|
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 {
|
try {
|
||||||
messageCollector.report(CompilerMessageSeverity.INFO,
|
messageCollector.report(CompilerMessageSeverity.INFO,
|
||||||
"Using kotlinHome=" + environment.getKotlinPaths().getHomePath(),
|
"Using kotlinHome=" + environment.getKotlinPaths().getHomePath(),
|
||||||
@@ -142,72 +131,4 @@ public class KotlinCompilerRunner {
|
|||||||
|
|
||||||
return ArrayUtil.toStringArray(args);
|
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.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class JetCompiler implements TranslatingCompiler {
|
public class JetCompiler implements TranslatingCompiler {
|
||||||
|
|
||||||
private static final boolean RUN_OUT_OF_PROCESS = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompilableFile(VirtualFile virtualFile, CompileContext compileContext) {
|
public boolean isCompilableFile(VirtualFile virtualFile, CompileContext compileContext) {
|
||||||
if (!(virtualFile.getFileType() instanceof JetFileType)) {
|
if (!(virtualFile.getFileType() instanceof JetFileType)) {
|
||||||
@@ -136,7 +133,7 @@ public class JetCompiler implements TranslatingCompiler {
|
|||||||
File scriptFile,
|
File scriptFile,
|
||||||
OutputItemsCollector outputItemsCollector
|
OutputItemsCollector outputItemsCollector
|
||||||
) {
|
) {
|
||||||
KotlinCompilerRunner.runK2JvmCompiler(messageCollector, environment, scriptFile, outputItemsCollector, RUN_OUT_OF_PROCESS);
|
KotlinCompilerRunner.runK2JvmCompiler(messageCollector, environment, scriptFile, outputItemsCollector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File tryToWriteScriptFile(
|
public static File tryToWriteScriptFile(
|
||||||
|
|||||||
@@ -152,8 +152,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
|||||||
messageCollector,
|
messageCollector,
|
||||||
environment,
|
environment,
|
||||||
moduleFile,
|
moduleFile,
|
||||||
outputItemCollector,
|
outputItemCollector);
|
||||||
/*runOutOfProcess = */false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SimpleOutputItem outputItem : outputItemCollector.getOutputs()) {
|
for (SimpleOutputItem outputItem : outputItemCollector.getOutputs()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user