diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt index 776a971b38a..5dd8dcf9ad6 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt @@ -208,7 +208,7 @@ abstract class AbstractIncrementalJpsTest( return MakeResult( log = logger.log, makeFailed = false, - mappingsDump = createMappingsDump(projectDescriptor, kotlinCompileContext), + mappingsDump = createMappingsDump(projectDescriptor, kotlinCompileContext, lookupsDuringTest), name = name ) } @@ -329,81 +329,6 @@ abstract class AbstractIncrementalJpsTest( } } - private fun createMappingsDump( - project: ProjectDescriptor, - kotlinContext: KotlinCompileContext - ) = createKotlinIncrementalCacheDump(project) + "\n\n\n" + - createLookupCacheDump(kotlinContext) + "\n\n\n" + - createCommonMappingsDump(project) + "\n\n\n" + - createJavaMappingsDump(project) - - private fun createKotlinIncrementalCacheDump( - project: ProjectDescriptor - ): String { - return buildString { - for (target in project.allModuleTargets.sortedBy { it.presentableName }) { - val kotlinCache = project.dataManager.getKotlinCache(kotlinCompileContext.targetsBinding[target]) - if (kotlinCache != null) { - append("\n") - append(kotlinCache.dump()) - append("\n\n\n") - } - } - } - } - - private fun createLookupCacheDump(kotlinContext: KotlinCompileContext): String { - val sb = StringBuilder() - val p = Printer(sb) - p.println("Begin of Lookup Maps") - p.println() - - kotlinContext.lookupStorageManager.withLookupStorage { lookupStorage -> - lookupStorage.forceGC() - p.print(lookupStorage.dump(lookupsDuringTest)) - } - - p.println() - p.println("End of Lookup Maps") - return sb.toString() - } - - private fun createCommonMappingsDump(project: ProjectDescriptor): String { - val resultBuf = StringBuilder() - val result = Printer(resultBuf) - - result.println("Begin of SourceToOutputMap") - result.pushIndent() - - for (target in project.allModuleTargets) { - result.println(target) - result.pushIndent() - - val mapping = project.dataManager.getSourceToOutputMap(target) - mapping.sources.sorted().forEach { - val outputs = mapping.getOutputs(it)!!.sorted() - if (outputs.isNotEmpty()) { - result.println("source $it -> $outputs") - } - } - - result.popIndent() - } - - result.popIndent() - result.println("End of SourceToOutputMap") - - return resultBuf.toString() - } - - private fun createJavaMappingsDump(project: ProjectDescriptor): String { - val byteArrayOutputStream = ByteArrayOutputStream() - PrintStream(byteArrayOutputStream).use { - project.dataManager.mappings.toStream(it) - } - return byteArrayOutputStream.toString() - } - protected data class MakeResult( val log: String, val makeFailed: Boolean, @@ -563,7 +488,7 @@ abstract class AbstractIncrementalJpsTest( override fun doGetProjectDir(): File? = workDir - private class MyLogger(val rootPath: String) : ProjectBuilderLoggerBase(), TestingBuildLogger { + internal class MyLogger(val rootPath: String) : ProjectBuilderLoggerBase(), TestingBuildLogger { private val markedDirtyBeforeRound = ArrayList() private val markedDirtyAfterRound = ArrayList() private val customMessages = mutableListOf() @@ -652,6 +577,89 @@ abstract class AbstractIncrementalJpsTest( } } +private fun createMappingsDump( + project: ProjectDescriptor, + kotlinContext: KotlinCompileContext, + lookupsDuringTest: Set +) = createKotlinCachesDump(project, kotlinContext, lookupsDuringTest) + "\n\n\n" + + createCommonMappingsDump(project) + "\n\n\n" + + createJavaMappingsDump(project) + +internal fun createKotlinCachesDump( + project: ProjectDescriptor, + kotlinContext: KotlinCompileContext, + lookupsDuringTest: Set +) = createKotlinIncrementalCacheDump(project, kotlinContext) + "\n\n\n" + + createLookupCacheDump(kotlinContext, lookupsDuringTest) + +private fun createKotlinIncrementalCacheDump( + project: ProjectDescriptor, + kotlinContext: KotlinCompileContext +): String { + return buildString { + for (target in project.allModuleTargets.sortedBy { it.presentableName }) { + val kotlinCache = project.dataManager.getKotlinCache(kotlinContext.targetsBinding[target]) + if (kotlinCache != null) { + append("\n") + append(kotlinCache.dump()) + append("\n\n\n") + } + } + } +} + +private fun createLookupCacheDump(kotlinContext: KotlinCompileContext, lookupsDuringTest: Set): String { + val sb = StringBuilder() + val p = Printer(sb) + p.println("Begin of Lookup Maps") + p.println() + + kotlinContext.lookupStorageManager.withLookupStorage { lookupStorage -> + lookupStorage.forceGC() + p.print(lookupStorage.dump(lookupsDuringTest)) + } + + p.println() + p.println("End of Lookup Maps") + return sb.toString() +} + +private fun createCommonMappingsDump(project: ProjectDescriptor): String { + val resultBuf = StringBuilder() + val result = Printer(resultBuf) + + result.println("Begin of SourceToOutputMap") + result.pushIndent() + + for (target in project.allModuleTargets) { + result.println(target) + result.pushIndent() + + val mapping = project.dataManager.getSourceToOutputMap(target) + mapping.sources.sorted().forEach { + val outputs = mapping.getOutputs(it)!!.sorted() + if (outputs.isNotEmpty()) { + result.println("source $it -> $outputs") + } + } + + result.popIndent() + } + + result.popIndent() + result.println("End of SourceToOutputMap") + + return resultBuf.toString() +} + +private fun createJavaMappingsDump(project: ProjectDescriptor): String { + val byteArrayOutputStream = ByteArrayOutputStream() + PrintStream(byteArrayOutputStream).use { + project.dataManager.mappings.toStream(it) + } + return byteArrayOutputStream.toString() +} + internal val ProjectDescriptor.allModuleTargets: Collection get() = buildTargetIndex.allTargets.filterIsInstance() diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTestIncremental.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTestIncremental.kt index 50e76a5cd4e..85166819553 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTestIncremental.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTestIncremental.kt @@ -17,8 +17,10 @@ package org.jetbrains.kotlin.jps.build import com.intellij.openapi.util.io.FileUtil +import org.jetbrains.jps.builders.CompileScopeTestBuilder import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.jps.builders.JpsBuildTestCase +import org.jetbrains.jps.builders.logging.BuildLoggingManager import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner import org.jetbrains.kotlin.config.IncrementalCompilation import org.jetbrains.kotlin.config.LanguageVersion @@ -26,8 +28,10 @@ import kotlin.reflect.KMutableProperty1 import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_ENABLED_PROPERTY import org.jetbrains.kotlin.daemon.common.isDaemonEnabled +import org.jetbrains.kotlin.incremental.LookupSymbol import org.jetbrains.kotlin.jps.model.kotlinCommonCompilerArguments import org.jetbrains.kotlin.jps.model.kotlinCompilerArguments +import org.junit.Assert import java.io.File class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() { @@ -44,6 +48,58 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() { super.tearDown() } + fun testRelocatableCaches() { + fun buildAndGetMappings(): String { + workDir.deleteRecursively() + workDir = AbstractKotlinJpsBuildTestCase.copyTestDataToTmpDir(originalProjectDir) + myDataStorageRoot.deleteRecursively() + myDataStorageRoot.mkdirs() + + initProject(LibraryDependency.JVM_FULL_RUNTIME) + + val workDirPath = FileUtil.toSystemIndependentName(workDir.absolutePath) + val logger = AbstractIncrementalJpsTest.MyLogger(workDirPath) + val projectDescriptor = createProjectDescriptor(BuildLoggingManager(logger)) + + val lookupTracker = TestLookupTracker() + val testingContext = TestingContext(lookupTracker, buildLogger = null) + myProject.setTestingContext(testingContext) + + try { + doBuild(projectDescriptor, CompileScopeTestBuilder.rebuild().allModules()).assertSuccessful() + + assertFilesExistInOutput( + myProject.modules.single(), + "MainKt.class", "Foo.class", "FooChild.class", "utils/Utils.class" + ) + + val kotlinContext = testingContext.kotlinCompileContext!! + val lookups = lookupTracker.lookups.mapTo(HashSet()) { LookupSymbol(it.name, it.scopeFqName) } + + return createKotlinCachesDump(projectDescriptor, kotlinContext, lookups) + } finally { + projectDescriptor.release() + } + } + + val mappings1 = buildAndGetMappings() + val projectDir1 = workDir + tearDown() + // hack to prevent setUp from creating the same dir after tearDown + projectDir1.mkdirs() + + try { + setUp() + val projectDir2 = workDir + Assert.assertNotEquals(projectDir1, projectDir2) + + val mappings2 = buildAndGetMappings() + Assert.assertEquals(mappings1, mappings2) + } finally { + projectDir1.deleteRecursively() + } + } + fun testJpsDaemonIC() { fun testImpl() { assertTrue("Daemon was not enabled!", isDaemonEnabled()) diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/TestingContext.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/TestingContext.kt index 310f89c667b..bda459ad2b6 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/TestingContext.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/TestingContext.kt @@ -40,7 +40,7 @@ val CompileContext.testingContext: TestingContext? class TestingContext( val lookupTracker: LookupTracker, - val buildLogger: TestingBuildLogger + val buildLogger: TestingBuildLogger? ) { var kotlinCompileContext: KotlinCompileContext? = null } diff --git a/jps/jps-plugin/testData/general/RelocatableCaches/kotlinProject.iml b/jps/jps-plugin/testData/general/RelocatableCaches/kotlinProject.iml new file mode 100644 index 00000000000..0c4fb67a3d4 --- /dev/null +++ b/jps/jps-plugin/testData/general/RelocatableCaches/kotlinProject.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/jps/jps-plugin/testData/general/RelocatableCaches/kotlinProject.ipr b/jps/jps-plugin/testData/general/RelocatableCaches/kotlinProject.ipr new file mode 100644 index 00000000000..8226e21ade3 --- /dev/null +++ b/jps/jps-plugin/testData/general/RelocatableCaches/kotlinProject.ipr @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/jps/jps-plugin/testData/general/RelocatableCaches/src/Foo.kt b/jps/jps-plugin/testData/general/RelocatableCaches/src/Foo.kt new file mode 100644 index 00000000000..0ac80e28778 --- /dev/null +++ b/jps/jps-plugin/testData/general/RelocatableCaches/src/Foo.kt @@ -0,0 +1,9 @@ +open class Foo() { + companion object { + const val CONST = 0 + } + + inline fun bar() = 1 +} + +class FooChild() : Foo() {} \ No newline at end of file diff --git a/jps/jps-plugin/testData/general/RelocatableCaches/src/main.kt b/jps/jps-plugin/testData/general/RelocatableCaches/src/main.kt new file mode 100644 index 00000000000..2e5d000513e --- /dev/null +++ b/jps/jps-plugin/testData/general/RelocatableCaches/src/main.kt @@ -0,0 +1,8 @@ +import utils.* + +fun main() { + Foo().bar() + Foo.CONST + util1() + util2() +} \ No newline at end of file diff --git a/jps/jps-plugin/testData/general/RelocatableCaches/src/utils/utils_part1.kt b/jps/jps-plugin/testData/general/RelocatableCaches/src/utils/utils_part1.kt new file mode 100644 index 00000000000..c83e13459bd --- /dev/null +++ b/jps/jps-plugin/testData/general/RelocatableCaches/src/utils/utils_part1.kt @@ -0,0 +1,6 @@ +@file:JvmMultifileClass +@file:JvmName("Utils") + +package utils + +fun util1() {} \ No newline at end of file diff --git a/jps/jps-plugin/testData/general/RelocatableCaches/src/utils/utils_part2.kt b/jps/jps-plugin/testData/general/RelocatableCaches/src/utils/utils_part2.kt new file mode 100644 index 00000000000..0b1c8be0204 --- /dev/null +++ b/jps/jps-plugin/testData/general/RelocatableCaches/src/utils/utils_part2.kt @@ -0,0 +1,6 @@ +@file:JvmMultifileClass +@file:JvmName("Utils") + +package utils + +fun util2() {} \ No newline at end of file