From 9e6d6ad9daf631c78192dc7825b07902cce5cbff Mon Sep 17 00:00:00 2001 From: Sergey Rostov Date: Mon, 10 Sep 2018 17:25:43 +0300 Subject: [PATCH] JPS, native: skip and report native modules as not supported #KT-26648 Fixed --- .../jps/build/AbstractIncrementalJpsTest.kt | 9 +++ .../kotlin/jps/build/KotlinJpsBuildTest.kt | 1 + ...mJpsTestWithGeneratedContentGenerated.java | 31 ++++++++ .../jps/build/dependeciestxt/ModulesTxt.kt | 22 ++++-- .../kotlin/jps/build/KotlinBuilder.kt | 20 ++++- .../kotlin/jps/build/TestingBuildLogger.kt | 1 + .../kotlin/jps/targets/KotlinTargetsIndex.kt | 6 +- .../KotlinUnsupportedModuleBuildTarget.kt | 57 ++++++++++++++ .../ignoreAndWarnAboutNative/dependencies.txt | 10 +++ .../editingCKotlin/build.log | 75 +++++++++++++++++++ 10 files changed, 217 insertions(+), 15 deletions(-) create mode 100644 jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinUnsupportedModuleBuildTarget.kt create mode 100644 jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/dependencies.txt create mode 100644 jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/editingCKotlin/build.log diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt index a2a01d07dae..bf2550927f2 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt @@ -552,6 +552,7 @@ abstract class AbstractIncrementalJpsTest( private class MyLogger(val rootPath: String) : ProjectBuilderLoggerBase(), TestingBuildLogger { private val markedDirtyBeforeRound = ArrayList() private val markedDirtyAfterRound = ArrayList() + private val customMessages = mutableListOf() override fun invalidOrUnusedCache( chunk: KotlinChunk?, @@ -588,7 +589,15 @@ abstract class AbstractIncrementalJpsTest( logDirtyFiles(markedDirtyBeforeRound) } + override fun addCustomMessage(message: String) { + customMessages.add(message) + } + override fun buildFinished(exitCode: ModuleLevelBuilder.ExitCode) { + customMessages.forEach { + logLine(it) + } + customMessages.clear() logDirtyFiles(markedDirtyAfterRound) logLine("Exit code: $exitCode") logLine("------------------------------------------") diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt index f59bb906dd4..8bf4420fc8e 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt @@ -1001,6 +1001,7 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { target: KotlinModuleBuildTarget<*>?, attributesDiff: CacheAttributesDiff<*> ) {} + override fun addCustomMessage(message: String) {} override fun buildFinished(exitCode: ModuleLevelBuilder.ExitCode) {} override fun markedAsDirtyBeforeRound(files: Iterable) {} override fun markedAsDirtyAfterRound(files: Iterable) {} diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/MultiplatformJpsTestWithGeneratedContentGenerated.java b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/MultiplatformJpsTestWithGeneratedContentGenerated.java index f9a2ae877fb..9efb180d4d3 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/MultiplatformJpsTestWithGeneratedContentGenerated.java +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/MultiplatformJpsTestWithGeneratedContentGenerated.java @@ -29,6 +29,37 @@ public class MultiplatformJpsTestWithGeneratedContentGenerated extends AbstractM KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, true); } + @TestMetadata("jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class IgnoreAndWarnAboutNative extends AbstractMultiplatformJpsTestWithGeneratedContent { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInIgnoreAndWarnAboutNative() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, true); + } + + @TestMetadata("editingCKotlin") + public void testEditingCKotlin() throws Exception { + runTest("jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/editingCKotlin/"); + } + + @TestMetadata("jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/editingCKotlin") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class EditingCKotlin extends AbstractMultiplatformJpsTestWithGeneratedContent { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInEditingCKotlin() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/editingCKotlin"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, true); + } + } + } + @TestMetadata("jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/simple") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/dependeciestxt/ModulesTxt.kt b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/dependeciestxt/ModulesTxt.kt index 91c57ff6366..48806a40409 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/dependeciestxt/ModulesTxt.kt +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/dependeciestxt/ModulesTxt.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.config.KotlinFacetSettings import org.jetbrains.kotlin.config.KotlinModuleKind.COMPILATION_AND_SOURCE_SET_HOLDER import org.jetbrains.kotlin.config.KotlinModuleKind.SOURCE_SET_HOLDER import org.jetbrains.kotlin.jps.build.dependeciestxt.ModulesTxt.Dependency.Kind.* +import org.jetbrains.kotlin.platform.impl.FakeK2NativeCompilerArguments import org.jetbrains.kotlin.platform.impl.isCommon import org.jetbrains.kotlin.platform.impl.isJvm import java.io.File @@ -168,15 +169,19 @@ class ModulesTxtBuilder { } fun readFile(file: File, fileTitle: String = file.toString()): ModulesTxt { - file.forEachLine { line -> - parseDeclaration(line) + try { + file.forEachLine { line -> + parseDeclaration(line) + } + + // dependencies need to be build first: module.build() requires it + val dependencies = dependencies.map { it.build() } + val modules = modules.values.mapIndexed { index, moduleRef -> moduleRef.build(index) } + + return ModulesTxt(muted, file, fileTitle, modules, dependencies) + } catch (t: Throwable) { + throw Error("Error while reading $file: ${t.message}", t) } - - // dependencies need to be build first: module.build() requires it - val dependencies = dependencies.map { it.build() } - val modules = modules.values.mapIndexed { index, moduleRef -> moduleRef.build(index) } - - return ModulesTxt(muted, file, fileTitle, modules, dependencies) } private fun parseDeclaration(line: String) = doParseDeclaration(removeComments(line)) @@ -251,6 +256,7 @@ class ModulesTxtBuilder { "common" -> settings.compilerArguments = K2MetadataCompilerArguments() "jvm" -> settings.compilerArguments = K2JVMCompilerArguments() "js" -> settings.compilerArguments = K2JSCompilerArguments() + "native" -> settings.compilerArguments = FakeK2NativeCompilerArguments() else -> { val flagProperty = ModulesTxt.Module.flags[flag] if (flagProperty != null) flagProperty.set(module, true) diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index db4349ed7c3..795478e93ac 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -31,11 +31,12 @@ import org.jetbrains.jps.model.JpsProject import org.jetbrains.kotlin.build.GeneratedFile import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.* import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil import org.jetbrains.kotlin.compilerRunner.* -import org.jetbrains.kotlin.config.* +import org.jetbrains.kotlin.config.IncrementalCompilation +import org.jetbrains.kotlin.config.KotlinModuleKind +import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.daemon.common.isDaemonEnabled import org.jetbrains.kotlin.incremental.* import org.jetbrains.kotlin.incremental.components.ExpectActualTracker @@ -45,6 +46,7 @@ import org.jetbrains.kotlin.jps.incremental.withLookupStorage import org.jetbrains.kotlin.jps.model.kotlinKind import org.jetbrains.kotlin.jps.targets.KotlinJvmModuleBuildTarget import org.jetbrains.kotlin.jps.targets.KotlinModuleBuildTarget +import org.jetbrains.kotlin.jps.targets.KotlinUnsupportedModuleBuildTarget import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.preloading.ClassCondition import org.jetbrains.kotlin.utils.KotlinPaths @@ -327,13 +329,23 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { return NOTHING_DONE } + val kotlinContext = context.kotlin val kotlinChunk = chunk.toKotlinChunk(context)!! + 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 } - val kotlinContext = context.kotlin val projectDescriptor = context.projectDescriptor val dataManager = projectDescriptor.dataManager val targets = chunk.targets diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/TestingBuildLogger.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/TestingBuildLogger.kt index d500f50b0e5..3d9852e9237 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/TestingBuildLogger.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/TestingBuildLogger.kt @@ -29,6 +29,7 @@ interface TestingBuildLogger { fun invalidOrUnusedCache(chunk: KotlinChunk?, target: KotlinModuleBuildTarget<*>?, attributesDiff: CacheAttributesDiff<*>) fun chunkBuildStarted(context: CompileContext, chunk: org.jetbrains.jps.ModuleChunk) fun afterChunkBuildStarted(context: CompileContext, chunk: org.jetbrains.jps.ModuleChunk) + fun addCustomMessage(message: String) fun buildFinished(exitCode: ModuleLevelBuilder.ExitCode) fun markedAsDirtyBeforeRound(files: Iterable) fun markedAsDirtyAfterRound(files: Iterable) diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinTargetsIndex.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinTargetsIndex.kt index fe9771197b6..b213ed2f9c5 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinTargetsIndex.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinTargetsIndex.kt @@ -41,7 +41,7 @@ internal class KotlinTargetsIndexBuilder internal constructor( // visit all kotlin build targets jpsContext.projectDescriptor.buildTargetIndex.getSortedTargetChunks(jpsContext).forEach { chunk -> val moduleBuildTargets = chunk.targets.mapNotNull { - if (it is ModuleBuildTarget) ensureLoaded(it)!! + if (it is ModuleBuildTarget) ensureLoaded(it) else null } @@ -132,7 +132,7 @@ internal class KotlinTargetsIndexBuilder internal constructor( } - private fun ensureLoaded(target: ModuleBuildTarget): KotlinModuleBuildTarget<*>? { + private fun ensureLoaded(target: ModuleBuildTarget): KotlinModuleBuildTarget<*> { return byJpsModuleBuildTarget.computeIfAbsent(target) { val platform = target.module.platform?.kind ?: detectTargetPlatform(target) @@ -140,7 +140,7 @@ internal class KotlinTargetsIndexBuilder internal constructor( platform.isCommon -> KotlinCommonModuleBuildTarget(uninitializedContext, target) platform.isJavaScript -> KotlinJsModuleBuildTarget(uninitializedContext, target) platform.isJvm -> KotlinJvmModuleBuildTarget(uninitializedContext, target) - else -> error("Unsupported platform $platform") + else -> KotlinUnsupportedModuleBuildTarget(uninitializedContext, target) } } } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinUnsupportedModuleBuildTarget.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinUnsupportedModuleBuildTarget.kt new file mode 100644 index 00000000000..36a06fe8e52 --- /dev/null +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinUnsupportedModuleBuildTarget.kt @@ -0,0 +1,57 @@ +/* + * 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.targets + +import org.jetbrains.jps.builders.storage.BuildDataPaths +import org.jetbrains.jps.incremental.ModuleBuildTarget +import org.jetbrains.kotlin.build.BuildMetaInfo +import org.jetbrains.kotlin.build.BuildMetaInfoFactory +import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment +import org.jetbrains.kotlin.jps.build.KotlinCompileContext +import org.jetbrains.kotlin.jps.build.KotlinDirtySourceFilesHolder +import org.jetbrains.kotlin.jps.incremental.JpsIncrementalCache +import org.jetbrains.kotlin.jps.model.platform + +class KotlinUnsupportedModuleBuildTarget( + kotlinContext: KotlinCompileContext, + jpsModuleBuildTarget: ModuleBuildTarget +) : KotlinModuleBuildTarget(kotlinContext, jpsModuleBuildTarget) { + val kind = module.platform?.kind?.name + + private fun shouldNotBeCalled(): Nothing = error("Should not be called") + + override fun isEnabled(chunkCompilerArguments: CommonCompilerArguments): Boolean { + return false + } + + override val isIncrementalCompilationEnabled: Boolean + get() = false + + override val hasCaches: Boolean + get() = false + + override val globalLookupCacheId: String + get() = shouldNotBeCalled() + + override fun compileModuleChunk( + commonArguments: CommonCompilerArguments, + dirtyFilesHolder: KotlinDirtySourceFilesHolder, + environment: JpsCompilerEnvironment + ): Boolean { + shouldNotBeCalled() + } + + override fun createCacheStorage(paths: BuildDataPaths): JpsIncrementalCache { + shouldNotBeCalled() + } + + override val buildMetaInfoFactory: BuildMetaInfoFactory + get() = shouldNotBeCalled() + + override val buildMetaInfoFileName: String + get() = shouldNotBeCalled() +} \ No newline at end of file diff --git a/jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/dependencies.txt b/jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/dependencies.txt new file mode 100644 index 00000000000..e87027d3bd8 --- /dev/null +++ b/jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/dependencies.txt @@ -0,0 +1,10 @@ +c [sourceSetHolder, edit] + +pJvm [compilationAndSourceSetHolder, jvm] +pJvm -> c [include] + +pJs [compilationAndSourceSetHolder, js] +pJs -> c [include] + +pNative [compilationAndSourceSetHolder, native] +pNative -> c [include] \ No newline at end of file diff --git a/jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/editingCKotlin/build.log b/jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/editingCKotlin/build.log new file mode 100644 index 00000000000..0f9dc130161 --- /dev/null +++ b/jps-plugin/testData/incremental/multiModule/multiplatform/withGeneratedContent/ignoreAndWarnAboutNative/editingCKotlin/build.log @@ -0,0 +1,75 @@ +================ 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. +Exit code: NOTHING_DONE +------------------------------------------ +Building pJs +Compiling files: + c/src/serviceCNewHeader.kt +End of files +Exit code: OK +------------------------------------------ +Building pJvm +Compiling files: + c/src/serviceCNewHeader.kt +End of files +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. +Exit code: NOTHING_DONE +------------------------------------------ +Building pJs +Cleaning output files: + out/production/pJs/pJs.js + out/production/pJs/pJs.meta.js + out/production/pJs/pJs/root-package.kjsm +End of files +Compiling files: + c/src/serviceCNewHeader.kt +End of files +Exit code: OK +------------------------------------------ +Building pJvm +Cleaning output files: + out/production/pJvm/META-INF/pJvm.kotlin_module + out/production/pJvm/ServiceCNewHeaderKt.class +End of files +Compiling files: + c/src/serviceCNewHeader.kt +End of files +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. +Exit code: NOTHING_DONE +------------------------------------------ +Cleaning output files: + out/production/pJs/pJs.js + out/production/pJs/pJs.meta.js + out/production/pJs/pJs/root-package.kjsm +End of files +Building pJs +Compiling files: +End of files +Exit code: OK +------------------------------------------ +Cleaning output files: + out/production/pJvm/META-INF/pJvm.kotlin_module + out/production/pJvm/ServiceCNewHeaderKt.class +End of files +Building pJvm +Compiling files: +End of files +Exit code: OK +------------------------------------------ \ No newline at end of file