Reformat jps-plugin module

Original commit: 455fe7fe61
This commit is contained in:
Alexey Tsvetkov
2018-03-27 16:30:07 +03:00
parent 78ee6ba693
commit d849d47e22
23 changed files with 380 additions and 335 deletions
@@ -25,30 +25,36 @@ import org.jetbrains.kotlin.load.java.NULLABLE_ANNOTATIONS
import java.util.*
internal class NullabilityAnnotationsTracker : AnnotationsChangeTracker() {
private val annotations = (NULLABLE_ANNOTATIONS + JAVAX_NONNULL_ANNOTATION + NOT_NULL_ANNOTATIONS).mapTo(HashSet()) { it.internalNameWithoutInnerClasses }.toTypedArray()
private val annotations =
(NULLABLE_ANNOTATIONS + JAVAX_NONNULL_ANNOTATION + NOT_NULL_ANNOTATIONS).mapTo(HashSet()) { it.internalNameWithoutInnerClasses }
.toTypedArray()
override fun methodAnnotationsChanged(
context: DependencyContext,
method: MethodRepr,
annotationsDiff: Difference.Specifier<ClassType, Difference>,
paramAnnotationsDiff: Difference.Specifier<ParamAnnotation, Difference>
context: DependencyContext,
method: MethodRepr,
annotationsDiff: Difference.Specifier<ClassType, Difference>,
paramAnnotationsDiff: Difference.Specifier<ParamAnnotation, Difference>
): Set<Recompile> {
val changedAnnotations = annotationsDiff.addedOrRemoved() +
paramAnnotationsDiff.addedOrRemoved().map { it.type }
paramAnnotationsDiff.addedOrRemoved().map { it.type }
return handleNullAnnotationsChanges(context, method, changedAnnotations)
}
override fun fieldAnnotationsChanged(
context: NamingContext,
field: FieldRepr,
annotationsDiff: Difference.Specifier<ClassType, Difference>
context: NamingContext,
field: FieldRepr,
annotationsDiff: Difference.Specifier<ClassType, Difference>
): Set<Recompile> {
return handleNullAnnotationsChanges(context, field, annotationsDiff.addedOrRemoved())
}
private fun handleNullAnnotationsChanges(context: NamingContext, protoMember: ProtoMember, annotations: Sequence<TypeRepr.ClassType>): Set<Recompile> {
private fun handleNullAnnotationsChanges(
context: NamingContext,
protoMember: ProtoMember,
annotations: Sequence<TypeRepr.ClassType>
): Set<Recompile> {
val nullabilityAnnotations = TIntHashSet(this.annotations.toIntArray { context.get(it) })
val changedNullAnnotation = annotations.firstOrNull { nullabilityAnnotations.contains(it.className) }
@@ -66,8 +72,8 @@ internal class NullabilityAnnotationsTracker : AnnotationsChangeTracker() {
}
private fun <T> Difference.Specifier<T, Difference>.addedOrRemoved(): Sequence<T> =
added().asSequence() + removed().asSequence()
added().asSequence() + removed().asSequence()
private inline fun <T> Array<T>.toIntArray(fn: (T)->Int): IntArray =
IntArray(size) { i -> fn(get(i)) }
private inline fun <T> Array<T>.toIntArray(fn: (T) -> Int): IntArray =
IntArray(size) { i -> fn(get(i)) }
}
@@ -125,5 +125,4 @@ public class CompilerRunnerUtil {
return null;
}
}
@@ -22,11 +22,11 @@ import org.jetbrains.kotlin.preloading.ClassCondition
import org.jetbrains.kotlin.utils.KotlinPaths
class JpsCompilerEnvironment(
val kotlinPaths: KotlinPaths,
services: Services,
val classesToLoadByParent: ClassCondition,
messageCollector: MessageCollector,
outputItemsCollector: OutputItemsCollectorImpl
val kotlinPaths: KotlinPaths,
services: Services,
val classesToLoadByParent: ClassCondition,
messageCollector: MessageCollector,
outputItemsCollector: OutputItemsCollectorImpl
) : CompilerEnvironment(services, messageCollector, outputItemsCollector) {
override val outputItemsCollector: OutputItemsCollectorImpl
get() = super.outputItemsCollector as OutputItemsCollectorImpl
@@ -26,17 +26,20 @@ import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import java.io.Serializable
internal class JpsCompilerServicesFacadeImpl(
private val env: JpsCompilerEnvironment,
port: Int = SOCKET_ANY_FREE_PORT
) : CompilerCallbackServicesFacadeServer(env.services.get(IncrementalCompilationComponents::class.java),
env.services.get(LookupTracker::class.java),
env.services.get(CompilationCanceledStatus::class.java),
port),
JpsCompilerServicesFacade {
private val env: JpsCompilerEnvironment,
port: Int = SOCKET_ANY_FREE_PORT
) : CompilerCallbackServicesFacadeServer(
env.services.get(IncrementalCompilationComponents::class.java),
env.services.get(LookupTracker::class.java),
env.services.get(CompilationCanceledStatus::class.java),
port
),
JpsCompilerServicesFacade {
override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) {
env.messageCollector.reportFromDaemon(
{ outFile, srcFiles -> env.outputItemsCollector.add(srcFiles, outFile) },
category, severity, message, attachment)
{ outFile, srcFiles -> env.outputItemsCollector.add(srcFiles, outFile) },
category, severity, message, attachment
)
}
}
@@ -39,13 +39,12 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
private var compilerSettings: CompilerSettings? = null
private inline fun withCompilerSettings(settings: CompilerSettings, fn: ()->Unit) {
private inline fun withCompilerSettings(settings: CompilerSettings, fn: () -> Unit) {
val old = compilerSettings
try {
compilerSettings = settings
fn()
}
finally {
} finally {
compilerSettings = old
}
}
@@ -55,14 +54,14 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
private var _jpsCompileServiceSession: CompileServiceSession? = null
@Synchronized
private fun getOrCreateDaemonConnection(newConnection: ()-> CompileServiceSession?): CompileServiceSession? {
private fun getOrCreateDaemonConnection(newConnection: () -> CompileServiceSession?): CompileServiceSession? {
// TODO: consider adding state "ping" to the daemon interface
if (_jpsCompileServiceSession == null || _jpsCompileServiceSession!!.compileService.getDaemonOptions() !is CompileService.CallResult.Good<DaemonOptions>) {
_jpsCompileServiceSession?. let {
_jpsCompileServiceSession?.let {
try {
it.compileService.releaseCompileSession(it.sessionId)
} catch (_: Throwable) {
}
catch (_: Throwable) {}
}
_jpsCompileServiceSession = newConnection()
}
@@ -74,11 +73,11 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
}
fun runK2JvmCompiler(
commonArguments: CommonCompilerArguments,
k2jvmArguments: K2JVMCompilerArguments,
compilerSettings: CompilerSettings,
environment: JpsCompilerEnvironment,
moduleFile: File
commonArguments: CommonCompilerArguments,
k2jvmArguments: K2JVMCompilerArguments,
compilerSettings: CompilerSettings,
environment: JpsCompilerEnvironment,
moduleFile: File
) {
val arguments = mergeBeans(commonArguments, XmlSerializerUtil.createCopy(k2jvmArguments))
setupK2JvmArguments(moduleFile, arguments)
@@ -88,15 +87,15 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
}
fun runK2JsCompiler(
commonArguments: CommonCompilerArguments,
k2jsArguments: K2JSCompilerArguments,
compilerSettings: CompilerSettings,
environment: JpsCompilerEnvironment,
sourceFiles: Collection<File>,
sourceRoots: Collection<File>,
libraries: List<String>,
friendModules: List<String>,
outputFile: File
commonArguments: CommonCompilerArguments,
k2jsArguments: K2JSCompilerArguments,
compilerSettings: CompilerSettings,
environment: JpsCompilerEnvironment,
sourceFiles: Collection<File>,
sourceRoots: Collection<File>,
libraries: List<String>,
friendModules: List<String>,
outputFile: File
) {
log.debug("K2JS: common arguments: " + ArgumentUtils.convertArgumentsToStringList(commonArguments))
log.debug("K2JS: JS arguments: " + ArgumentUtils.convertArgumentsToStringList(k2jsArguments))
@@ -117,25 +116,24 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
}
override fun compileWithDaemonOrFallback(
compilerClassName: String,
compilerArgs: CommonCompilerArguments,
environment: JpsCompilerEnvironment
compilerClassName: String,
compilerArgs: CommonCompilerArguments,
environment: JpsCompilerEnvironment
): ExitCode {
log.debug("Using kotlin-home = " + environment.kotlinPaths.homePath)
return if (isDaemonEnabled()) {
val daemonExitCode = compileWithDaemon(compilerClassName, compilerArgs, environment)
daemonExitCode ?: fallbackCompileStrategy(compilerArgs, compilerClassName, environment)
}
else {
} else {
fallbackCompileStrategy(compilerArgs, compilerClassName, environment)
}
}
override fun compileWithDaemon(
compilerClassName: String,
compilerArgs: CommonCompilerArguments,
environment: JpsCompilerEnvironment
compilerClassName: String,
compilerArgs: CommonCompilerArguments,
environment: JpsCompilerEnvironment
): ExitCode? {
val targetPlatform = when (compilerClassName) {
K2JVM_COMPILER -> CompileService.TargetPlatform.JVM
@@ -154,15 +152,22 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
val (daemon, sessionId) = connection
val compilerMode = CompilerMode.JPS_COMPILER
val verbose = compilerArgs.verbose
val options = CompilationOptions(compilerMode, targetPlatform, reportCategories(verbose), reportSeverity(verbose), requestedCompilationResults = emptyArray())
val res = daemon.compile(sessionId, withAdditionalCompilerArgs(compilerArgs), options, JpsCompilerServicesFacadeImpl(environment), null)
val options = CompilationOptions(
compilerMode,
targetPlatform,
reportCategories(verbose),
reportSeverity(verbose),
requestedCompilationResults = emptyArray()
)
val res =
daemon.compile(sessionId, withAdditionalCompilerArgs(compilerArgs), options, JpsCompilerServicesFacadeImpl(environment), null)
// TODO: consider implementing connection retry, instead of fallback here
return res.takeUnless { it is CompileService.CallResult.Dying }?.let { exitCodeFromProcessExitCode(it.get()) }
}
private fun withAdditionalCompilerArgs(compilerArgs: CommonCompilerArguments): Array<String> {
val allArgs = ArgumentUtils.convertArgumentsToStringList(compilerArgs) +
(compilerSettings?.additionalArgumentsAsList ?: emptyList())
(compilerSettings?.additionalArgumentsAsList ?: emptyList())
return allArgs.toTypedArray()
}
@@ -170,8 +175,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
val categories =
if (!verbose) {
arrayOf(ReportCategory.COMPILER_MESSAGE, ReportCategory.EXCEPTION)
}
else {
} else {
ReportCategory.values()
}
@@ -180,17 +184,16 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
private fun reportSeverity(verbose: Boolean): Int =
if (!verbose) {
ReportSeverity.INFO.code
}
else {
ReportSeverity.DEBUG.code
}
if (!verbose) {
ReportSeverity.INFO.code
} else {
ReportSeverity.DEBUG.code
}
private fun fallbackCompileStrategy(
compilerArgs: CommonCompilerArguments,
compilerClassName: String,
environment: JpsCompilerEnvironment
compilerArgs: CommonCompilerArguments,
compilerClassName: String,
environment: JpsCompilerEnvironment
): ExitCode {
if ("true" == System.getProperty("kotlin.jps.tests") && "true" == System.getProperty(FAIL_ON_FALLBACK_PROPERTY)) {
error("Fallback strategy is disabled in tests!")
@@ -227,7 +230,13 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
}
}
private fun setupK2JsArguments(_outputFile: File, sourceFiles: Collection<File>, _libraries: List<String>, _friendModules: List<String>, settings: K2JSCompilerArguments) {
private fun setupK2JsArguments(
_outputFile: File,
sourceFiles: Collection<File>,
_libraries: List<String>,
_friendModules: List<String>,
settings: K2JSCompilerArguments
) {
with(settings) {
noStdlib = true
freeArgs = sourceFiles.map { it.path }.toMutableList()
@@ -245,15 +254,15 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
}
override fun getDaemonConnection(environment: JpsCompilerEnvironment): CompileServiceSession? =
getOrCreateDaemonConnection {
val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, environment.messageCollector)
val compilerPath = File(libPath, "kotlin-compiler.jar")
val toolsJarPath = CompilerRunnerUtil.getJdkToolsJar()
val compilerId = CompilerId.makeCompilerId(listOfNotNull(compilerPath, toolsJarPath) )
val daemonOptions = configureDaemonOptions()
getOrCreateDaemonConnection {
val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, environment.messageCollector)
val compilerPath = File(libPath, "kotlin-compiler.jar")
val toolsJarPath = CompilerRunnerUtil.getJdkToolsJar()
val compilerId = CompilerId.makeCompilerId(listOfNotNull(compilerPath, toolsJarPath))
val daemonOptions = configureDaemonOptions()
val clientFlagFile = KotlinCompilerClient.getOrCreateClientFlagFile(daemonOptions)
val sessionFlagFile = makeAutodeletingFlagFile("compiler-jps-session-", File(daemonOptions.runFilesPathOrDefault))
newDaemonConnection(compilerId, clientFlagFile, sessionFlagFile, environment, daemonOptions)
}
val clientFlagFile = KotlinCompilerClient.getOrCreateClientFlagFile(daemonOptions)
val sessionFlagFile = makeAutodeletingFlagFile("compiler-jps-session-", File(daemonOptions.runFilesPathOrDefault))
newDaemonConnection(compilerId, clientFlagFile, sessionFlagFile, environment, daemonOptions)
}
}
@@ -69,9 +69,9 @@ class JpsKotlinCompilerSettings : JpsElementBase<JpsKotlinCompilerSettings>() {
val facetArguments = facetSettings.compilerArguments ?: return defaultArguments
return copyBean(facetArguments).apply {
multiPlatform = module
.dependenciesList
.dependencies
.any { (it as? JpsModuleDependency)?.module?.targetPlatform == TargetPlatformKind.Common }
.dependenciesList
.dependencies
.any { (it as? JpsModuleDependency)?.module?.targetPlatform == TargetPlatformKind.Common }
}
}
@@ -30,9 +30,9 @@ import java.io.File
import java.util.HashMap
class FSOperationsHelper(
private val compileContext: CompileContext,
private val chunk: ModuleChunk,
private val log: Logger
private val compileContext: CompileContext,
private val chunk: ModuleChunk,
private val log: Logger
) {
private val moduleBasedFilter = ModulesBasedFileFilter(compileContext, chunk)
@@ -53,8 +53,7 @@ class FSOperationsHelper(
if (recursively) {
FSOperations.markDirtyRecursively(compileContext, CompilationRound.NEXT, chunk, ::shouldMark)
}
else {
} else {
FSOperations.markDirty(compileContext, CompilationRound.NEXT, chunk, ::shouldMark)
}
}
@@ -67,7 +66,7 @@ class FSOperationsHelper(
markFilesImpl(files) { it !in excludeFiles && it.exists() && moduleBasedFilter.accept(it) }
}
private inline fun markFilesImpl(files: Iterable<File>, shouldMark: (File)->Boolean) {
private inline fun markFilesImpl(files: Iterable<File>, shouldMark: (File) -> Boolean) {
val filesToMark = files.filterTo(HashSet(), shouldMark)
if (filesToMark.isEmpty()) return
@@ -83,9 +82,9 @@ class FSOperationsHelper(
// Based on `JavaBuilderUtil#ModulesBasedFileFilter` from Intellij
private class ModulesBasedFileFilter(
private val context: CompileContext,
chunk: ModuleChunk
): Mappings.DependentFilesFilter {
private val context: CompileContext,
chunk: ModuleChunk
) : Mappings.DependentFilesFilter {
private val chunkTargets = chunk.targets
private val buildRootIndex = context.projectDescriptor.buildRootIndex
private val buildTargetIndex = context.projectDescriptor.buildTargetIndex
@@ -70,24 +70,25 @@ object JpsJsModuleUtils {
@JvmStatic
fun getOutputMetaFile(module: JpsModule, isTests: Boolean): File {
val moduleBuildTarget = ModuleBuildTarget(module, if (isTests) JavaModuleBuildTargetType.TEST else JavaModuleBuildTargetType.PRODUCTION)
val moduleBuildTarget =
ModuleBuildTarget(module, if (isTests) JavaModuleBuildTargetType.TEST else JavaModuleBuildTargetType.PRODUCTION)
val outputDir = KotlinBuilderModuleScriptGenerator.getOutputDirSafe(moduleBuildTarget)
return getOutputMetaFile(outputDir, module.name, isTests)
}
@JvmStatic
fun getOutputFile(outputDir: File, moduleName: String, isTests: Boolean)
= File(outputDir, moduleName + suffix(isTests) + KotlinJavascriptMetadataUtils.JS_EXT)
fun getOutputFile(outputDir: File, moduleName: String, isTests: Boolean) =
File(outputDir, moduleName + suffix(isTests) + KotlinJavascriptMetadataUtils.JS_EXT)
@JvmStatic
fun getOutputMetaFile(outputDir: File, moduleName: String, isTests: Boolean)
= File(outputDir, moduleName + suffix(isTests) + KotlinJavascriptMetadataUtils.META_JS_SUFFIX)
fun getOutputMetaFile(outputDir: File, moduleName: String, isTests: Boolean) =
File(outputDir, moduleName + suffix(isTests) + KotlinJavascriptMetadataUtils.META_JS_SUFFIX)
private fun suffix(isTests: Boolean) = if (isTests) "_test" else ""
}
val JpsModule.hasProductionSourceRoot
get() = sourceRoots.any { it.rootType == JavaSourceRootType.SOURCE}
get() = sourceRoots.any { it.rootType == JavaSourceRootType.SOURCE }
val JpsModule.hasTestSourceRoot
get() = sourceRoots.any { it.rootType == JavaSourceRootType.TEST_SOURCE}
get() = sourceRoots.any { it.rootType == JavaSourceRootType.TEST_SOURCE }
@@ -37,7 +37,9 @@ import java.util.concurrent.ConcurrentHashMap;
class JpsUtils {
private static final Map<ModuleBuildTarget, Boolean> IS_KOTLIN_JS_MODULE_CACHE = new ConcurrentHashMap<ModuleBuildTarget, Boolean>();
private static final Map<String, Boolean> IS_KOTLIN_JS_STDLIB_JAR_CACHE = new ConcurrentHashMap<String, Boolean>();
private JpsUtils() {}
private JpsUtils() {
}
@NotNull
static JpsJavaDependenciesEnumerator getAllDependencies(@NotNull ModuleBuildTarget target) {
@@ -66,8 +68,12 @@ class JpsUtils {
Boolean cachedValue = IS_KOTLIN_JS_STDLIB_JAR_CACHE.get(url);
if (cachedValue != null) {
if (cachedValue.booleanValue()) return true;
else continue;
if (cachedValue.booleanValue()) {
return true;
}
else {
continue;
}
}
boolean isKotlinJavascriptStdLibrary = LibraryUtils.isKotlinJavascriptStdLibrary(JpsPathUtil.urlToFile(url));
@@ -29,7 +29,6 @@ import org.jetbrains.jps.builders.java.JavaBuilderUtil
import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor
import org.jetbrains.jps.incremental.*
import org.jetbrains.jps.incremental.ModuleLevelBuilder.ExitCode.*
import org.jetbrains.jps.incremental.fs.CompilationRound
import org.jetbrains.jps.incremental.java.JavaBuilder
import org.jetbrains.jps.incremental.messages.BuildMessage
import org.jetbrains.jps.incremental.messages.CompilerMessage
@@ -70,10 +69,11 @@ import java.io.File
import java.io.IOException
import java.net.URI
import java.util.*
import kotlin.collections.HashSet
class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
companion object {
@JvmField val KOTLIN_BUILDER_NAME: String = "Kotlin Builder"
const val KOTLIN_BUILDER_NAME: String = "Kotlin Builder"
val LOG = Logger.getInstance("#org.jetbrains.kotlin.jps.build.KotlinBuilder")
const val JVM_BUILD_META_INFO_FILE_NAME = "jvm-build-meta-info.txt"
@@ -83,14 +83,14 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val classesToLoadByParent: ClassCondition
get() = ClassCondition { className ->
className.startsWith("org.jetbrains.kotlin.load.kotlin.incremental.components.")
|| className.startsWith("org.jetbrains.kotlin.incremental.components.")
|| className.startsWith("org.jetbrains.kotlin.incremental.js")
|| className == "org.jetbrains.kotlin.config.Services"
|| 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.TargetId"
|| className == "org.jetbrains.kotlin.cli.common.ExitCode"
|| className.startsWith("org.jetbrains.kotlin.incremental.components.")
|| className.startsWith("org.jetbrains.kotlin.incremental.js")
|| className == "org.jetbrains.kotlin.config.Services"
|| 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.TargetId"
|| className == "org.jetbrains.kotlin.cli.common.ExitCode"
}
}
@@ -174,18 +174,19 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
if (!file.exists()) continue
val lastBuildMetaInfo =
try {
JvmBuildMetaInfo.deserializeFromString(file.readText()) ?: continue
}
catch (e: Exception) {
LOG.error("Could not deserialize jvm build meta info", e)
continue
}
try {
JvmBuildMetaInfo.deserializeFromString(file.readText()) ?: continue
} catch (e: Exception) {
LOG.error("Could not deserialize jvm build meta info", e)
continue
}
val lastBuildLangVersion = LanguageVersion.fromVersionString(lastBuildMetaInfo.languageVersionString)
val lastBuildApiVersion = ApiVersion.parse(lastBuildMetaInfo.apiVersionString)
val currentLangVersion = args.languageVersion?.let { LanguageVersion.fromVersionString(it) } ?: LanguageVersion.LATEST_STABLE
val currentApiVersion = args.apiVersion?.let { ApiVersion.parse(it) } ?: ApiVersion.createByLanguageVersion(currentLangVersion)
val currentLangVersion =
args.languageVersion?.let { LanguageVersion.fromVersionString(it) } ?: LanguageVersion.LATEST_STABLE
val currentApiVersion =
args.apiVersion?.let { ApiVersion.parse(it) } ?: ApiVersion.createByLanguageVersion(currentLangVersion)
val reasonToRebuild = when {
currentLangVersion != lastBuildLangVersion -> {
@@ -220,10 +221,10 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
override fun build(
context: CompileContext,
chunk: ModuleChunk,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
outputConsumer: ModuleLevelBuilder.OutputConsumer
context: CompileContext,
chunk: ModuleChunk,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
outputConsumer: ModuleLevelBuilder.OutputConsumer
): ModuleLevelBuilder.ExitCode {
if (chunk.isDummy(context)) return NOTHING_DONE
@@ -235,30 +236,28 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val actualExitCode = if (proposedExitCode == OK && fsOperations.hasMarkedDirty) ADDITIONAL_PASS_REQUIRED else proposedExitCode
LOG.debug("Build result: " + actualExitCode)
LOG.debug("Build result: $actualExitCode")
context.testingContext?.buildLogger?.buildFinished(actualExitCode)
return actualExitCode
}
catch (e: StopBuildException) {
LOG.info("Caught exception: " + e)
} catch (e: StopBuildException) {
LOG.info("Caught exception: $e")
throw e
}
catch (e: Throwable) {
LOG.info("Caught exception: " + e)
} catch (e: Throwable) {
LOG.info("Caught exception: $e")
MessageCollectorUtil.reportException(messageCollector, e)
return ABORT
}
}
private fun doBuild(
chunk: ModuleChunk,
context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
messageCollector: MessageCollectorAdapter,
outputConsumer: OutputConsumer,
fsOperations: FSOperationsHelper
chunk: ModuleChunk,
context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
messageCollector: MessageCollectorAdapter,
outputConsumer: OutputConsumer,
fsOperations: FSOperationsHelper
): ModuleLevelBuilder.ExitCode {
// Workaround for Android Studio
if (!JavaBuilder.IS_ENABLED[context, true] && !JpsUtils.isJsKotlinModule(chunk.representativeTarget())) {
@@ -272,15 +271,14 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val hasKotlin = HasKotlinMarker(dataManager)
val rebuildAfterCacheVersionChanged = RebuildAfterCacheVersionChangeMarker(dataManager)
val isChunkRebuilding = JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)
|| targets.any { rebuildAfterCacheVersionChanged[it] == true }
|| targets.any { rebuildAfterCacheVersionChanged[it] == true }
if (hasKotlinDirtyOrRemovedFiles(dirtyFilesHolder, chunk)) {
if (!isChunkRebuilding && !IncrementalCompilation.isEnabled()) {
targets.forEach { rebuildAfterCacheVersionChanged[it] = true }
return CHUNK_REBUILD_REQUIRED
}
}
else {
} else {
if (isChunkRebuilding) {
targets.forEach { hasKotlin[it] = false }
}
@@ -311,8 +309,10 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
LOG.debug("Compiling files: ${filesToCompile.values()}")
val start = System.nanoTime()
val outputItemCollector = doCompileModuleChunk(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder,
environment, filesToCompile, incrementalCaches, project)
val outputItemCollector = doCompileModuleChunk(
allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder,
environment, filesToCompile, incrementalCaches, project
)
statisticsLogger.registerStatistic(chunk, System.nanoTime() - start)
@@ -324,8 +324,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
if (compilationErrors) {
LOG.info("Compiled with errors")
return ABORT
}
else {
} else {
LOG.info("Compiled successfully")
}
@@ -372,12 +371,12 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
private fun applyActionsOnCacheVersionChange(
actions: Set<CacheVersion.Action>,
cacheVersionsProvider: CacheVersionProvider,
context: CompileContext,
dataManager: BuildDataManager,
targets: MutableSet<ModuleBuildTarget>,
fsOperations: FSOperationsHelper
actions: Set<CacheVersion.Action>,
cacheVersionsProvider: CacheVersionProvider,
context: CompileContext,
dataManager: BuildDataManager,
targets: MutableSet<ModuleBuildTarget>,
fsOperations: FSOperationsHelper
) {
val hasKotlin = HasKotlinMarker(dataManager)
val sortedActions = actions.sorted()
@@ -463,13 +462,13 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
private fun compilerArgumentsForChunk(chunk: ModuleChunk): CommonCompilerArguments =
JpsKotlinCompilerSettings.getCommonCompilerArguments(chunk.representativeTarget().module)
JpsKotlinCompilerSettings.getCommonCompilerArguments(chunk.representativeTarget().module)
private fun doCompileModuleChunk(
allCompiledFiles: MutableSet<File>, chunk: ModuleChunk, commonArguments: CommonCompilerArguments, context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>, environment: JpsCompilerEnvironment,
filesToCompile: MultiMap<ModuleBuildTarget, File>, incrementalCaches: Map<ModuleBuildTarget, IncrementalJvmCache>,
project: JpsProject
allCompiledFiles: MutableSet<File>, chunk: ModuleChunk, commonArguments: CommonCompilerArguments, context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>, environment: JpsCompilerEnvironment,
filesToCompile: MultiMap<ModuleBuildTarget, File>, incrementalCaches: Map<ModuleBuildTarget, IncrementalJvmCache>,
project: JpsProject
): OutputItemsCollector? {
val representativeTarget = chunk.representativeTarget()
@@ -478,11 +477,15 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
for (argumentProvider in ServiceLoader.load(KotlinJpsCompilerArgumentsProvider::class.java)) {
// appending to pluginOptions
commonArguments.pluginOptions = concatenate(commonArguments.pluginOptions,
argumentProvider.getExtraArguments(representativeTarget, context))
commonArguments.pluginOptions = concatenate(
commonArguments.pluginOptions,
argumentProvider.getExtraArguments(representativeTarget, context)
)
// appending to classpath
commonArguments.pluginClasspaths = concatenate(commonArguments.pluginClasspaths,
argumentProvider.getClasspath(representativeTarget, context))
commonArguments.pluginClasspaths = concatenate(
commonArguments.pluginClasspaths,
argumentProvider.getClasspath(representativeTarget, context)
)
LOG.debug("Plugin loaded: ${argumentProvider::class.java.simpleName}")
}
@@ -504,15 +507,17 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
private fun createCompileEnvironment(
incrementalCaches: Map<ModuleBuildTarget, IncrementalCache>,
lookupTracker: LookupTracker,
context: CompileContext,
messageCollector: MessageCollectorAdapter
incrementalCaches: Map<ModuleBuildTarget, IncrementalCache>,
lookupTracker: LookupTracker,
context: CompileContext,
messageCollector: MessageCollectorAdapter
): JpsCompilerEnvironment? {
val compilerServices = with(Services.Builder()) {
register(LookupTracker::class.java, lookupTracker)
register(IncrementalCompilationComponents::class.java,
IncrementalCompilationComponentsImpl(incrementalCaches.mapKeys { TargetId(it.key) }))
register(
IncrementalCompilationComponents::class.java,
IncrementalCompilationComponentsImpl(incrementalCaches.mapKeys { TargetId(it.key) })
)
register(CompilationCanceledStatus::class.java, object : CompilationCanceledStatus {
override fun checkCanceled() {
if (context.cancelStatus.isCanceled) throw CompilationCanceledException()
@@ -523,17 +528,19 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val paths = computeKotlinPathsForJpsPlugin()
if (paths == null || !paths.homePath.exists()) {
messageCollector.report(ERROR, "Cannot find kotlinc home. Make sure the plugin is properly installed, " +
"or specify $JPS_KOTLIN_HOME_PROPERTY system property")
messageCollector.report(
ERROR, "Cannot find kotlinc home. Make sure the plugin is properly installed, " +
"or specify $JPS_KOTLIN_HOME_PROPERTY system property"
)
return null
}
return JpsCompilerEnvironment(
paths,
compilerServices,
classesToLoadByParent,
messageCollector,
OutputItemsCollectorImpl()
paths,
compilerServices,
classesToLoadByParent,
messageCollector,
OutputItemsCollectorImpl()
)
}
@@ -559,35 +566,39 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
private fun getGeneratedFiles(
chunk: ModuleChunk,
outputItemCollector: OutputItemsCollectorImpl
chunk: ModuleChunk,
outputItemCollector: OutputItemsCollectorImpl
): Map<ModuleBuildTarget, List<GeneratedFile>> {
// If there's only one target, this map is empty: get() always returns null, and the representativeTarget will be used below
val sourceToTarget = HashMap<File, ModuleBuildTarget>()
if (chunk.targets.size > 1) {
for (target in chunk.targets) {
for (file in KotlinSourceFileCollector.getAllKotlinSourceFiles(target)) {
sourceToTarget.put(file, target)
sourceToTarget[file] = target
}
}
}
val representativeTarget = chunk.representativeTarget()
fun SimpleOutputItem.target() =
sourceFiles.firstOrNull()?.let { sourceToTarget[it] } ?:
chunk.targets.singleOrNull { it.outputDir?.let { outputFile.startsWith(it) } ?: false } ?:
representativeTarget
sourceFiles.firstOrNull()?.let { sourceToTarget[it] } ?: chunk.targets.singleOrNull {
it.outputDir?.let {
outputFile.startsWith(
it
)
} ?: false
} ?: representativeTarget
return outputItemCollector.outputs.groupBy(SimpleOutputItem::target, SimpleOutputItem::toGeneratedFile)
}
private fun updateJavaMappings(
chunk: ModuleChunk,
context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
filesToCompile: MultiMap<ModuleBuildTarget, File>,
outputItems: Map<ModuleBuildTarget, Iterable<GeneratedFile>>,
incrementalCaches: Map<ModuleBuildTarget, JpsIncrementalJvmCache>
chunk: ModuleChunk,
context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
filesToCompile: MultiMap<ModuleBuildTarget, File>,
outputItems: Map<ModuleBuildTarget, Iterable<GeneratedFile>>,
incrementalCaches: Map<ModuleBuildTarget, JpsIncrementalJvmCache>
) {
val previousMappings = context.projectDescriptor.dataManager.mappings
val callback = JavaBuilderUtil.getDependenciesRegistrar(context)
@@ -619,9 +630,9 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
sourceFiles.addAll(output.sourceFiles)
callback.associate(
FileUtil.toSystemIndependentName(output.outputFile.canonicalPath),
sourceFiles.map { FileUtil.toSystemIndependentName(it.canonicalPath) },
ClassReader(output.outputClass.fileContents)
FileUtil.toSystemIndependentName(output.outputFile.canonicalPath),
sourceFiles.map { FileUtil.toSystemIndependentName(it.canonicalPath) },
ClassReader(output.outputClass.fileContents)
)
}
}
@@ -640,13 +651,14 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
private fun updateLookupStorage(
chunk: ModuleChunk,
lookupTracker: LookupTracker,
dataManager: BuildDataManager,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
filesToCompile: MultiMap<ModuleBuildTarget, File>
chunk: ModuleChunk,
lookupTracker: LookupTracker,
dataManager: BuildDataManager,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
filesToCompile: MultiMap<ModuleBuildTarget, File>
) {
if (lookupTracker !is LookupTrackerImpl) throw AssertionError("Lookup tracker is expected to be LookupTrackerImpl, got ${lookupTracker::class.java}")
if (lookupTracker !is LookupTrackerImpl)
throw AssertionError("Lookup tracker is expected to be LookupTrackerImpl, got ${lookupTracker::class.java}")
val removedFiles = chunk.targets.flatMap { KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, it) }
dataManager.withLookupStorage { lookupStorage ->
@@ -656,20 +668,21 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
// if null is returned, nothing was done
private fun compileToJs(chunk: ModuleChunk,
commonArguments: CommonCompilerArguments,
environment: JpsCompilerEnvironment,
project: JpsProject
private fun compileToJs(
chunk: ModuleChunk,
commonArguments: CommonCompilerArguments,
environment: JpsCompilerEnvironment,
project: JpsProject
): OutputItemsCollector? {
val representativeTarget = chunk.representativeTarget()
if (chunk.modules.size > 1) {
// We do not support circular dependencies, but if they are present, we do our best should not break the build,
// so we simply yield a warning and report NOTHING_DONE
environment.messageCollector.report(
STRONG_WARNING,
"Circular dependencies are not supported. The following JS modules depend on each other: "
+ chunk.modules.joinToString(", ") { it.name } + ". "
+ "Kotlin is not compiled for these modules"
STRONG_WARNING,
"Circular dependencies are not supported. The following JS modules depend on each other: "
+ chunk.modules.joinToString(", ") { it.name } + ". "
+ "Kotlin is not compiled for these modules"
)
return null
}
@@ -698,12 +711,11 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
// If prefix is not specified (empty) in UI, we want to produce paths relative to source maps location
val sourceRoots = if (k2JsArguments.sourceMapPrefix.isNullOrBlank()) {
emptyList()
}
else {
} else {
representativeModule.contentRootsList.urls
.map { URI.create(it) }
.filter { it.scheme == "file" }
.map { File(it.path) }
.map { URI.create(it) }
.filter { it.scheme == "file" }
.map { File(it.path) }
}
val friendPaths = KotlinBuilderModuleScriptGenerator.getProductionModulesWhichInternalsAreVisible(representativeTarget).mapNotNull {
@@ -712,8 +724,10 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
val compilerRunner = JpsKotlinCompilerRunner()
compilerRunner.runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, environment, sourceFiles, sourceRoots,
libraries, friendPaths, outputFile)
compilerRunner.runK2JsCompiler(
commonArguments, k2JsArguments, compilerSettings, environment, sourceFiles, sourceRoots,
libraries, friendPaths, outputFile
)
return environment.outputItemsCollector
}
@@ -726,26 +740,29 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val outputLibraryRuntimeDirectory = File(outputDir, compilerSettings.outputDirectoryForJsLibraryFiles).absolutePath
val libraryFilesToCopy = arrayListOf<String>()
JpsJsModuleUtils.getLibraryFiles(representativeTarget, libraryFilesToCopy)
JsLibraryUtils.copyJsFilesFromLibraries(libraryFilesToCopy, outputLibraryRuntimeDirectory,
copySourceMap = k2jsCompilerSettings.sourceMap)
JsLibraryUtils.copyJsFilesFromLibraries(
libraryFilesToCopy, outputLibraryRuntimeDirectory,
copySourceMap = k2jsCompilerSettings.sourceMap
)
}
}
// if null is returned, nothing was done
private fun compileToJvm(allCompiledFiles: MutableSet<File>,
chunk: ModuleChunk,
commonArguments: CommonCompilerArguments,
context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
environment: JpsCompilerEnvironment,
filesToCompile: MultiMap<ModuleBuildTarget, File>
private fun compileToJvm(
allCompiledFiles: MutableSet<File>,
chunk: ModuleChunk,
commonArguments: CommonCompilerArguments,
context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
environment: JpsCompilerEnvironment,
filesToCompile: MultiMap<ModuleBuildTarget, File>
): OutputItemsCollector? {
if (chunk.modules.size > 1) {
environment.messageCollector.report(
STRONG_WARNING,
"Circular dependencies are only partially supported. The following modules depend on each other: "
+ chunk.modules.joinToString(", ") { it.name } + ". "
+ "Kotlin will compile them, but some strange effect may happen"
STRONG_WARNING,
"Circular dependencies are only partially supported. The following modules depend on each other: "
+ chunk.modules.joinToString(", ") { it.name } + ". "
+ "Kotlin will compile them, but some strange effect may happen"
)
}
@@ -763,7 +780,8 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
}
val moduleFile = KotlinBuilderModuleScriptGenerator.generateModuleDescription(context, chunk, filesToCompile, totalRemovedFiles != 0)
val moduleFile =
KotlinBuilderModuleScriptGenerator.generateModuleDescription(context, chunk, filesToCompile, totalRemovedFiles != 0)
if (moduleFile == null) {
KotlinBuilder.LOG.debug("Not compiling, because no files affected: " + filesToCompile.keySet().joinToString { it.presentableName })
// No Kotlin sources found
@@ -775,14 +793,13 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(module)
KotlinBuilder.LOG.debug("Compiling to JVM ${filesToCompile.values().size} files"
+ (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)")
+ " in " + filesToCompile.keySet().joinToString { it.presentableName })
+ (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)")
+ " in " + filesToCompile.keySet().joinToString { it.presentableName })
try {
val compilerRunner = JpsKotlinCompilerRunner()
compilerRunner.runK2JvmCompiler(commonArguments, k2JvmArguments, compilerSettings, environment, moduleFile)
}
finally {
} finally {
if (System.getProperty("kotlin.jps.delete.module.file.after.build") != "false") {
moduleFile.delete()
}
@@ -802,7 +819,8 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
val kind = kind(severity)
if (kind != null) {
context.processMessage(CompilerMessage(
context.processMessage(
CompilerMessage(
CompilerRunnerConstants.KOTLIN_COMPILER_NAME,
kind,
prefix + message,
@@ -810,9 +828,9 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
-1, -1, -1,
location?.line?.toLong() ?: -1,
location?.column?.toLong() ?: -1
))
}
else {
)
)
} else {
val path = if (location != null) "${location.path}:${location.line}:${location.column}: " else ""
KotlinBuilder.LOG.debug(path + message)
}
@@ -830,7 +848,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
ERROR, EXCEPTION -> BuildMessage.Kind.ERROR
WARNING, STRONG_WARNING -> BuildMessage.Kind.WARNING
LOGGING -> null
else -> throw IllegalArgumentException("Unsupported severity: " + severity)
else -> throw IllegalArgumentException("Unsupported severity: $severity")
}
}
}
@@ -845,10 +863,10 @@ private class JpsICReporter : ICReporter {
}
private fun ChangesCollector.processChangesUsingLookups(
compiledFiles: Set<File>,
dataManager: BuildDataManager,
fsOperations: FSOperationsHelper,
caches: Iterable<IncrementalJvmCache>
compiledFiles: Set<File>,
dataManager: BuildDataManager,
fsOperations: FSOperationsHelper,
caches: Iterable<IncrementalJvmCache>
) {
val allCaches = caches.flatMap { it.thisWithDependentCaches }
val reporter = JpsICReporter()
@@ -890,8 +908,8 @@ private fun getIncrementalCaches(chunk: ModuleChunk, context: CompileContext): M
}
fun getDependentTargets(
compilingChunk: ModuleChunk,
context: CompileContext
compilingChunk: ModuleChunk,
context: CompileContext
): Set<ModuleBuildTarget> {
val compilingChunkIsTests = compilingChunk.targets.any { it.isTests }
val classpathKind = JpsJavaClasspathKind.compile(compilingChunkIsTests)
@@ -922,10 +940,11 @@ fun getDependentTargets(
}
private fun getDependenciesRecursively(module: JpsModule, kind: JpsJavaClasspathKind): Set<JpsModule> =
JpsJavaExtensionService.dependencies(module).includedIn(kind).recursivelyExportedOnly().modules
JpsJavaExtensionService.dependencies(module).includedIn(kind).recursivelyExportedOnly().modules
// TODO: investigate thread safety
private val ALL_COMPILED_FILES_KEY = Key.create<MutableSet<File>>("_all_kotlin_compiled_files_")
private fun getAllCompiledFilesContainer(context: CompileContext): MutableSet<File> {
var allCompiledFiles = ALL_COMPILED_FILES_KEY.get(context)
if (allCompiledFiles == null) {
@@ -937,18 +956,19 @@ private fun getAllCompiledFilesContainer(context: CompileContext): MutableSet<Fi
// TODO: investigate thread safety
private val PROCESSED_TARGETS_WITH_REMOVED_FILES = Key.create<MutableSet<ModuleBuildTarget>>("_processed_targets_with_removed_files_")
private fun getProcessedTargetsWithRemovedFilesContainer(context: CompileContext): MutableSet<ModuleBuildTarget> {
var set = PROCESSED_TARGETS_WITH_REMOVED_FILES.get(context)
if (set == null) {
set = HashSet<ModuleBuildTarget>()
set = HashSet()
PROCESSED_TARGETS_WITH_REMOVED_FILES.set(context, set)
}
return set
}
private fun hasKotlinDirtyOrRemovedFiles(
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
chunk: ModuleChunk
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
chunk: ModuleChunk
): Boolean {
if (!dirtyFilesHolder.hasDirtyFiles() && !dirtyFilesHolder.hasRemovedFiles()) return false
@@ -958,4 +978,4 @@ private fun hasKotlinDirtyOrRemovedFiles(
}
fun jvmBuildMetaInfoFile(target: ModuleBuildTarget, dataManager: BuildDataManager): File =
File(dataManager.dataPaths.getTargetDataRoot(target), KotlinBuilder.JVM_BUILD_META_INFO_FILE_NAME)
File(dataManager.dataPaths.getTargetDataRoot(target), KotlinBuilder.JVM_BUILD_META_INFO_FILE_NAME)
@@ -51,21 +51,21 @@ object KotlinBuilderModuleScriptGenerator {
// TODO switch to directly using when "since-build" will be >= 144.3357.4
internal val getRelatedProductionModule: (JpsModule) -> JpsModule? = run {
val klass =
try {
Class.forName("org.jetbrains.jps.model.module.JpsTestModuleProperties")
} catch (e: ClassNotFoundException) {
return@run alwaysNull()
}
try {
Class.forName("org.jetbrains.jps.model.module.JpsTestModuleProperties")
} catch (e: ClassNotFoundException) {
return@run alwaysNull()
}
val getTestModulePropertiesMethod: Method
val getProductionModuleMethod: Method
try {
getTestModulePropertiesMethod = JpsJavaExtensionService::class.java.getDeclaredMethod("getTestModuleProperties", JpsModule::class.java)
getTestModulePropertiesMethod =
JpsJavaExtensionService::class.java.getDeclaredMethod("getTestModuleProperties", JpsModule::class.java)
getProductionModuleMethod = klass.getDeclaredMethod("getProductionModule")
}
catch (e: NoSuchMethodException) {
} catch (e: NoSuchMethodException) {
return@run alwaysNull()
}
@@ -77,10 +77,10 @@ object KotlinBuilderModuleScriptGenerator {
}
fun generateModuleDescription(
context: CompileContext,
chunk: ModuleChunk,
sourceFiles: MultiMap<ModuleBuildTarget, File>, // ignored for non-incremental compilation
hasRemovedFiles: Boolean
context: CompileContext,
chunk: ModuleChunk,
sourceFiles: MultiMap<ModuleBuildTarget, File>, // ignored for non-incremental compilation
hasRemovedFiles: Boolean
): File? {
val builder = KotlinModuleXmlBuilder()
@@ -97,10 +97,11 @@ object KotlinBuilderModuleScriptGenerator {
val friendDirs = getAdditionalOutputDirsWhereInternalsAreVisible(target)
val moduleSources = ArrayList(
if (IncrementalCompilation.isEnabled())
sourceFiles.get(target)
else
KotlinSourceFileCollector.getAllKotlinSourceFiles(target))
if (IncrementalCompilation.isEnabled())
sourceFiles.get(target)
else
KotlinSourceFileCollector.getAllKotlinSourceFiles(target)
)
if (moduleSources.size > 0 || hasRemovedFiles) {
noSources = false
@@ -114,17 +115,18 @@ object KotlinBuilderModuleScriptGenerator {
assert(targetType is JavaModuleBuildTargetType)
val targetId = TargetId(target)
builder.addModule(
targetId.name,
outputDir.absolutePath,
moduleSources,
findSourceRoots(context, target),
findClassPathRoots(target),
findModularJdkRoot(target),
targetId.type,
(targetType as JavaModuleBuildTargetType).isTests,
// this excludes the output directories from the class path, to be removed for true incremental compilation
outputDirs,
friendDirs)
targetId.name,
outputDir.absolutePath,
moduleSources,
findSourceRoots(context, target),
findClassPathRoots(target),
findModularJdkRoot(target),
targetId.type,
(targetType as JavaModuleBuildTargetType).isTests,
// this excludes the output directories from the class path, to be removed for true incremental compilation
outputDirs,
friendDirs
)
}
if (noSources) return null
@@ -144,14 +146,12 @@ object KotlinBuilderModuleScriptGenerator {
val dir = System.getProperty("kotlin.jps.dir.for.module.files")?.let { File(it) }?.takeIf { it.isDirectory }
return try {
File.createTempFile("kjps", readableSuffix + ".script.xml", dir)
}
catch (e: IOException) {
} catch (e: IOException) {
// sometimes files cannot be created, because file name is too long (Windows, Mac OS)
// see https://bugs.openjdk.java.net/browse/JDK-8148023
try {
File.createTempFile("kjps", ".script.xml", dir)
}
catch (e: IOException) {
} catch (e: IOException) {
val message = buildString {
append("Could not create module file when building chunk $chunk")
if (dir != null) {
@@ -203,8 +203,8 @@ object KotlinBuilderModuleScriptGenerator {
// List of paths to JRE modules in the following format:
// jrt:///Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home!/java.base
val urls = JpsJavaExtensionService.dependencies(target.module)
.satisfying { dependency -> dependency is JpsSdkDependency }
.classes().urls
.satisfying { dependency -> dependency is JpsSdkDependency }
.classes().urls
val url = urls.firstOrNull { it.startsWith(StandardFileSystems.JRT_PROTOCOL_PREFIX) } ?: return null
@@ -42,8 +42,7 @@ public class KotlinSourceFileCollector {
// For incremental compilation
@NotNull
public static MultiMap<ModuleBuildTarget, File> getDirtySourceFiles(DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder)
throws IOException
{
throws IOException {
final MultiMap<ModuleBuildTarget, File> result = new MultiMap<ModuleBuildTarget, File>();
dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {
@@ -84,15 +83,17 @@ public class KotlinSourceFileCollector {
@NotNull
public static List<File> getAllKotlinSourceFiles(@NotNull ModuleBuildTarget target) {
final List<File> moduleExcludes = ContainerUtil.map(target.getModule().getExcludeRootsList().getUrls(), new Function<String, File>() {
@Override
public File fun(String url) {
return JpsPathUtil.urlToFile(url);
}
});
final List<File> moduleExcludes =
ContainerUtil.map(target.getModule().getExcludeRootsList().getUrls(), new Function<String, File>() {
@Override
public File fun(String url) {
return JpsPathUtil.urlToFile(url);
}
});
final JpsCompilerExcludes compilerExcludes =
JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(target.getModule().getProject()).getCompilerExcludes();
JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(target.getModule().getProject())
.getCompilerExcludes();
final List<File> result = ContainerUtil.newArrayList();
for (JpsModuleSourceRoot sourceRoot : getRelevantSourceRoots(target)) {
@@ -135,5 +136,6 @@ public class KotlinSourceFileCollector {
return FileUtilRt.extensionEquals(file.getName(), "kt");
}
private KotlinSourceFileCollector() {}
private KotlinSourceFileCollector() {
}
}
@@ -57,4 +57,5 @@ abstract class MarkerFile(private val fileName: String, private val paths: Build
}
class HasKotlinMarker(dataManager: BuildDataManager) : MarkerFile(HAS_KOTLIN_MARKER_FILE_NAME, dataManager.dataPaths)
class RebuildAfterCacheVersionChangeMarker(dataManager: BuildDataManager) : MarkerFile(REBUILD_AFTER_CACHE_VERSION_CHANGE_MARKER, dataManager.dataPaths)
class RebuildAfterCacheVersionChangeMarker(dataManager: BuildDataManager) :
MarkerFile(REBUILD_AFTER_CACHE_VERSION_CHANGE_MARKER, dataManager.dataPaths)
@@ -47,8 +47,7 @@ class TeamcityStatisticsLogger {
val escChar = escapedChar(c)
if (escChar == 0.toChar()) {
escaped.append(c)
}
else {
} else {
escaped.append('|').append(escChar)
}
}
@@ -65,8 +64,8 @@ class TeamcityStatisticsLogger {
private fun printPerChunkStatistics(moduleChunk: ModuleChunk, timeToCompileNs: Long) {
printStatisticMessage(
"${KotlinBuilder.KOTLIN_BUILDER_NAME} for ${moduleChunk.presentableShortName} compilation time, ms",
timeToCompileNs.nanosToMillis().toString()
"${KotlinBuilder.KOTLIN_BUILDER_NAME} for ${moduleChunk.presentableShortName} compilation time, ms",
timeToCompileNs.nanosToMillis().toString()
)
}
@@ -74,8 +73,8 @@ class TeamcityStatisticsLogger {
if (!isOnTeamcity) return
printStatisticMessage(
"${KotlinBuilder.KOTLIN_BUILDER_NAME} total compilation time, ms",
totalTime.get().nanosToMillis().toString()
"${KotlinBuilder.KOTLIN_BUILDER_NAME} total compilation time, ms",
totalTime.get().nanosToMillis().toString()
)
}
@@ -26,8 +26,8 @@ import org.jetbrains.kotlin.jps.build.KotlinBuilder
import java.io.File
class JpsIncrementalJvmCache(
target: ModuleBuildTarget,
paths: BuildDataPaths
target: ModuleBuildTarget,
paths: BuildDataPaths
) : IncrementalJvmCache(paths.getTargetDataRoot(target), target.outputDir), StorageOwner {
override fun debugLog(message: String) {
KotlinBuilder.LOG.debug(message)
@@ -35,8 +35,8 @@ class JpsIncrementalJvmCache(
}
private class KotlinIncrementalStorageProvider(
private val target: ModuleBuildTarget,
private val paths: BuildDataPaths
private val target: ModuleBuildTarget,
private val paths: BuildDataPaths
) : StorageProvider<JpsIncrementalJvmCache>() {
override fun equals(other: Any?) = other is KotlinIncrementalStorageProvider && target == other.target
@@ -44,9 +44,9 @@ private class KotlinIncrementalStorageProvider(
override fun hashCode() = target.hashCode()
override fun createStorage(targetDataDir: File): JpsIncrementalJvmCache =
JpsIncrementalJvmCache(target, paths)
JpsIncrementalJvmCache(target, paths)
}
fun BuildDataManager.getKotlinCache(target: ModuleBuildTarget): JpsIncrementalJvmCache =
getStorage(target, KotlinIncrementalStorageProvider(target, dataPaths))
getStorage(target, KotlinIncrementalStorageProvider(target, dataPaths))
@@ -30,9 +30,9 @@ object KotlinDataContainerTargetType : BuildTargetType<KotlinDataContainerTarget
override fun computeAllTargets(model: JpsModel): List<KotlinDataContainerTarget> = listOf(KotlinDataContainerTarget)
override fun createLoader(model: JpsModel): BuildTargetLoader<KotlinDataContainerTarget> =
object : BuildTargetLoader<KotlinDataContainerTarget>() {
override fun createTarget(targetId: String): KotlinDataContainerTarget? = KotlinDataContainerTarget
}
object : BuildTargetLoader<KotlinDataContainerTarget>() {
override fun createTarget(targetId: String): KotlinDataContainerTarget? = KotlinDataContainerTarget
}
}
// Fake target to store data per project for incremental compilation
@@ -41,10 +41,10 @@ object KotlinDataContainerTarget : BuildTarget<BuildRootDescriptor>(KotlinDataCo
override fun getPresentableName(): String = KOTLIN_DATA_CONTAINER
override fun computeRootDescriptors(
model: JpsModel?,
index: ModuleExcludeIndex?,
ignoredFileIndex: IgnoredFileIndex?,
dataPaths: BuildDataPaths?
model: JpsModel?,
index: ModuleExcludeIndex?,
ignoredFileIndex: IgnoredFileIndex?,
dataPaths: BuildDataPaths?
): List<BuildRootDescriptor> = listOf()
override fun getOutputRoots(context: CompileContext): Collection<File> {
@@ -56,7 +56,7 @@ object KotlinDataContainerTarget : BuildTarget<BuildRootDescriptor>(KotlinDataCo
override fun findRootDescriptor(rootId: String?, rootIndex: BuildRootIndex?): BuildRootDescriptor? = null
override fun computeDependencies(
targetRegistry: BuildTargetRegistry?,
outputIndex: TargetOutputIndex?
targetRegistry: BuildTargetRegistry?,
outputIndex: TargetOutputIndex?
): Collection<BuildTarget<*>>? = listOf()
}
@@ -19,9 +19,9 @@ package org.jetbrains.kotlin.jps.incremental.storages
import com.intellij.openapi.util.io.FileUtil
class PathFunctionPair(
val path: String,
val function: String
): Comparable<PathFunctionPair> {
val path: String,
val function: String
) : Comparable<PathFunctionPair> {
override fun compareTo(other: PathFunctionPair): Int {
val pathComp = FileUtil.comparePaths(path, other.path)
@@ -31,12 +31,12 @@ class PathFunctionPair(
}
override fun equals(other: Any?): Boolean =
when (other) {
is PathFunctionPair ->
FileUtil.pathsEqual(path, other.path) && function == other.function
else ->
false
}
when (other) {
is PathFunctionPair ->
FileUtil.pathsEqual(path, other.path) && function == other.function
else ->
false
}
override fun hashCode(): Int = 31 * FileUtil.pathHashCode(path) + function.hashCode()
}
@@ -24,9 +24,9 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.config.SettingConstants
abstract class BaseJpsCompilerSettingsSerializer<T : Any>(
componentName: String,
private val settingsFactory: () -> T
): JpsProjectExtensionSerializer(SettingConstants.KOTLIN_COMPILER_SETTINGS_FILE, componentName) {
componentName: String,
private val settingsFactory: () -> T
) : JpsProjectExtensionSerializer(SettingConstants.KOTLIN_COMPILER_SETTINGS_FILE, componentName) {
protected abstract fun onLoad(project: JpsProject, settings: T)
override fun loadExtension(project: JpsProject, componentTag: Element) {
@@ -24,23 +24,23 @@ import org.jetbrains.kotlin.config.deserializeFacetSettings
import org.jetbrains.kotlin.config.serializeFacetSettings
object JpsKotlinFacetConfigurationSerializer : JpsFacetConfigurationSerializer<JpsKotlinFacetModuleExtension>(
JpsKotlinFacetModuleExtension.KIND,
JpsKotlinFacetModuleExtension.FACET_TYPE_ID,
JpsKotlinFacetModuleExtension.FACET_NAME
JpsKotlinFacetModuleExtension.KIND,
JpsKotlinFacetModuleExtension.FACET_TYPE_ID,
JpsKotlinFacetModuleExtension.FACET_NAME
) {
override fun loadExtension(
facetConfigurationElement: Element,
name: String,
parent: JpsElement?,
module: JpsModule
facetConfigurationElement: Element,
name: String,
parent: JpsElement?,
module: JpsModule
): JpsKotlinFacetModuleExtension {
return JpsKotlinFacetModuleExtension(deserializeFacetSettings(facetConfigurationElement))
}
override fun saveExtension(
extension: JpsKotlinFacetModuleExtension?,
facetConfigurationTag: Element,
module: JpsModule
extension: JpsKotlinFacetModuleExtension?,
facetConfigurationTag: Element,
module: JpsModule
) {
(extension as JpsKotlinFacetModuleExtension).settings.serializeFacetSettings(facetConfigurationTag)
}
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JS_COMPILER_ARGUME
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
internal class Kotlin2JsCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer<K2JSCompilerArguments>(
KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION, ::K2JSCompilerArguments
KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION, ::K2JSCompilerArguments
) {
override fun onLoad(project: JpsProject, settings: K2JSCompilerArguments) {
JpsKotlinCompilerSettings.setK2JsCompilerArguments(project, settings)
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JVM_COMPILER_ARGUM
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
internal class Kotlin2JvmCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer<K2JVMCompilerArguments>(
KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION, ::K2JVMCompilerArguments
KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION, ::K2JVMCompilerArguments
) {
override fun onLoad(project: JpsProject, settings: K2JVMCompilerArguments) {
JpsKotlinCompilerSettings.setK2JvmCompilerArguments(project, settings)
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMMON_COMPILER_ARGUM
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
internal class KotlinCommonCompilerArgumentsSerializer : BaseJpsCompilerSettingsSerializer<CommonCompilerArguments.DummyImpl>(
KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION, CommonCompilerArguments::DummyImpl
KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION, CommonCompilerArguments::DummyImpl
) {
override fun onLoad(project: JpsProject, settings: CommonCompilerArguments.DummyImpl) {
settings.setApiVersionToLanguageVersionIfNeeded()
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMPILER_SETTINGS_SEC
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
internal class KotlinCompilerSettingsSerializer : BaseJpsCompilerSettingsSerializer<CompilerSettings>(
KOTLIN_COMPILER_SETTINGS_SECTION, ::CompilerSettings
KOTLIN_COMPILER_SETTINGS_SECTION, ::CompilerSettings
) {
override fun onLoad(project: JpsProject, settings: CompilerSettings) {
JpsKotlinCompilerSettings.setCompilerSettings(project, settings)