Use simple data class TargetId instead of Module to get incremental cache
This commit is contained in:
@@ -143,7 +143,7 @@ public class PackageCodegen {
|
||||
// TODO rewrite it to something more robust when module system is implemented
|
||||
for (PackageFragmentDescriptor fragment : state.getModule().getPackage(fqName).getFragments()) {
|
||||
if (fragment instanceof IncrementalPackageFragmentProvider.IncrementalPackageFragment &&
|
||||
((IncrementalPackageFragmentProvider.IncrementalPackageFragment) fragment).getTarget().equals(state.getTarget())) {
|
||||
((IncrementalPackageFragmentProvider.IncrementalPackageFragment) fragment).getTarget().equals(state.getTargetId())) {
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@ fun List<PackageParts>.addCompiledPartsAndSort(state: GenerationState): List<Pac
|
||||
addCompiledParts(state).sortedBy { it.packageFqName }
|
||||
|
||||
private fun List<PackageParts>.addCompiledParts(state: GenerationState): List<PackageParts> {
|
||||
if (state.incrementalCompilationComponents == null || state.target == null) return this
|
||||
if (state.incrementalCompilationComponents == null || state.targetId == null) return this
|
||||
|
||||
val incrementalCache = state.incrementalCompilationComponents.getIncrementalCache(state.target)
|
||||
val incrementalCache = state.incrementalCompilationComponents.getIncrementalCache(state.targetId)
|
||||
val moduleMappingData = incrementalCache.getModuleMappingData() ?: return this
|
||||
|
||||
val mapping = ModuleMapping.create(moduleMappingData)
|
||||
|
||||
@@ -30,11 +30,10 @@ import org.jetbrains.kotlin.codegen.context.PackageContext;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.InlineRegistering;
|
||||
import org.jetbrains.kotlin.modules.Module;
|
||||
import org.jetbrains.kotlin.modules.TargetId;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
@@ -748,11 +747,11 @@ public class InlineCodegen extends CallGenerator {
|
||||
@NotNull FunctionDescriptor targetDescriptor
|
||||
) {
|
||||
IncrementalCompilationComponents incrementalCompilationComponents = state.getIncrementalCompilationComponents();
|
||||
Module target = state.getTarget();
|
||||
TargetId targetId = state.getTargetId();
|
||||
|
||||
if (incrementalCompilationComponents == null || target == null) return;
|
||||
if (incrementalCompilationComponents == null || targetId == null) return;
|
||||
|
||||
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(target);
|
||||
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(targetId);
|
||||
String sourceFile = getClassFilePath(sourceDescriptor, incrementalCache);
|
||||
String targetFile = getSourceFilePath(targetDescriptor);
|
||||
InlineRegistering inlineRegistering = incrementalCache.getInlineRegistering();
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
@@ -52,7 +52,7 @@ public class GenerationState jvmOverloads constructor(
|
||||
public val diagnostics: DiagnosticSink = DiagnosticSink.DO_NOTHING,
|
||||
public val packagesWithObsoleteParts: Collection<FqName> = emptySet(),
|
||||
// for PackageCodegen in incremental compilation mode
|
||||
public val target: Module? = null,
|
||||
public val targetId: TargetId? = null,
|
||||
moduleName: String? = null,
|
||||
// TODO: temporary hack, see JetTypeMapperWithOutDirectory state for details
|
||||
public val outDirectory: File? = null,
|
||||
|
||||
+11
-6
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.cli.common.CompilerPlugin;
|
||||
import org.jetbrains.kotlin.cli.common.CompilerPluginContext;
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.modules.Module;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JVMConfigurationKeys;
|
||||
@@ -46,6 +45,9 @@ import org.jetbrains.kotlin.idea.MainFunctionDetector;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents;
|
||||
import org.jetbrains.kotlin.modules.Module;
|
||||
import org.jetbrains.kotlin.modules.ModulesPackage;
|
||||
import org.jetbrains.kotlin.modules.TargetId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.parsing.JetScriptDefinition;
|
||||
import org.jetbrains.kotlin.parsing.JetScriptDefinitionProvider;
|
||||
@@ -357,7 +359,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
@NotNull KotlinCoreEnvironment environment,
|
||||
@NotNull AnalysisResult result,
|
||||
@NotNull List<JetFile> sourceFiles,
|
||||
@Nullable Module target,
|
||||
@Nullable Module module,
|
||||
File outputDirectory,
|
||||
String moduleName
|
||||
) {
|
||||
@@ -365,11 +367,14 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
IncrementalCompilationComponents incrementalCompilationComponents = configuration.get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS);
|
||||
|
||||
Collection<FqName> packagesWithObsoleteParts;
|
||||
if (target == null || incrementalCompilationComponents == null) {
|
||||
TargetId targetId = null;
|
||||
|
||||
if (module == null || incrementalCompilationComponents == null) {
|
||||
packagesWithObsoleteParts = Collections.emptySet();
|
||||
}
|
||||
else {
|
||||
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(target);
|
||||
targetId = ModulesPackage.TargetId(module);
|
||||
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(targetId);
|
||||
packagesWithObsoleteParts = new HashSet<FqName>();
|
||||
for (String internalName : incrementalCache.getObsoletePackageParts()) {
|
||||
packagesWithObsoleteParts.add(JvmClassName.byInternalName(internalName).getPackageFqName());
|
||||
@@ -389,7 +394,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
configuration.get(JVMConfigurationKeys.DISABLE_OPTIMIZATION, false),
|
||||
diagnosticHolder,
|
||||
packagesWithObsoleteParts,
|
||||
target,
|
||||
targetId,
|
||||
moduleName,
|
||||
outputDirectory,
|
||||
incrementalCompilationComponents
|
||||
@@ -401,7 +406,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
|
||||
long generationNanos = PerformanceCounter.Companion.currentTime() - generationStart;
|
||||
String desc = target != null ? "target " + target.getModuleName() + "-" + target.getModuleType() + " " : "";
|
||||
String desc = module != null ? "target " + module.getModuleName() + "-" + module.getModuleType() + " " : "";
|
||||
String message = "GENERATE: " + sourceFiles.size() + " files (" +
|
||||
environment.countLinesOfCode(sourceFiles) + " lines) " + desc + "in " + TimeUnit.NANOSECONDS.toMillis(generationNanos) + " ms";
|
||||
K2JVMCompiler.Companion.reportPerf(environment.getConfiguration(), message);
|
||||
|
||||
+5
-5
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
@@ -46,11 +46,11 @@ import java.util.*
|
||||
|
||||
public class IncrementalPackageFragmentProvider(
|
||||
sourceFiles: Collection<JetFile>,
|
||||
val module: ModuleDescriptor,
|
||||
val moduleDescriptor: ModuleDescriptor,
|
||||
val storageManager: StorageManager,
|
||||
val deserializationComponents: DeserializationComponents,
|
||||
val incrementalCache: IncrementalCache,
|
||||
val target: Module
|
||||
val target: TargetId
|
||||
) : PackageFragmentProvider {
|
||||
|
||||
companion object {
|
||||
@@ -93,8 +93,8 @@ public class IncrementalPackageFragmentProvider(
|
||||
}
|
||||
|
||||
|
||||
public inner class IncrementalPackageFragment(fqName: FqName) : PackageFragmentDescriptorImpl(module, fqName) {
|
||||
public val target: Module
|
||||
public inner class IncrementalPackageFragment(fqName: FqName) : PackageFragmentDescriptorImpl(moduleDescriptor, fqName) {
|
||||
public val target: TargetId
|
||||
get() = this@IncrementalPackageFragmentProvider.target
|
||||
|
||||
val memberScope: NotNullLazyValue<JetScope> = storageManager.createLazyValue {
|
||||
|
||||
+4
-4
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.PackagePartProvider
|
||||
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
@@ -47,13 +47,13 @@ internal class IncrementalPackagePartProvider private constructor(
|
||||
public fun create(
|
||||
parent: PackagePartProvider,
|
||||
sourceFiles: Collection<JetFile>,
|
||||
modules: List<Module>?,
|
||||
targets: List<TargetId>?,
|
||||
incrementalCompilationComponents: IncrementalCompilationComponents?,
|
||||
storageManager: StorageManager
|
||||
): PackagePartProvider {
|
||||
if (modules == null || incrementalCompilationComponents == null) return parent
|
||||
if (targets == null || incrementalCompilationComponents == null) return parent
|
||||
|
||||
val incrementalCaches = modules.map { incrementalCompilationComponents.getIncrementalCache(it) }
|
||||
val incrementalCaches = targets.map { incrementalCompilationComponents.getIncrementalCache(it) }
|
||||
return IncrementalPackagePartProvider(parent, sourceFiles, incrementalCaches, storageManager)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@
|
||||
package org.jetbrains.kotlin.load.kotlin.incremental.components
|
||||
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
|
||||
public interface IncrementalCompilationComponents {
|
||||
public fun getIncrementalCache(target: Module): IncrementalCache
|
||||
public fun getIncrementalCache(target: TargetId): IncrementalCache
|
||||
public fun getLookupTracker(): LookupTracker
|
||||
}
|
||||
|
||||
+19
-8
@@ -33,6 +33,8 @@ import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackagePartProvid
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents;
|
||||
import org.jetbrains.kotlin.modules.Module;
|
||||
import org.jetbrains.kotlin.modules.ModulesPackage;
|
||||
import org.jetbrains.kotlin.modules.TargetId;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap;
|
||||
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap;
|
||||
@@ -101,12 +103,12 @@ public enum TopDownAnalyzerFacadeForJVM {
|
||||
@NotNull ModuleContext moduleContext,
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull BindingTrace trace,
|
||||
@Nullable List<Module> targets,
|
||||
@Nullable List<Module> modules,
|
||||
@Nullable IncrementalCompilationComponents incrementalCompilationComponents,
|
||||
@NotNull PackagePartProvider packagePartProvider
|
||||
) {
|
||||
return analyzeFilesWithJavaIntegration(
|
||||
moduleContext, files, trace, TopDownAnalysisMode.TopLevelDeclarations, targets, incrementalCompilationComponents,
|
||||
moduleContext, files, trace, TopDownAnalysisMode.TopLevelDeclarations, modules, incrementalCompilationComponents,
|
||||
packagePartProvider);
|
||||
}
|
||||
|
||||
@@ -116,7 +118,7 @@ public enum TopDownAnalyzerFacadeForJVM {
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull TopDownAnalysisMode topDownAnalysisMode,
|
||||
@Nullable List<Module> targets,
|
||||
@Nullable List<Module> modules,
|
||||
@Nullable IncrementalCompilationComponents incrementalCompilationComponents,
|
||||
@NotNull PackagePartProvider packagePartProvider
|
||||
) {
|
||||
@@ -129,7 +131,16 @@ public enum TopDownAnalyzerFacadeForJVM {
|
||||
LookupTracker lookupTracker =
|
||||
incrementalCompilationComponents != null ? incrementalCompilationComponents.getLookupTracker() : LookupTracker.DO_NOTHING;
|
||||
|
||||
packagePartProvider = IncrementalPackagePartProvider.create(packagePartProvider, files, targets, incrementalCompilationComponents, moduleContext.getStorageManager());
|
||||
List<TargetId> targetIds = null;
|
||||
if (modules != null) {
|
||||
targetIds = new ArrayList<TargetId>(modules.size());
|
||||
|
||||
for (Module module : modules) {
|
||||
targetIds.add(ModulesPackage.TargetId(module));
|
||||
}
|
||||
}
|
||||
|
||||
packagePartProvider = IncrementalPackagePartProvider.create(packagePartProvider, files, targetIds, incrementalCompilationComponents, moduleContext.getStorageManager());
|
||||
|
||||
ContainerForTopDownAnalyzerForJvm container = DiPackage.createContainerForTopDownAnalyzerForJvm(
|
||||
moduleContext,
|
||||
@@ -142,15 +153,15 @@ public enum TopDownAnalyzerFacadeForJVM {
|
||||
|
||||
List<PackageFragmentProvider> additionalProviders = new ArrayList<PackageFragmentProvider>();
|
||||
|
||||
if (targets != null && incrementalCompilationComponents != null) {
|
||||
for (Module target : targets) {
|
||||
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(target);
|
||||
if (targetIds != null && incrementalCompilationComponents != null) {
|
||||
for (TargetId targetId : targetIds) {
|
||||
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(targetId);
|
||||
|
||||
additionalProviders.add(
|
||||
new IncrementalPackageFragmentProvider(
|
||||
files, moduleContext.getModule(), moduleContext.getStorageManager(),
|
||||
container.getDeserializationComponentsForJava().getComponents(),
|
||||
incrementalCache, target
|
||||
incrementalCache, targetId
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.rmi.kotlinr
|
||||
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import org.jetbrains.kotlin.rmi.*
|
||||
import java.io.File
|
||||
import java.io.OutputStream
|
||||
@@ -176,10 +176,10 @@ public class KotlinCompilerClient {
|
||||
}
|
||||
}
|
||||
|
||||
public fun incrementalCompile(compiler: CompileService, args: Array<out String>, caches: Map<Module, IncrementalCache>, out: OutputStream): Int {
|
||||
public fun incrementalCompile(compiler: CompileService, args: Array<out String>, caches: Map<TargetId, IncrementalCache>, out: OutputStream): Int {
|
||||
|
||||
val outStrm = RemoteOutputStreamServer(out)
|
||||
val cacheServers = hashMapOf<Module, RemoteIncrementalCacheServer>()
|
||||
val cacheServers = hashMapOf<TargetId, RemoteIncrementalCacheServer>()
|
||||
try {
|
||||
caches.mapValuesTo(cacheServers, { RemoteIncrementalCacheServer( it.getValue()) })
|
||||
return compiler.remoteIncrementalCompile(args, cacheServers, outStrm, CompileService.OutputFormat.XML)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.rmi
|
||||
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.InlineRegistering
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import java.rmi.Remote
|
||||
import java.rmi.RemoteException
|
||||
|
||||
@@ -63,7 +63,7 @@ public interface CompileService : Remote {
|
||||
throws(RemoteException::class)
|
||||
public fun remoteIncrementalCompile(
|
||||
args: Array<out String>,
|
||||
caches: Map<Module, RemoteIncrementalCache>,
|
||||
caches: Map<TargetId, RemoteIncrementalCache>,
|
||||
outputStream: RemoteOutputStream,
|
||||
outputFormat: OutputFormat): Int
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import org.jetbrains.kotlin.rmi.*
|
||||
import org.jetbrains.kotlin.rmi.service.RemoteIncrementalCacheClient
|
||||
import org.jetbrains.kotlin.rmi.service.RemoteOutputStreamClient
|
||||
@@ -81,14 +81,14 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
|
||||
alive = true
|
||||
}
|
||||
|
||||
public class IncrementalCompilationComponentsImpl(val targetToCache: Map<Module, CompileService.RemoteIncrementalCache>): IncrementalCompilationComponents {
|
||||
public class IncrementalCompilationComponentsImpl(val targetToCache: Map<TargetId, CompileService.RemoteIncrementalCache>): IncrementalCompilationComponents {
|
||||
// perf: cheap object, but still the pattern may be costly if there are too many calls to cache with the same id (which seems not to be the case now)
|
||||
override fun getIncrementalCache(target: Module): IncrementalCache = RemoteIncrementalCacheClient(targetToCache[target]!!)
|
||||
override fun getIncrementalCache(target: TargetId): IncrementalCache = RemoteIncrementalCacheClient(targetToCache[target]!!)
|
||||
// TODO: add appropriate proxy into interaction when lookup tracker is needed
|
||||
override fun getLookupTracker(): LookupTracker = LookupTracker.DO_NOTHING
|
||||
}
|
||||
|
||||
private fun createCompileServices(incrementalCaches: Map<Module, CompileService.RemoteIncrementalCache>): Services =
|
||||
private fun createCompileServices(incrementalCaches: Map<TargetId, CompileService.RemoteIncrementalCache>): Services =
|
||||
Services.Builder()
|
||||
.register(IncrementalCompilationComponents::class.java, IncrementalCompilationComponentsImpl(incrementalCaches))
|
||||
// TODO: add remote proxy for cancellation status tracking
|
||||
@@ -187,7 +187,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
|
||||
}
|
||||
}
|
||||
|
||||
override fun remoteIncrementalCompile(args: Array<out String>, caches: Map<Module, CompileService.RemoteIncrementalCache>, outputStream: RemoteOutputStream, outputFormat: CompileService.OutputFormat): Int =
|
||||
override fun remoteIncrementalCompile(args: Array<out String>, caches: Map<TargetId, CompileService.RemoteIncrementalCache>, outputStream: RemoteOutputStream, outputFormat: CompileService.OutputFormat): Int =
|
||||
doCompile(args, outputStream) { printStream ->
|
||||
when (outputFormat) {
|
||||
CompileService.OutputFormat.PLAIN -> throw NotImplementedError("Only XML output is supported in remote incremental compilation")
|
||||
|
||||
@@ -30,15 +30,4 @@ public interface Module {
|
||||
public fun getAnnotationsRoots(): List<String>
|
||||
|
||||
public fun getJavaSourceRoots(): List<String>
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
when {
|
||||
this === other -> true
|
||||
other !is Module -> false
|
||||
else -> getModuleName() == other.getModuleName() &&
|
||||
getModuleType() == other.getModuleType()
|
||||
}
|
||||
|
||||
override fun hashCode(): Int =
|
||||
31 * getModuleName().hashCode() + getModuleType().hashCode()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.modules
|
||||
|
||||
public data class TargetId(public val name: String, public val type: String)
|
||||
|
||||
public fun TargetId(module: Module): TargetId =
|
||||
TargetId(module.getModuleName(), module.getModuleType())
|
||||
@@ -31,7 +31,7 @@ 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.modules.Module;
|
||||
import org.jetbrains.kotlin.modules.TargetId;
|
||||
import org.jetbrains.kotlin.rmi.*;
|
||||
import org.jetbrains.kotlin.rmi.kotlinr.KotlinCompilerClient;
|
||||
import org.jetbrains.kotlin.utils.UtilsPackage;
|
||||
@@ -59,7 +59,7 @@ public class KotlinCompilerRunner {
|
||||
CompilerSettings compilerSettings,
|
||||
MessageCollector messageCollector,
|
||||
CompilerEnvironment environment,
|
||||
Map<Module, IncrementalCache> incrementalCaches,
|
||||
Map<TargetId, IncrementalCache> incrementalCaches,
|
||||
File moduleFile,
|
||||
OutputItemsCollector collector
|
||||
) {
|
||||
@@ -76,7 +76,7 @@ public class KotlinCompilerRunner {
|
||||
@NotNull CompilerSettings compilerSettings,
|
||||
@NotNull MessageCollector messageCollector,
|
||||
@NotNull CompilerEnvironment environment,
|
||||
Map<Module, IncrementalCache> incrementalCaches,
|
||||
Map<TargetId, IncrementalCache> incrementalCaches,
|
||||
@NotNull OutputItemsCollector collector,
|
||||
@NotNull Collection<File> sourceFiles,
|
||||
@NotNull List<String> libraryFiles,
|
||||
@@ -96,7 +96,7 @@ public class KotlinCompilerRunner {
|
||||
MessageCollector messageCollector,
|
||||
OutputItemsCollector collector,
|
||||
CompilerEnvironment environment,
|
||||
Map<Module, IncrementalCache> incrementalCaches
|
||||
Map<TargetId, IncrementalCache> incrementalCaches
|
||||
) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
PrintStream out = new PrintStream(stream);
|
||||
@@ -117,7 +117,7 @@ public class KotlinCompilerRunner {
|
||||
CommonCompilerArguments arguments,
|
||||
String additionalArguments,
|
||||
CompilerEnvironment environment,
|
||||
Map<Module, IncrementalCache> incrementalCaches,
|
||||
Map<TargetId, IncrementalCache> incrementalCaches,
|
||||
PrintStream out,
|
||||
MessageCollector messageCollector
|
||||
) {
|
||||
|
||||
@@ -62,7 +62,7 @@ import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
||||
import org.jetbrains.kotlin.load.kotlin.header.isCompatiblePackageFacadeKind
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledException
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
@@ -320,8 +320,8 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
}
|
||||
|
||||
return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment,
|
||||
incrementalCaches.mapKeysTo(HashMap<Module, IncrementalCache>(incrementalCaches.size()),
|
||||
{ ModuleToModuleBuildTargetAdapter(it.getKey()) }),
|
||||
incrementalCaches.mapKeysTo(HashMap<TargetId, IncrementalCache>(incrementalCaches.size()),
|
||||
{ TargetId(it.getKey()) }),
|
||||
filesToCompile, messageCollector)
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
|| className.startsWith("org.apache.log4j.") // For logging from compiler
|
||||
|| className == "org.jetbrains.kotlin.progress.CompilationCanceledStatus"
|
||||
|| className == "org.jetbrains.kotlin.progress.CompilationCanceledException"
|
||||
|| className == "org.jetbrains.kotlin.modules.Module"
|
||||
|| className == "org.jetbrains.kotlin.modules.TargetId"
|
||||
},
|
||||
compilerServices
|
||||
)
|
||||
@@ -488,7 +488,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
private fun compileToJs(chunk: ModuleChunk,
|
||||
commonArguments: CommonCompilerArguments,
|
||||
environment: CompilerEnvironment,
|
||||
incrementalCaches: MutableMap<Module, IncrementalCache>?,
|
||||
incrementalCaches: MutableMap<TargetId, IncrementalCache>?,
|
||||
messageCollector: MessageCollectorAdapter, project: JpsProject
|
||||
): OutputItemsCollectorImpl? {
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
@@ -543,7 +543,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
context: CompileContext,
|
||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||
environment: CompilerEnvironment,
|
||||
incrementalCaches: MutableMap<Module, IncrementalCache>?,
|
||||
incrementalCaches: MutableMap<TargetId, IncrementalCache>?,
|
||||
filesToCompile: MultiMap<ModuleBuildTarget, File>, messageCollector: MessageCollectorAdapter
|
||||
): OutputItemsCollectorImpl? {
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
|
||||
+3
-29
@@ -20,42 +20,16 @@ import org.jetbrains.jps.incremental.ModuleBuildTarget
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
|
||||
public class IncrementalCompilationComponentsImpl(
|
||||
caches: Map<ModuleBuildTarget, IncrementalCache>,
|
||||
private val lookupTracker: LookupTracker
|
||||
): IncrementalCompilationComponents {
|
||||
private val caches = caches.mapKeys { ModuleToModuleBuildTargetAdapter(it.key) }
|
||||
private val caches = caches.mapKeys { TargetId(it.key) }
|
||||
|
||||
override fun getIncrementalCache(target: Module): IncrementalCache =
|
||||
override fun getIncrementalCache(target: TargetId): IncrementalCache =
|
||||
caches[target]!!
|
||||
|
||||
override fun getLookupTracker(): LookupTracker = lookupTracker
|
||||
}
|
||||
|
||||
public class ModuleToModuleBuildTargetAdapter(
|
||||
private val moduleBuildTarget: ModuleBuildTarget
|
||||
) : Module {
|
||||
|
||||
override fun getModuleName(): String =
|
||||
moduleBuildTarget.id
|
||||
|
||||
override fun getModuleType(): String =
|
||||
moduleBuildTarget.targetType.typeId
|
||||
|
||||
override fun getAnnotationsRoots(): List<String> =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override fun getClasspathRoots(): List<String> =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override fun getJavaSourceRoots(): List<String> =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override fun getOutputDirectory(): String =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override fun getSourceFiles(): List<String> =
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.modules
|
||||
|
||||
import org.jetbrains.jps.incremental.ModuleBuildTarget
|
||||
|
||||
public fun TargetId(moduleBuildTarget: ModuleBuildTarget): TargetId =
|
||||
TargetId(moduleBuildTarget.id, moduleBuildTarget.targetType.typeId)
|
||||
Reference in New Issue
Block a user