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