Test JPS Kotlin caches don't change when project root is different
Original commit: f66d95545d
This commit is contained in:
+85
-77
@@ -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("<target $target>\n")
|
||||
append(kotlinCache.dump())
|
||||
append("</target $target>\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<File>()
|
||||
private val markedDirtyAfterRound = ArrayList<File>()
|
||||
private val customMessages = mutableListOf<String>()
|
||||
@@ -652,6 +577,89 @@ abstract class AbstractIncrementalJpsTest(
|
||||
}
|
||||
}
|
||||
|
||||
private fun createMappingsDump(
|
||||
project: ProjectDescriptor,
|
||||
kotlinContext: KotlinCompileContext,
|
||||
lookupsDuringTest: Set<LookupSymbol>
|
||||
) = createKotlinCachesDump(project, kotlinContext, lookupsDuringTest) + "\n\n\n" +
|
||||
createCommonMappingsDump(project) + "\n\n\n" +
|
||||
createJavaMappingsDump(project)
|
||||
|
||||
internal fun createKotlinCachesDump(
|
||||
project: ProjectDescriptor,
|
||||
kotlinContext: KotlinCompileContext,
|
||||
lookupsDuringTest: Set<LookupSymbol>
|
||||
) = 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("<target $target>\n")
|
||||
append(kotlinCache.dump())
|
||||
append("</target $target>\n\n\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createLookupCacheDump(kotlinContext: KotlinCompileContext, lookupsDuringTest: Set<LookupSymbol>): 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<ModuleBuildTarget>
|
||||
get() = buildTargetIndex.allTargets.filterIsInstance<ModuleBuildTarget>()
|
||||
|
||||
|
||||
+56
@@ -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())
|
||||
|
||||
@@ -40,7 +40,7 @@ val CompileContext.testingContext: TestingContext?
|
||||
|
||||
class TestingContext(
|
||||
val lookupTracker: LookupTracker,
|
||||
val buildLogger: TestingBuildLogger
|
||||
val buildLogger: TestingBuildLogger?
|
||||
) {
|
||||
var kotlinCompileContext: KotlinCompileContext? = null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
</component>
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
open class Foo() {
|
||||
companion object {
|
||||
const val CONST = 0
|
||||
}
|
||||
|
||||
inline fun bar() = 1
|
||||
}
|
||||
|
||||
class FooChild() : Foo() {}
|
||||
@@ -0,0 +1,8 @@
|
||||
import utils.*
|
||||
|
||||
fun main() {
|
||||
Foo().bar()
|
||||
Foo.CONST
|
||||
util1()
|
||||
util2()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("Utils")
|
||||
|
||||
package utils
|
||||
|
||||
fun util1() {}
|
||||
@@ -0,0 +1,6 @@
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("Utils")
|
||||
|
||||
package utils
|
||||
|
||||
fun util2() {}
|
||||
Reference in New Issue
Block a user