JPS: report about unsupported targets once

Report about unsupported targets once per target type, show presentable
chunks list and don't show more then 5 chunks.

Example: "Native is not yet supported in IDEA internal build system.
Please use Gradle to build a, b, c, d, e and 10 other  (enable 'Delegate
IDE build/run actions to Gradle' in Settings)."

#KT-26980 Fixed
#KT-28316 Fixed
This commit is contained in:
Sergey Rostov
2018-11-26 15:50:24 +03:00
parent ab2b4311fd
commit 62b0b3e4e9
5 changed files with 128 additions and 18 deletions
@@ -0,0 +1,59 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.jps.build
import com.intellij.testFramework.UsefulTestCase
class JoinToReadableStringTest : UsefulTestCase() {
fun test0() {
assertEquals(
"",
listOf<String>().joinToReadableString()
)
}
fun test1() {
assertEquals(
"a",
listOf("a").joinToReadableString()
)
}
fun test2() {
assertEquals(
"a and b",
listOf("a", "b").joinToReadableString()
)
}
fun test3() {
assertEquals(
"a, b and c",
listOf("a", "b", "c").joinToReadableString()
)
}
fun test4() {
assertEquals(
"a, b, c and d",
listOf("a", "b", "c", "d").joinToReadableString()
)
}
fun test5() {
assertEquals(
"a, b, c, d and e",
listOf("a", "b", "c", "d", "e").joinToReadableString()
)
}
fun test6() {
assertEquals(
"a, b, c, d, e and 1 more",
listOf("a", "b", "c", "d", "e", "f").joinToReadableString()
)
}
}
@@ -143,6 +143,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
}
kotlinContext.cleanupCaches()
kotlinContext.reportUnsupportedTargets()
}
LOG.info("Total Kotlin global compile context initialization time: $time ms")
@@ -344,16 +345,6 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
return ABORT
}
if (representativeTarget is KotlinUnsupportedModuleBuildTarget) {
val msg = "${representativeTarget.kind} is not yet supported in IDEA internal build system. " +
"Please use Gradle to build ${kotlinChunk.presentableShortName}."
kotlinContext.testingLogger?.addCustomMessage(msg)
messageCollector.report(STRONG_WARNING, msg)
return NOTHING_DONE
}
if (!kotlinChunk.isEnabled) {
return NOTHING_DONE
}
@@ -12,10 +12,12 @@ import org.jetbrains.jps.incremental.GlobalContextKey
import org.jetbrains.jps.incremental.fs.CompilationRound
import org.jetbrains.jps.incremental.messages.BuildMessage
import org.jetbrains.jps.incremental.messages.CompilerMessage
import org.jetbrains.kotlin.config.CompilerRunnerConstants
import org.jetbrains.kotlin.incremental.LookupSymbol
import org.jetbrains.kotlin.jps.incremental.*
import org.jetbrains.kotlin.jps.targets.KotlinTargetsIndex
import org.jetbrains.kotlin.jps.targets.KotlinTargetsIndexBuilder
import org.jetbrains.kotlin.jps.targets.KotlinUnsupportedModuleBuildTarget
import java.io.File
import java.util.concurrent.atomic.AtomicBoolean
@@ -249,4 +251,50 @@ class KotlinCompileContext(val jpsContext: CompileContext) {
return targetsIndex.chunksByJpsRepresentativeTarget[rawRepresentativeTarget]
?: error("Kotlin binding for chunk $this is not loaded at build start")
}
fun reportUnsupportedTargets() {
// group all KotlinUnsupportedModuleBuildTarget by kind
// only representativeTarget will be added
val byKind = mutableMapOf<String?, MutableList<KotlinUnsupportedModuleBuildTarget>>()
targetsIndex.chunks.forEach {
val target = it.representativeTarget
if (target is KotlinUnsupportedModuleBuildTarget) {
if (target.sourceFiles.isNotEmpty()) {
byKind.getOrPut(target.kind) { mutableListOf() }.add(target)
}
}
}
byKind.forEach { (kind, targets) ->
targets.sortBy { it.module.name }
val chunkNames = targets.map { it.chunk.presentableShortName }
val presentableChunksListString = chunkNames.joinToReadableString()
val msg =
if (kind == null) {
"$presentableChunksListString is not yet supported in IDEA internal build system. " +
"Please use Gradle to build them (enable 'Delegate IDE build/run actions to Gradle' in Settings)."
} else {
"$kind is not yet supported in IDEA internal build system. " +
"Please use Gradle to build $presentableChunksListString (enable 'Delegate IDE build/run actions to Gradle' in Settings)."
}
testingLogger?.addCustomMessage(msg)
jpsContext.processMessage(
CompilerMessage(
CompilerRunnerConstants.KOTLIN_COMPILER_NAME,
BuildMessage.Kind.WARNING,
msg
)
)
}
}
}
fun List<String>.joinToReadableString(): String = when {
size > 5 -> take(5).joinToString() + " and ${size - 5} more"
size > 1 -> dropLast(1).joinToString() + " and ${last()}"
size == 1 -> single()
else -> ""
}
@@ -6,5 +6,8 @@ pJvm -> c [include]
pJs [compilationAndSourceSetHolder, js]
pJs -> c [include]
pNative [compilationAndSourceSetHolder, native]
pNative -> c [include]
pNative1 [compilationAndSourceSetHolder, native]
pNative1 -> c [include]
pNative2 [compilationAndSourceSetHolder, native]
pNative2 -> c [include]
@@ -1,8 +1,11 @@
================ Step #1 create new service =================
Building c
Building pNative
Native is not yet supported in IDEA internal build system. Please use Gradle to build pNative.
Building pNative2
Native is not yet supported in IDEA internal build system. Please use Gradle to build pNative1 and pNative2 (enable 'Delegate IDE build/run actions to Gradle' in Settings).
Exit code: NOTHING_DONE
------------------------------------------
Building pNative1
Exit code: NOTHING_DONE
------------------------------------------
Building pJs
@@ -21,8 +24,11 @@ Exit code: OK
================ Step #2 edit new service =================
Building c
Building pNative
Native is not yet supported in IDEA internal build system. Please use Gradle to build pNative.
Building pNative2
Native is not yet supported in IDEA internal build system. Please use Gradle to build pNative1 and pNative2 (enable 'Delegate IDE build/run actions to Gradle' in Settings).
Exit code: NOTHING_DONE
------------------------------------------
Building pNative1
Exit code: NOTHING_DONE
------------------------------------------
Building pJs
@@ -50,8 +56,11 @@ Exit code: OK
================ Step #3 delete new service =================
Building c
Building pNative
Native is not yet supported in IDEA internal build system. Please use Gradle to build pNative.
Building pNative2
Native is not yet supported in IDEA internal build system. Please use Gradle to build pNative1 and pNative2 (enable 'Delegate IDE build/run actions to Gradle' in Settings).
Exit code: NOTHING_DONE
------------------------------------------
Building pNative1
Exit code: NOTHING_DONE
------------------------------------------
Cleaning output files: