diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheFormatVersion.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheFormatVersion.kt index c8cb8784996..473dad5d1af 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheFormatVersion.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheFormatVersion.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.jps.incremental +import org.jetbrains.annotations.TestOnly import org.jetbrains.kotlin.jps.build.KotlinBuilder import org.jetbrains.kotlin.load.java.JvmAbi import java.io.File @@ -30,7 +31,7 @@ class CacheFormatVersion(targetDataRoot: File) { JvmAbi.VERSION.major * 1000 + JvmAbi.VERSION.minor - val FORMAT_VERSION_FILE_PATH: String = "$CACHE_DIRECTORY_NAME/format-version.txt" + private val FORMAT_VERSION_FILE_PATH: String = "$CACHE_DIRECTORY_NAME/format-version.txt" } private val file = File(targetDataRoot, FORMAT_VERSION_FILE_PATH) @@ -59,4 +60,8 @@ class CacheFormatVersion(targetDataRoot: File) { fun clean() { file.delete() } + + @TestOnly + val formatVersionFile: File + get() = file } \ No newline at end of file diff --git a/jps-plugin/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt b/jps-plugin/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt index 39b3b8c9824..8da3559fb11 100644 --- a/jps-plugin/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt +++ b/jps-plugin/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt @@ -75,6 +75,8 @@ public abstract class AbstractIncrementalJpsTest( protected var workDir: File by Delegates.notNull() + protected var projectDescriptor: ProjectDescriptor by Delegates.notNull() + private fun enableDebugLogging() { com.intellij.openapi.diagnostic.Logger.setFactory(javaClass()) TestLoggerFactory.dumpLogToStdout("") @@ -106,19 +108,20 @@ public abstract class AbstractIncrementalJpsTest( protected open fun createLookupTracker(): LookupTracker = LookupTracker.DO_NOTHING - protected open fun checkLookups(@Suppress("UNUSED_PARAMETER") lookupTracker: LookupTracker) {} + protected open fun checkLookups(@Suppress("UNUSED_PARAMETER") lookupTracker: LookupTracker) { + } fun build(scope: CompileScopeTestBuilder = CompileScopeTestBuilder.make().all()): MakeResult { val workDirPath = FileUtil.toSystemIndependentName(workDir.absolutePath) val logger = MyLogger(workDirPath) - val descriptor = createProjectDescriptor(BuildLoggingManager(logger)) + projectDescriptor = createProjectDescriptor(BuildLoggingManager(logger)) val lookupTracker = createLookupTracker() val dataContainer = JpsElementFactory.getInstance().createSimpleElement(lookupTracker) - descriptor.project.container.setChild(KotlinBuilder.LOOKUP_TRACKER, dataContainer) + projectDescriptor.project.container.setChild(KotlinBuilder.LOOKUP_TRACKER, dataContainer) try { - val builder = IncProjectBuilder(descriptor, BuilderRegistry.getInstance(), myBuildParams, CanceledStatus.NULL, mockConstantSearch, true) + val builder = IncProjectBuilder(projectDescriptor, BuilderRegistry.getInstance(), myBuildParams, CanceledStatus.NULL, mockConstantSearch, true) val buildResult = BuildResult() builder.addMessageHandler(buildResult) builder.build(scope.build(), false) @@ -135,11 +138,12 @@ public abstract class AbstractIncrementalJpsTest( return MakeResult(logger.log + "$COMPILATION_FAILED\n" + errorMessages + "\n", true, null) } else { - return MakeResult(logger.log, false, createMappingsDump(descriptor)) + return MakeResult(logger.log, false, createMappingsDump(projectDescriptor)) } - } finally { - descriptor.dataManager.flush(false) - descriptor.release() + } + finally { + projectDescriptor.dataManager.flush(false) + projectDescriptor.release() } } @@ -289,10 +293,7 @@ public abstract class AbstractIncrementalJpsTest( private fun createKotlinIncrementalCacheDump(project: ProjectDescriptor): String { return StringBuilder { - val allTargets = project.buildTargetIndex.allTargets - val moduleTargets = allTargets.filterIsInstance(ModuleBuildTarget::class.java) - - for (target in moduleTargets.sortedBy { it.presentableName }) { + for (target in project.allModuleTargets.sortedBy { it.presentableName }) { append("\n") append(project.dataManager.getKotlinCache(target).dump()) append("\n\n\n") @@ -307,7 +308,7 @@ public abstract class AbstractIncrementalJpsTest( result.println("Begin of SourceToOutputMap") result.pushIndent() - for (target in project.buildTargetIndex.allTargets) { + for (target in project.allModuleTargets) { result.println(target) result.pushIndent() @@ -445,3 +446,6 @@ public abstract class AbstractIncrementalJpsTest( } } } + +internal val ProjectDescriptor.allModuleTargets: Collection + get() = buildTargetIndex.allTargets.filterIsInstance() diff --git a/jps-plugin/test/org/jetbrains/kotlin/jps/build/IncrementalCacheVersionChangedTest.kt b/jps-plugin/test/org/jetbrains/kotlin/jps/build/IncrementalCacheVersionChangedTest.kt index 97c7880cfc8..53b7dfe1cf6 100644 --- a/jps-plugin/test/org/jetbrains/kotlin/jps/build/IncrementalCacheVersionChangedTest.kt +++ b/jps-plugin/test/org/jetbrains/kotlin/jps/build/IncrementalCacheVersionChangedTest.kt @@ -16,11 +16,8 @@ package org.jetbrains.kotlin.jps.build -import org.jetbrains.jps.builders.impl.BuildDataPathsImpl -import java.io.File -import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType +import org.jetbrains.kotlin.jps.incremental.getKotlinCacheVersion import kotlin.test.assertTrue -import org.jetbrains.kotlin.jps.incremental.CacheFormatVersion public class IncrementalCacheVersionChangedTest : AbstractIncrementalJpsTest(allowNoFilesWithSuffixInTestData = true) { fun testCacheVersionChanged() { @@ -36,16 +33,13 @@ public class IncrementalCacheVersionChangedTest : AbstractIncrementalJpsTest(all } override fun performAdditionalModifications() { - val storageForTargetType = BuildDataPathsImpl(myDataStorageRoot).getTargetTypeDataRoot(JavaModuleBuildTargetType.PRODUCTION) + val targets = projectDescriptor.allModuleTargets + val paths = projectDescriptor.dataManager.dataPaths - - val moduleNames = if (getTestName(false) == "CacheVersionChangedMultiModule") listOf("module1", "module2") else listOf("module") - - for (moduleName in moduleNames) { - val relativePath = "$moduleName/${CacheFormatVersion.FORMAT_VERSION_FILE_PATH}" - val cacheVersionFile = File(storageForTargetType, relativePath) - - assertTrue(cacheVersionFile.exists()) + for (target in targets) { + val cacheVersion = paths.getKotlinCacheVersion(target) + val cacheVersionFile = cacheVersion.formatVersionFile + assertTrue(cacheVersionFile.exists(), "Cache version file does not exists: $cacheVersionFile") cacheVersionFile.writeText("777") } }