@@ -21,5 +21,7 @@
|
||||
<orderEntry type="library" name="asm" level="project" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="preloader" />
|
||||
<orderEntry type="module" module-name="kotlinr" />
|
||||
<orderEntry type="module" module-name="rmi-interface" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -30,6 +30,9 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil;
|
||||
import org.jetbrains.kotlin.config.CompilerSettings;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
|
||||
import org.jetbrains.kotlin.rmi.CompilerFacade;
|
||||
import org.jetbrains.kotlin.rmi.kotlinr.KotlinCompilerClient;
|
||||
import org.jetbrains.kotlin.utils.UtilsPackage;
|
||||
|
||||
import java.io.*;
|
||||
@@ -38,6 +41,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR;
|
||||
@@ -54,13 +58,14 @@ public class KotlinCompilerRunner {
|
||||
CompilerSettings compilerSettings,
|
||||
MessageCollector messageCollector,
|
||||
CompilerEnvironment environment,
|
||||
File moduleFile,
|
||||
Map<String, IncrementalCache> incrementalCaches, File moduleFile,
|
||||
OutputItemsCollector collector
|
||||
) {
|
||||
K2JVMCompilerArguments arguments = mergeBeans(commonArguments, k2jvmArguments);
|
||||
setupK2JvmArguments(moduleFile, arguments);
|
||||
|
||||
runCompiler(K2JVM_COMPILER, arguments, compilerSettings.getAdditionalArguments(), messageCollector, collector, environment);
|
||||
runCompiler(K2JVM_COMPILER, arguments, compilerSettings.getAdditionalArguments(), messageCollector, collector, environment,
|
||||
incrementalCaches);
|
||||
}
|
||||
|
||||
public static void runK2JsCompiler(
|
||||
@@ -69,7 +74,7 @@ public class KotlinCompilerRunner {
|
||||
@NotNull CompilerSettings compilerSettings,
|
||||
@NotNull MessageCollector messageCollector,
|
||||
@NotNull CompilerEnvironment environment,
|
||||
@NotNull OutputItemsCollector collector,
|
||||
Map<String, IncrementalCache> incrementalCaches, @NotNull OutputItemsCollector collector,
|
||||
@NotNull Collection<File> sourceFiles,
|
||||
@NotNull List<String> libraryFiles,
|
||||
@NotNull File outputFile
|
||||
@@ -77,7 +82,8 @@ public class KotlinCompilerRunner {
|
||||
K2JSCompilerArguments arguments = mergeBeans(commonArguments, k2jsArguments);
|
||||
setupK2JsArguments(outputFile, sourceFiles, libraryFiles, arguments);
|
||||
|
||||
runCompiler(K2JS_COMPILER, arguments, compilerSettings.getAdditionalArguments(), messageCollector, collector, environment);
|
||||
runCompiler(K2JS_COMPILER, arguments, compilerSettings.getAdditionalArguments(), messageCollector, collector, environment,
|
||||
incrementalCaches);
|
||||
}
|
||||
|
||||
private static void runCompiler(
|
||||
@@ -86,12 +92,13 @@ public class KotlinCompilerRunner {
|
||||
String additionalArguments,
|
||||
MessageCollector messageCollector,
|
||||
OutputItemsCollector collector,
|
||||
CompilerEnvironment environment
|
||||
CompilerEnvironment environment,
|
||||
Map<String, IncrementalCache> incrementalCaches
|
||||
) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
PrintStream out = new PrintStream(stream);
|
||||
|
||||
String exitCode = execCompiler(compilerClassName, arguments, additionalArguments, environment, out, messageCollector);
|
||||
String exitCode = execCompiler(compilerClassName, arguments, additionalArguments, environment, incrementalCaches, out, messageCollector);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new StringReader(stream.toString()));
|
||||
CompilerOutputParser.parseCompilerMessagesFromReader(messageCollector, reader, collector);
|
||||
@@ -107,6 +114,7 @@ public class KotlinCompilerRunner {
|
||||
CommonCompilerArguments arguments,
|
||||
String additionalArguments,
|
||||
CompilerEnvironment environment,
|
||||
Map<String, IncrementalCache> incrementalCaches,
|
||||
PrintStream out,
|
||||
MessageCollector messageCollector
|
||||
) {
|
||||
@@ -116,13 +124,27 @@ public class KotlinCompilerRunner {
|
||||
List<String> argumentsList = ArgumentUtils.convertArgumentsToStringList(arguments);
|
||||
argumentsList.addAll(StringUtil.split(additionalArguments, " "));
|
||||
|
||||
String[] argsArray = ArrayUtil.toStringArray(argumentsList);
|
||||
|
||||
// trying the daemon first
|
||||
if (incrementalCaches != null) {
|
||||
CompilerFacade daemon = KotlinCompilerClient.Companion.connectToCompilerServer();
|
||||
if (daemon != null) {
|
||||
Integer res = KotlinCompilerClient.Companion.incrementalCompile(daemon, argsArray, incrementalCaches, out);
|
||||
return res.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise fallback to in-process
|
||||
|
||||
Object rc = CompilerRunnerUtil.invokeExecMethod(
|
||||
compilerClassName, ArrayUtil.toStringArray(argumentsList), environment, messageCollector, out
|
||||
compilerClassName, argsArray, environment, messageCollector, out
|
||||
);
|
||||
|
||||
// exec() returns an ExitCode object, class of which is loaded with a different class loader,
|
||||
// so we take it's contents through reflection
|
||||
return getReturnCodeFromObject(rc);
|
||||
|
||||
}
|
||||
catch (Throwable e) {
|
||||
MessageCollectorUtil.reportException(messageCollector, e);
|
||||
|
||||
@@ -247,9 +247,10 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
filesToCompile: MultiMap<ModuleBuildTarget, File>, incrementalCaches: Map<ModuleBuildTarget, IncrementalCacheImpl>,
|
||||
messageCollector: MessageCollectorAdapter, project: JpsProject
|
||||
): OutputItemsCollectorImpl? {
|
||||
|
||||
if (JpsUtils.isJsKotlinModule(chunk.representativeTarget())) {
|
||||
LOG.debug("Compiling to JS ${filesToCompile.values().size()} files in " + filesToCompile.keySet().map { it.getPresentableName() }.join())
|
||||
return compileToJs(chunk, commonArguments, environment, messageCollector, project)
|
||||
return compileToJs(chunk, commonArguments, environment, null, messageCollector, project)
|
||||
}
|
||||
|
||||
if (IncrementalCompilation.ENABLED) {
|
||||
@@ -279,7 +280,9 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
)
|
||||
}
|
||||
|
||||
return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment, filesToCompile, messageCollector)
|
||||
return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment,
|
||||
incrementalCaches.mapKeysTo(HashMap<String, IncrementalCache>(incrementalCaches.size()), { it.getKey().id }),
|
||||
filesToCompile, messageCollector)
|
||||
}
|
||||
|
||||
private fun createCompileEnvironment(
|
||||
@@ -436,8 +439,8 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
private fun compileToJs(chunk: ModuleChunk,
|
||||
commonArguments: CommonCompilerArguments,
|
||||
environment: CompilerEnvironment,
|
||||
messageCollector: KotlinBuilder.MessageCollectorAdapter,
|
||||
project: JpsProject
|
||||
incrementalCaches: MutableMap<String, IncrementalCache>?,
|
||||
messageCollector: MessageCollectorAdapter, project: JpsProject
|
||||
): OutputItemsCollectorImpl? {
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
|
||||
@@ -468,7 +471,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(project)
|
||||
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(project)
|
||||
|
||||
runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, messageCollector, environment, outputItemCollector, sourceFiles, libraryFiles, outputFile)
|
||||
runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, messageCollector, environment, incrementalCaches, outputItemCollector, sourceFiles, libraryFiles, outputFile)
|
||||
return outputItemCollector
|
||||
}
|
||||
|
||||
@@ -491,8 +494,8 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
context: CompileContext,
|
||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||
environment: CompilerEnvironment,
|
||||
filesToCompile: MultiMap<ModuleBuildTarget, File>,
|
||||
messageCollector: KotlinBuilder.MessageCollectorAdapter
|
||||
incrementalCaches: MutableMap<String, IncrementalCache>?,
|
||||
filesToCompile: MultiMap<ModuleBuildTarget, File>, messageCollector: MessageCollectorAdapter
|
||||
): OutputItemsCollectorImpl? {
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
|
||||
@@ -535,7 +538,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
+ (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)")
|
||||
+ " in " + filesToCompile.keySet().map { it.getPresentableName() }.join())
|
||||
|
||||
runK2JvmCompiler(commonArguments, k2JvmArguments, compilerSettings, messageCollector, environment, moduleFile, outputItemCollector)
|
||||
runK2JvmCompiler(commonArguments, k2JvmArguments, compilerSettings, messageCollector, environment, incrementalCaches, moduleFile, outputItemCollector)
|
||||
moduleFile.delete()
|
||||
|
||||
return outputItemCollector
|
||||
|
||||
Reference in New Issue
Block a user